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 4095

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 4489

<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 4522

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 4472
Returns:
Specified element name or undefined if not found.
Type
string

connectToNameServer(options)

Starts connection to NameServer.

Parameters:
Name Type Argument Description
options object <optional>
Additional options
Properties:
Name Type Description
options object Additional options
Properties
Name Type Argument Default Description
region string <optional>
Don't disconnect from Master server after joining room.
lobbyName string <optional>
Name of the lobby connect to.
lobbyType Photon.LoadBalancing.Constants.LobbyType <optional>
LobbyType.Default Type of the lobby.
lobbyStats boolean <optional>
false If true, Master server will be sending lobbies statistics periodically.
Override onLobbyStats to handle request results.
Alternatively, requestLobbyStats can be used.
keepMasterConnection boolean <optional>
false Don't disconnect from Master server after joining room.
Source:
  • Photon-Javascript_SDK.js, line 1752

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 4174
Returns:
True if current client state allows connection.
Type
boolean

disconnect()

Disconnects from all servers.

Source:
  • Photon-Javascript_SDK.js, line 1998

getRegions()

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

Source:
  • Photon-Javascript_SDK.js, line 2200

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 4184
Returns:
True if connected.
Type
boolean

isConnectedToNameServer() → {boolean}

Checks if client is connected to NameServer server.

Source:
  • Photon-Javascript_SDK.js, line 2268
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 4148

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 4156

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 4121

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 4134

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 4141

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 4164

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 4251
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 4282
Returns:
True if message sent.
Type
boolean

setCustomAuthentication(authParameters, authType, authData)

Enables custom authentication and sets it's parameters.

Parameters:
Name Type Argument Default Description
authParameters string This string must contain any (http get) parameters expected by the used authentication service.
authType Photon.LoadBalancing.Constants.CustomAuthenticationType <optional>
Photon.LoadBalancing.Constants.CustomAuthenticationType.Custom The type of custom authentication provider that should be used.
authData any <optional>
The data to be passed-on to the auth service via POST. String passed as is, objects as application/json
Source:
  • Photon-Javascript_SDK.js, line 1695

setLogLevel(level)

Sets client logger level

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

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 4311
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 4192
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 4231
Returns:
True if operation sent.
Type
boolean