Class: PhotonPeer

Photon. PhotonPeer

Instances of the PhotonPeer class are used to connect to a Photon server and communicate with it. A PhotonPeer instance allows communication with the Photon Server, which in turn distributes messages to other PhotonPeer clients. An application can use more than one PhotonPeer instance, which are treated as separate users on the server. Each should have its own listener instance, to separate the operations, callbacks and events.

new PhotonPeer(url, subprotocol, debugName)

Parameters:
Name Type Argument Default Description
url string Server address:port.
subprotocol string <optional>
"" WebSocket protocol.
debugName string <optional>
"" Log messages prefixed with this value.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 24

Members

<static, readonly> StatusCodes

Enum for peer status codes. Use to subscribe to status changes.

Properties:
Name Type Description
connecting string Is connecting to server.
connect string Connected to server.
connectFailed string Connection to server failed.
disconnect string Disconnected from server.
connectClosed string Connection closed by server.
error string General connection error.
timeout string Disconnected from server for timeout.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 511

keepAliveTimeoutMs :number

Peer sends 'keep alive' message to server as this timeout exceeded after last send operation. Set it < 1000 to disable 'keep alive' operation

Default Value:
  • 5000
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 39

Methods

addEventListener(eventCode, callback)

Registers listener for custom event.

Parameters:
Name Type Description
eventCode number Custom event code.
callback Function The listener function that processes the event. This function may accept object with event content.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 159

addPeerStatusListener(statusCode, callback)

Registers listener for peer status change.

Parameters:
Name Type Description
statusCode PhotonPeer.StatusCodes Status change to this value will be listening.
callback Function The listener function that processes the status change. This function don't accept any parameters.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 150

addResponseListener(operationCode, callback)

Registers listener for operation response.

Parameters:
Name Type Description
operationCode number Operation code.
callback Function The listener function that processes the event. This function may accept object with operation response content.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 168

connect()

Starts connection to server.

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

disconnect()

Disconnects from server.

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

isClosing() → {boolean}

Checks if peer is closing.

Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 72
Returns:
True if peer is closing.
Type
boolean

isConnected() → {boolean}

Checks if peer is connected.

Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 66
Returns:
True if peer is connected.
Type
boolean

isConnecting() → {boolean}

Checks if peer is connecting.

Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 59
Returns:
True if peer is connecting.
Type
boolean

onUnhandledEvent(eventCode, args)

Called if no listener found for received custom event. Override to relay unknown event to user's code or handle known events without listener registration.

Parameters:
Name Type Argument Description
eventCode number Code of received event.
args object <optional>
Content of received event or empty object.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 236

onUnhandledEvent(operationCode, args)

Called if no listener found for received operation response event. Override to relay unknown response to user's code or handle known responses without listener registration.

Parameters:
Name Type Argument Description
operationCode number Code of received response.
args object <optional>
Content of received response or empty object.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 246

removeEventListener(eventCode, callback)

Removes listener if exists for custom event.

Parameters:
Name Type Description
eventCode number Event code to remove to remove listener for.
callback Function Listener to remove.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 186

removeEventListenersForCode(eventCode)

Removes all listeners for custom event specified.

Parameters:
Name Type Description
eventCode number Event code to remove all listeners for.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 212

removePeerStatusListener(statusCode, callback)

Removes listener if exists for peer status change.

Parameters:
Name Type Description
statusCode string One of PhotonPeer.StatusCodes to remove listener for.
callback Function Listener to remove.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 177

removePeerStatusListenersForCode(statusCode)

Removes all listeners for peer status change specified.

Parameters:
Name Type Description
statusCode string One of PhotonPeer.StatusCodes to remove all listeners for.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 204

removeResponseListener(operationCode, callback)

Removes listener if exists for operation response.

Parameters:
Name Type Description
operationCode number Operation code to remove listener for.
callback Function Listener to remove.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 195

removeResponseListenersForCode(operationCode)

Removes all listeners for operation response specified.

Parameters:
Name Type Description
operationCode number Operation code to remove all listeners for.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 220

sendOperation(code, data, sendReliable, channelId)

Sends operation to the Photon Server.

Parameters:
Name Type Argument Default Description
code number Code of operation.
data object <optional>
Parameters of operation as a flattened array of key-value pairs: [key1, value1, key2, value2...]
sendReliable boolean <optional>
false Selects if the operation must be acknowledged or not. If false, the operation is not guaranteed to reach the server.
channelId number <optional>
0 The channel in which this operation should be sent.
Source:
  • Photon-Javascript_v4-0-0-7_Cloud_SDK.js, line 124

setLogLevel(level)

Sets peer logger level.

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