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 4355
Members
-
<static, readonly> ChatPeerErrorCode
Enum for client peers error codes.
-
- Source:
- Photon-Javascript_SDK.js, line 4846
Properties:
Name Type Description Oknumber No Error. FrontEndErrornumber General FrontEnd server peer error. FrontEndConnectFailednumber FrontEnd server connection error. FrontEndConnectClosednumber Disconnected from FrontEnd server. FrontEndTimeoutnumber Disconnected from FrontEnd server for timeout. FrontEndEncryptionEstablishErrornumber FrontEnd server encryption establishing failed. FrontEndAuthenticationFailednumber FrontEnd server authentication failed. NameServerErrornumber General NameServer peer error. NameServerConnectFailednumber NameServer connection error. NameServerConnectClosednumber Disconnected from NameServer. NameServerTimeoutnumber Disconnected from NameServer for timeout. NameServerEncryptionEstablishErrornumber NameServer encryption establishing failed. NameServerAuthenticationFailednumber NameServer authentication failed. -
<static, readonly> ChatState
Enum for client states.
-
- Source:
- Photon-Javascript_SDK.js, line 4879
Properties:
Name Type Description Errornumber Critical error occurred. Uninitializednumber Client is created but not used yet. ConnectingToNameServernumber Connecting to NameServer. ConnectedToNameServernumber Connected to NameServer. ConnectingToFrontEndnumber Connecting to FrontEnd server. ConnectedToFrontEndnumber Connected to FrontEnd server. Disconnectednumber The client is no longer connected (to any server).
Methods
-
<static> StateToName(state) → {string}
Converts ChatState element to string name.
-
Parameters:
Name Type Description statePhoton.Chat.ChatClient.ChatState Client state. - Source:
- Photon-Javascript_SDK.js, line 4829
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 regionstring Region connect to Master server of. - Source:
- Photon-Javascript_SDK.js, line 4460
Returns:
True if current client state allows connection.- Type
- boolean
-
disconnect()
Disconnects from all servers.
-
- Source:
- Photon-Javascript_SDK.js, line 2160
-
getRegions()
Requests NameServer for regions list.
Override onGetRegionsResult to handle request results. -
- Source:
- Photon-Javascript_SDK.js, line 2362
-
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 4470
Returns:
True if connected.- Type
- boolean
-
isConnectedToNameServer() → {boolean}
Checks if client is connected to NameServer server.
-
- Source:
- Photon-Javascript_SDK.js, line 2429
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 channelNamestring Chat channel name. messagesPhoton.Chat.Message[] Array of received messages. - Source:
- Photon-Javascript_SDK.js, line 4409
-
onPrivateMessage(channelName, message)
Called when new private message received.
Override to handle message receive event. -
Parameters:
Name Type Description channelNamestring Private channel name(counterpart user id). messagePhoton.Chat.Message Received message. - Source:
- Photon-Javascript_SDK.js, line 4417
-
onStateChange(state)
Called on client state change. Override to handle it.
-
Parameters:
Name Type Description statePhoton.Chat.ChatClient.ChatState New client state. - Source:
- Photon-Javascript_SDK.js, line 4382
-
onSubscribeResult(results)
Called when subscribe request completed.
Override to handle request results. -
Parameters:
Name Type Description resultsobject Object with channel names as keys and boolean results as values. - Source:
- Photon-Javascript_SDK.js, line 4395
-
onUnsubscribeResult(results)
Called when unsubscribe request completed.
Override to handle request results. -
Parameters:
Name Type Description resultsobject Object with channel names as keys and boolean results as values. - Source:
- Photon-Javascript_SDK.js, line 4402
-
onUserStatusUpdate(userId, status, gotMessage, statusMessage)
Called when user from friend list changes state.
Override to handle change state event. -
Parameters:
Name Type Description userIdstring User id. statusnumber New User status. Predefined Constants.UserStatus or custom. gotMessageboolean True if status message updated. statusMessagestring Optional status message (may be null even if gotMessage = true). - Source:
- Photon-Javascript_SDK.js, line 4425
-
onUserSubscribe(channelName, userId)
A user has subscribed to a public chat channel
-
Parameters:
Name Type Description channelNamestring Chat channel name. userIdstring User id. - Source:
- Photon-Javascript_SDK.js, line 4435
-
onUserUnsubscribe(channelName, userId)
A user has unsubscribed from a public chat channel
-
Parameters:
Name Type Description channelNamestring Chat channel name. userIdstring User id. - Source:
- Photon-Javascript_SDK.js, line 4442
-
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 channelNamestring Channel name to send message to. contentany Text string or arbitrary data to send. optionsobject <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 4553
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Description webForwardboolean <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 userIdstring User id to send this message to. contentany Text string or arbitrary data to send. optionsobject <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 4584
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Description webForwardboolean <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 levelExitgames.Common.Logger.Level Logging level. - Source:
- Photon-Javascript_SDK.js, line 2465
-
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 statusnumber User status to set. messagestring <optional>
null State message. skipMessageboolean <optional>
false If true { client does not send state message. - Source:
- Photon-Javascript_SDK.js, line 4613
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 channelNamesstring[] Array of channel names to subscribe to. optionsobject <optional>
Additional options createOptionsobject <optional>
Room options for creation - Source:
- Photon-Javascript_SDK.js, line 4478
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Description historyLengthnumber <optional>
Controls messages history sent on subscription. Not specified or 0: no history. 1 and higher: number of messages in history. -1: all history. lastIdsnumber[] <optional>
Array of IDs of last messages received per channel. Useful when resubscribing to receive only messages we missed. createOptionsobject Room options for creation Properties
Name Type Argument Default Description publishSubscribersboolean <optional>
false Whether or not the channel to be created will allow client to keep a list of users. maxSubscribersnumber <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 channelNamesstring[] Array of channel names to unsubscribe from. - Source:
- Photon-Javascript_SDK.js, line 4533
Returns:
True if operation sent.- Type
- boolean