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(protocol, address, subprotocol, debugName)

Parameters:
Name Type Argument Default Description
protocol Photon.ConnectionProtocol Connection protocol.
address string Server address:port.
subprotocol string <optional>
"" WebSocket protocol.
debugName string <optional>
"" Log messages prefixed with this value.
Source:
  • Photon-Javascript_SDK.js, line 350

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

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:
  • 3000
Source:
  • Photon-Javascript_SDK.js, line 367

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 521

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 512

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 530

connect()

Starts connection to server.

Source:
  • Photon-Javascript_SDK.js, line 437

disconnect()

Disconnects from server.

Source:
  • Photon-Javascript_SDK.js, line 476

isClosing() → {boolean}

Checks if peer is closing.

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

isConnected() → {boolean}

Checks if peer is connected.

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

isConnecting() → {boolean}

Checks if peer is connecting.

Source:
  • Photon-Javascript_SDK.js, line 412
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 598

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 608

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 548

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 574

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 539

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 566

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 557

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 582

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 486

setLogLevel(level)

Sets peer logger level.

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