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 348
Members
-
<static, readonly> StatusCodes
Enum for peer status codes. Use to subscribe to status changes.
-
- Source:
- Photon-Javascript_SDK.js, line 864
Properties:
Name Type Description connectingstring Is connecting to server. connectstring Connected to server. connectFailedstring Connection to server failed. disconnectstring Disconnected from server. connectClosedstring Connection closed by server. errorstring General connection error. timeoutstring Disconnected from server for timeout. -
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 365
Methods
-
addEventListener(eventCode, callback)
Registers listener for custom event.
-
Parameters:
Name Type Description eventCodenumber Custom event code. callbackFunction The listener function that processes the event. This function may accept object with event content. - Source:
- Photon-Javascript_SDK.js, line 510
-
addPeerStatusListener(statusCode, callback)
Registers listener for peer status change.
-
Parameters:
Name Type Description statusCodePhotonPeer.StatusCodes Status change to this value will be listening. callbackFunction The listener function that processes the status change. This function don't accept any parameters. - Source:
- Photon-Javascript_SDK.js, line 501
-
addResponseListener(operationCode, callback)
Registers listener for operation response.
-
Parameters:
Name Type Description operationCodenumber Operation code. callbackFunction The listener function that processes the event. This function may accept object with operation response content. - Source:
- Photon-Javascript_SDK.js, line 519
-
connect()
Starts connection to server.
-
- Source:
- Photon-Javascript_SDK.js, line 426
-
disconnect()
Disconnects from server.
-
- Source:
- Photon-Javascript_SDK.js, line 465
-
isClosing() → {boolean}
Checks if peer is closing.
-
- Source:
- Photon-Javascript_SDK.js, line 420
Returns:
True if peer is closing.- Type
- boolean
-
isConnected() → {boolean}
Checks if peer is connected.
-
- Source:
- Photon-Javascript_SDK.js, line 414
Returns:
True if peer is connected.- Type
- boolean
-
isConnecting() → {boolean}
Checks if peer is connecting.
-
- Source:
- Photon-Javascript_SDK.js, line 407
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 eventCodenumber Code of received event. argsobject <optional>
Content of received event or empty object. - Source:
- Photon-Javascript_SDK.js, line 587
-
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 operationCodenumber Code of received response. argsobject <optional>
Content of received response or empty object. - Source:
- Photon-Javascript_SDK.js, line 597
-
removeEventListener(eventCode, callback)
Removes listener if exists for custom event.
-
Parameters:
Name Type Description eventCodenumber Event code to remove to remove listener for. callbackFunction Listener to remove. - Source:
- Photon-Javascript_SDK.js, line 537
-
removeEventListenersForCode(eventCode)
Removes all listeners for custom event specified.
-
Parameters:
Name Type Description eventCodenumber Event code to remove all listeners for. - Source:
- Photon-Javascript_SDK.js, line 563
-
removePeerStatusListener(statusCode, callback)
Removes listener if exists for peer status change.
-
Parameters:
Name Type Description statusCodestring One of PhotonPeer.StatusCodes to remove listener for. callbackFunction Listener to remove. - Source:
- Photon-Javascript_SDK.js, line 528
-
removePeerStatusListenersForCode(statusCode)
Removes all listeners for peer status change specified.
-
Parameters:
Name Type Description statusCodestring One of PhotonPeer.StatusCodes to remove all listeners for. - Source:
- Photon-Javascript_SDK.js, line 555
-
removeResponseListener(operationCode, callback)
Removes listener if exists for operation response.
-
Parameters:
Name Type Description operationCodenumber Operation code to remove listener for. callbackFunction Listener to remove. - Source:
- Photon-Javascript_SDK.js, line 546
-
removeResponseListenersForCode(operationCode)
Removes all listeners for operation response specified.
-
Parameters:
Name Type Description operationCodenumber Operation code to remove all listeners for. - Source:
- Photon-Javascript_SDK.js, line 571
-
sendOperation(code, data, sendReliable, channelId)
Sends operation to the Photon Server.
-
Parameters:
Name Type Argument Default Description codenumber Code of operation. dataobject <optional>
Parameters of operation as a flattened array of key-value pairs: [key1, value1, key2, value2...] sendReliableboolean <optional>
false Selects if the operation must be acknowledged or not. If false, the operation is not guaranteed to reach the server. channelIdnumber <optional>
0 The channel in which this operation should be sent. - Source:
- Photon-Javascript_SDK.js, line 475
-
setLogLevel(level)
Sets peer logger level.
-
Parameters:
Name Type Description levelExitgames.Common.Logger.Level Logging level. - Source:
- Photon-Javascript_SDK.js, line 579