Class: ChatClient

Photon.Chat. ChatClient

Implements the Photon Chat API workflow.
This class should be extended to handle system or custom events and operation responses.

new ChatClient(protocol, appId, appVersion)

Parameters:
Name Type Description
protocol Photon.ConnectionProtocol Connecton protocol.
appId string Cloud application ID.
appVersion string Cloud application version.
Source:
  • Photon-Javascript_SDK.js, line 4144

Members

<static, readonly> ChatPeerErrorCode

Enum for client peers error codes.

Properties:
Name Type Description
Ok number No Error.
FrontEndError number General FrontEnd server peer error.
FrontEndConnectFailed number FrontEnd server connection error.
FrontEndConnectClosed number Disconnected from FrontEnd server.
FrontEndTimeout number Disconnected from FrontEnd server for timeout.
FrontEndEncryptionEstablishError number FrontEnd server encryption establishing failed.
FrontEndAuthenticationFailed number FrontEnd server authentication failed.
NameServerError number General NameServer peer error.
NameServerConnectFailed number NameServer connection error.
NameServerConnectClosed number Disconnected from NameServer.
NameServerTimeout number Disconnected from NameServer for timeout.
NameServerEncryptionEstablishError number NameServer encryption establishing failed.
NameServerAuthenticationFailed number NameServer authentication failed.
Source:
  • Photon-Javascript_SDK.js, line 4545

<static, readonly> ChatState

Enum for client states.

Properties:
Name Type Description
Error number Critical error occurred.
Uninitialized number Client is created but not used yet.
ConnectingToNameServer number Connecting to NameServer.
ConnectedToNameServer number Connected to NameServer.
ConnectingToFrontEnd number Connecting to FrontEnd server.
ConnectedToFrontEnd number Connected to FrontEnd server.
Disconnected number The client is no longer connected (to any server).
Source:
  • Photon-Javascript_SDK.js, line 4578

Methods

<static> StateToName(state) → {string}

Converts ChatState element to string name.

Parameters:
Name Type Description
state Photon.Chat.ChatClient.ChatState Client state.
Source:
  • Photon-Javascript_SDK.js, line 4528
Returns:
Specified element name or undefined if not found.
Type
string

connectToRegionFrontEnd(region) → {boolean}

Connects to a specific region's Master server, using the NameServer to find the IP. Override onWebRpcResult to handle request results.

Parameters:
Name Type Description
region string Region connect to Master server of.
Source:
  • Photon-Javascript_SDK.js, line 4230
Returns:
True if current client state allows connection.
Type
boolean

disconnect()

Disconnects from all servers.

Source:
  • Photon-Javascript_SDK.js, line 2043

getRegions()

Requests NameServer for regions list.
Override onGetRegionsResult to handle request results.

Source:
  • Photon-Javascript_SDK.js, line 2245

isConnectedToFrontEnd() → {boolean}

Returns true if client connected to Front End.When connected, client can send messages, subscribe to channels and so on.

Source:
  • Photon-Javascript_SDK.js, line 4240
Returns:
True if connected.
Type
boolean

isConnectedToNameServer() → {boolean}

Checks if client is connected to NameServer server.

Source:
  • Photon-Javascript_SDK.js, line 2312
Returns:
True if client is connected to NameServer server.
Type
boolean

onChatMessages(channelName, messages)

Called when new chat messages received.
Override to handle messages receive event.

Parameters:
Name Type Description
channelName string Chat channel name.
messages Photon.Chat.Message[] Array of received messages.
Source:
  • Photon-Javascript_SDK.js, line 4197

onPrivateMessage(channelName, message)

Called when new private message received.
Override to handle message receive event.

Parameters:
Name Type Description
channelName string Private channel name(counterpart user id).
message Photon.Chat.Message Received message.
Source:
  • Photon-Javascript_SDK.js, line 4205

onStateChange(state)

Called on client state change. Override to handle it.

Parameters:
Name Type Description
state Photon.Chat.ChatClient.ChatState New client state.
Source:
  • Photon-Javascript_SDK.js, line 4170

onSubscribeResult(results)

Called when subscribe request completed.
Override to handle request results.

Parameters:
Name Type Description
results object Object with channel names as keys and boolean results as values.
Source:
  • Photon-Javascript_SDK.js, line 4183

onUnsubscribeResult(results)

Called when unsubscribe request completed.
Override to handle request results.

Parameters:
Name Type Description
results object Object with channel names as keys and boolean results as values.
Source:
  • Photon-Javascript_SDK.js, line 4190

onUserStatusUpdate(userId, status, gotMessage, statusMessage)

Called when user from friend list changes state.
Override to handle change state event.

Parameters:
Name Type Description
userId string User id.
status number New User status. Predefined Constants.UserStatus or custom.
gotMessage boolean True if status message updated.
statusMessage string Optional status message (may be null even if gotMessage = true).
Source:
  • Photon-Javascript_SDK.js, line 4213

publishMessage(channelName, content, options) → {boolean}

Sends a message to a public channel.
Channel should be subscribed before publishing to it. Everyone in that channel will get the message.

Parameters:
Name Type Argument Description
channelName string Channel name to send message to.
content any Text string or arbitrary data to send.
options object <optional>
Additional options
Properties:
Name Type Description
options object Additional options
Properties
Name Type Argument Description
webForward boolean <optional>
Optionally, private messages can be forwarded as webhooks. Configure webhooks for your Chat app to use this.
Source:
  • Photon-Javascript_SDK.js, line 4307
Returns:
True if message sent.
Type
boolean

sendPrivateMessage(userId, content, options) → {boolean}

Sends a private message to a single target user.

Parameters:
Name Type Argument Description
userId string User id to send this message to.
content any Text string or arbitrary data to send.
options object <optional>
Additional options
Properties:
Name Type Description
options object Additional options
Properties
Name Type Argument Description
webForward boolean <optional>
Optionally, private messages can be forwarded as webhooks. Configure webhooks for your Chat app to use this.
Source:
  • Photon-Javascript_SDK.js, line 4338
Returns:
True if message sent.
Type
boolean

setLogLevel(level)

Sets client logger level

Parameters:
Name Type Description
level Exitgames.Common.Logger.Level Logging level.
Source:
  • Photon-Javascript_SDK.js, line 2348

setUserStatus(status, message, skipMessage) → {boolean}

Sets the user's status (pre-defined or custom) and an optional message.
The predefined status values can be found in Constants.UserStatus.
State UserStatus.Invisible will make you offline for everyone and send no message.

Parameters:
Name Type Argument Default Description
status number User status to set.
message string <optional>
null State message.
skipMessage boolean <optional>
false If true { client does not send state message.
Source:
  • Photon-Javascript_SDK.js, line 4367
Returns:
True if command sent.
Type
boolean

subscribe(channelNames, options) → {boolean}

Sends operation to subscribe to a list of channels by name.
Override onSubscribeResult to handle request results.

Parameters:
Name Type Argument Description
channelNames string[] Array of channel names to subscribe to.
options object <optional>
Additional options
Properties:
Name Type Description
options object Additional options
Properties
Name Type Argument Description
historyLength number <optional>
Controls messages history sent on subscription. Not specified or 0: no history. 1 and higher: number of messages in history. -1: all history.
lastIds number[] <optional>
Array of IDs of last messages received per channel. Useful when resubscribing to receive only messages we missed.
Source:
  • Photon-Javascript_SDK.js, line 4248
Returns:
True if operation sent.
Type
boolean

unsubscribe(channelNames) → {boolean}

Sends operation to unsubscribe from a list of channels by name.
Override onUnsubscribeResult to handle request results.

Parameters:
Name Type Description
channelNames string[] Array of channel names to unsubscribe from.
Source:
  • Photon-Javascript_SDK.js, line 4287
Returns:
True if operation sent.
Type
boolean