SCLOrkChatClient:
Filter:
SCLOrkTools/Classes (extension) | Quarks > SCLOrkTools

SCLOrkChatClient
ExtensionExtension

Programmatic client interface to SCLOrkChat system.

Description

Provides a programmatic interface to the SCLOrkChat-User-Guide system. Used by SCLOrkChat, the chat graphical user interface, and could also be used by other programs to make bots. The primary usage of the object revolves around providing callback functions to the client on the onConnected, onMessageReceived, and onUserChanged accessors, and responding to server events from there.

Class Methods

.new

Create a new SCLOrkChatClient object, initialize and return it.

Arguments:

serverAddress

A string with either an IP address or a resolvable hostname providing the location for a running instance of SCLOrkChatServer.

serverPort

The port provided to the running SCLOrkChatServer: bindPort.

listenPort

The SCLOrkWire port to listen to responses from the server on. Clients listen on only one port to enable multiple clients to run on the same IP address/machine.

Returns:

A new SCLOrkChatClient object.

WARNING: Running two or more SCLOrkChatClients on the same computer and with the same listenPort will lead to undefined client behavior.

Instance Methods

.nameMap

Acessor method for the client's current map of userId keys to name values.

Returns:

A Dictionary with integer userIds as keys and string nicknames as values.

.connect

Connect to the server at the address specificed in new. Will call the function at onConnected with results of the connection attempt.

Arguments:

name

The nickName to associate with this client.

.onMessageReceived

Function the client will call upon receipt of any chat messages from the server. The client will call the function with a single argument, a SCLOrkChatMessage object containing the deserialized message.

.sendMessage

Serializes the provided SCLOrkChatMessage object and sends it to the server, for sending to the targeted recipients on the client's behalf.

Arguments:

chatMessage

A SCLOrkChatMessage object.

.name

Access, or change the current name associated with this client to a new string value.

Arguments:

newName

The new string name to associate with this client.

.onUserChanged

Function the client will call after applying any updates to its userDictionary. The client will call the provided function with four arguments: type, userId, name, oldName. The type argument is an enumeration documented at SCLOrkChat-OSC-Command-Reference: changeType enumeration. The userId and name arguments are the id and name associated with the client that is changing. Lastly the oldName argument is only valid if the type values is \rename, in which case the client will supply the old name the user was going by, and the new name will be in name.

.free

Will automatically call disconnect if the client is connected to the server. Then unbinds all listener functions and destroys the object.

.onConnected

Function the client will call after any change in connection status. The client will call the provided function with a single boolean argument, if true the client has successfully connected, if false the client is disconnected.

.userId

Accessor method for the integer userId associated with this particular client.

.disconnect

If connected to the server the client will send a sign-out message to the server. It will then call onConnected with a false value in the argument to indicate disconnection has occurred.

Examples