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 4330
Members
-
<static, readonly> ChatPeerErrorCode
Enum for client peers error codes.
-
- Source:
- Photon-Javascript_SDK.js, line 4821
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. -
<static, readonly> ChatState
Enum for client states.
-
- Source:
- Photon-Javascript_SDK.js, line 4854
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).
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 4804
Returns:
Specified element name or undefined if not found.- Type
- string
-
connectToNameServer(options) → {boolean}
Starts connection to NameServer.
-
Parameters:
Name Type Argument Description options
object <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 4424
Properties:
Name Type Description options
object Additional options Properties
Name Type Argument Description region
string <optional>
If specified, Connect to region master after succesfull connection to name server Returns:
True if current client state allows connection.- Type
- boolean
-
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 4435
Returns:
True if current client state allows connection.- Type
- boolean
-
disconnect()
Disconnects from all servers.
-
- Source:
- Photon-Javascript_SDK.js, line 2328
-
getRegions()
Requests NameServer for regions list.
Override onGetRegionsResult to handle request results. -
- Source:
- Photon-Javascript_SDK.js, line 2530
-
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 4445
Returns:
True if connected.- Type
- boolean
-
isConnectedToNameServer() → {boolean}
Checks if client is connected to NameServer server.
-
- Source:
- Photon-Javascript_SDK.js, line 2597
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 4384
-
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 4392
-
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 4357
-
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 4370
-
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 4377
-
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 4400
-
onUserSubscribe(channelName, userId)
A user has subscribed to a public chat channel
-
Parameters:
Name Type Description channelName
string Chat channel name. userId
string User id. - Source:
- Photon-Javascript_SDK.js, line 4410
-
onUserUnsubscribe(channelName, userId)
A user has unsubscribed from a public chat channel
-
Parameters:
Name Type Description channelName
string Chat channel name. userId
string User id. - Source:
- Photon-Javascript_SDK.js, line 4417
-
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 - Source:
- Photon-Javascript_SDK.js, line 4528
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. 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 - Source:
- Photon-Javascript_SDK.js, line 4559
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. 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 2633
-
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 4588
Returns:
True if command sent.- Type
- boolean
-
subscribe(channelNames, options, createOptions) → {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 createOptions
object <optional>
Room options for creation - Source:
- Photon-Javascript_SDK.js, line 4453
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. createOptions
object Room options for creation Properties
Name Type Argument Default Description publishSubscribers
boolean <optional>
false Whether or not the channel to be created will allow client to keep a list of users. maxSubscribers
number <optional>
0 Limit of the number of users subscribed to the channel to be created. 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 4508
Returns:
True if operation sent.- Type
- boolean