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_v4-0-0-7_Cloud_SDK.js, line 4238

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_v4-0-0-7_Cloud_SDK.js, line 4597

<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_v4-0-0-7_Cloud_SDK.js, line 4630

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_v4-0-0-7_Cloud_SDK.js, line 4580
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
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 2575

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_v4-0-0-7_Cloud_SDK.js, line 4316
Returns:
True if current client state allows connection.
Type
boolean

disconnect()

Disconnects from all servers.

Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 2818

getRegions()

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

Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 3002

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_v4-0-0-7_Cloud_SDK.js, line 4326
Returns:
True if connected.
Type
boolean

isConnectedToNameServer() → {boolean}

Checks if client is connected to NameServer server.

Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 3067
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_v4-0-0-7_Cloud_SDK.js, line 4290

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_v4-0-0-7_Cloud_SDK.js, line 4298

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_v4-0-0-7_Cloud_SDK.js, line 4263

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_v4-0-0-7_Cloud_SDK.js, line 4276

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_v4-0-0-7_Cloud_SDK.js, line 4283

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_v4-0-0-7_Cloud_SDK.js, line 4306

publishMessage(channelName, content) → {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 Description
channelName string Channel name to send message to.
content any Text string or arbitrary data to send.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 4379
Returns:
True if message sent.
Type
boolean

sendPrivateMessage(userId, content) → {boolean}

Sends a private message to a single target user.

Parameters:
Name Type Description
userId string User id to send this message to.
content any Text string or arbitrary data to send.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 4401
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 string The data to be passed-on to the auth service via POST.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 2520

setLogLevel(level)

Sets client logger level

Parameters:
Name Type Description
level Exitgames.Common.Logger.Level Logging level.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 3103

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_v4-0-0-7_Cloud_SDK.js, line 4421
Returns:
True if command sent.
Type
boolean

subscribe(channelNames, messagesFromHistory) → {boolean}

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

Parameters:
Name Type Argument Default Description
channelNames string[] Array of channel names to subscribe to.
messagesFromHistory number <optional>
0 Controls messages history sent on subscription. Not specified or 0: no history. 1 and higher: number of messages in history. -1: all history.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 4334
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_v4-0-0-7_Cloud_SDK.js, line 4359
Returns:
True if operation sent.
Type
boolean