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_SDK.js, line 20

Members

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_SDK.js, line 35

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_SDK.js, line 162

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_SDK.js, line 152

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_SDK.js, line 172

connect()

Starts connection to server.

Source:
  • Photon-Javascript_SDK.js, line 80

disconnect()

Disconnects from server.

Source:
  • Photon-Javascript_SDK.js, line 118

isClosing() → {boolean}

Checks if peer is closing.

Source:
  • Photon-Javascript_SDK.js, line 71
Returns:
True if peer is closing.
Type
boolean

isConnected() → {boolean}

Checks if peer is connected.

Source:
  • Photon-Javascript_SDK.js, line 62
Returns:
True if peer is connected.
Type
boolean

isConnecting() → {boolean}

Checks if peer is connecting.

Source:
  • Photon-Javascript_SDK.js, line 53
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_SDK.js, line 248

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_SDK.js, line 259

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_SDK.js, line 192

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_SDK.js, line 221

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_SDK.js, line 182

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_SDK.js, line 212

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_SDK.js, line 202

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_SDK.js, line 230

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_SDK.js, line 127

setLogLevel(level)

Sets peer logger level.

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