new LoadBalancingClient(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 1488
Members
-
<static, readonly> PeerErrorCode
Enum for client peers error codes.
-
- Source:
- Photon-Javascript_SDK.js, line 3152
Properties:
Name Type Description Oknumber No Error. MasterErrornumber General Master server peer error. MasterConnectFailednumber Master server connection error. MasterConnectClosednumber Disconnected from Master server. MasterTimeoutnumber Disconnected from Master server for timeout. MasterEncryptionEstablishErrornumber Master server encryption establishing failed. MasterAuthenticationFailednumber Master server authentication failed. GameErrornumber General Game server peer error. GameConnectFailednumber Game server connection error. GameConnectClosednumber Disconnected from Game server. GameTimeoutnumber Disconnected from Game server for timeout. GameEncryptionEstablishErrornumber Game server encryption establishing failed. GameAuthenticationFailednumber Game 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> State
Enum for client states.
-
- Source:
- Photon-Javascript_SDK.js, line 3197
Properties:
Name Type Description Errornumber Critical error occurred. Uninitializednumber Client is created but not used yet. ConnectingToNameServernumber Connecting to NameServer. ConnectedToNameServernumber Connected to NameServer. ConnectingToMasterservernumber Connecting to Master (includes connect, authenticate and joining the lobby). ConnectedToMasternumber Connected to Master server. JoinedLobbynumber Connected to Master and joined lobby. Display room list and join/create rooms at will. ConnectingToGameservernumber Connecting to Game server(client will authenticate and join/create game). ConnectedToGameservernumber Connected to Game server (going to auth and join game). Joinednumber The client joined room. Disconnectednumber The client is no longer connected (to any server). Connect to Master to go on.
Methods
-
<static> StateToName(state) → {string}
Converts State element to string name.
-
Parameters:
Name Type Description statePhoton.LoadBalancing.LoadBalancingClient.State Client state enum element. - Source:
- Photon-Javascript_SDK.js, line 3134
Returns:
Specified element name or undefined if not found.- Type
- string
-
actorFactory(name, actorNr, isLocal)
Override with creation of custom actor (extended from Actor): { return new CustomActor(...); }
-
Parameters:
Name Type Description namestring Actor name. Pass to super() in custom room constructor. actorNrnumber Actor ID. Pass to super() in custom room constructor. isLocalboolean Actor is local. Pass to super() in custom room constructor. - Source:
- Photon-Javascript_SDK.js, line 1714
-
availableRooms() → {Photon.LoadBalancing.RoomInfo[]}
Current room list from Master server.
-
- Source:
- Photon-Javascript_SDK.js, line 2459
Returns:
Current room list -
changeGroups(groupsToRemove, groupsToAdd)
Changes client's interest groups (for events in room).
Note the difference between passing null and []: null won't add/remove any groups, [] will add/remove all (existing) groups.
First, removing groups is executed. This way, you could leave all groups and join only the ones provided. -
Parameters:
Name Type Description groupsToRemovenumber[] Groups to remove from interest. Null will not leave any. A [] will remove all. groupsToAddnumber[] Groups to add to interest. Null will not add any. A [] will add all current. - Source:
- Photon-Javascript_SDK.js, line 2254
-
connect(options) → {boolean}
Starts connection to Master server.
-
Parameters:
Name Type Argument Description optionsobject <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 1844
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Default Description keepMasterConnectionboolean <optional>
false Don't disconnect from Master server after joining room. lobbyNamestring <optional>
Name of the lobby connect to. lobbyTypePhoton.LoadBalancing.Constants.LobbyType <optional>
LobbyType.Default Type of the lobby. lobbyStatsboolean <optional>
false If true, Master server will be sending lobbies statistics periodically.
Override onLobbyStats to handle request results.
Alternatively, requestLobbyStats can be used.Returns:
True if current client state allows connection.- Type
- boolean
-
connectToNameServer(options) → {boolean}
Starts connection to NameServer.
-
Parameters:
Name Type Argument Description optionsobject <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 1887
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Default Description regionstring <optional>
If specified, Connect ro region master after succesfull connection to name server lobbyNamestring <optional>
Name of the lobby connect to. lobbyTypePhoton.LoadBalancing.Constants.LobbyType <optional>
LobbyType.Default Type of the lobby. lobbyStatsboolean <optional>
false If true, Master server will be sending lobbies statistics periodically.
Override onLobbyStats to handle request results.
Alternatively, requestLobbyStats can be used.keepMasterConnectionboolean <optional>
false Don't disconnect from Master server after joining room. Returns:
True if current client state allows connection.- Type
- boolean
-
connectToNameServer(options) → {boolean}
Starts connection to NameServer.
-
Parameters:
Name Type Argument Description optionsobject <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 4449
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Description regionstring <optional>
If specified, Connect ro region master after succesfull connection to name server Returns:
True if current client state allows connection.- Type
- boolean
-
connectToRegionMaster(region) → {boolean}
Connects to a specific region's Master server, using the NameServer to find the IP.
-
Parameters:
Name Type Description regionstring Region connect to Master server of. - Source:
- Photon-Javascript_SDK.js, line 2401
Returns:
True if current client state allows connection.- Type
- boolean
-
createRoom(roomName, options)
Creates a new room on the server (or fails when the name is already taken).
-
Parameters:
Name Type Argument Description roomNamestring <optional>
The name to create a room with. Must be unique and not in use or can't be created. If not specified or null, the server will assign a GUID as name. optionsobject <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 1991
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Default Description isVisibleboolean <optional>
true Shows the room in the lobby's room list. isOpenboolean <optional>
true Keeps players from joining the room (or opens it to everyone). maxPlayersnumber <optional>
0 Max players before room is considered full (but still listed). customGamePropertiesobject <optional>
Custom properties to apply to the room on creation (use string-typed keys but short ones). propsListedInLobbystring[] <optional>
Defines the custom room properties that get listed in the lobby. emptyRoomLiveTimenumber <optional>
0 Room live time (ms) in the server room cache after all clients have left the room. suspendedPlayerLiveTimenumber <optional>
0 Player live time (ms) in the room after player suspended. pluginsstring[] <optional>
Expected server plugins. lobbyNamestring <optional>
"" Name of the lobby to create room in. lobbyTypePhoton.LoadBalancing.Constants.LobbyType <optional>
LobbyType.Default Type of the lobby. expectedUsersstring[] <optional>
Expected users. -
createRoomFromMy(roomName, options)
Creates a new room on the server (or fails when the name is already taken). Takes parameters (except name) for new room from myRoom() object. Set them before call.
-
Parameters:
Name Type Argument Description roomNamestring <optional>
New room name. Assigned automatically by server if empty or not specified. optionsobject <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 1961
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Default Description lobbyNamestring <optional>
Name of the lobby to create room in. lobbyTypePhoton.LoadBalancing.Constants.LobbyType <optional>
LobbyType.Default Type of the lobby. -
disconnect()
Disconnects from all servers.
-
- Source:
- Photon-Javascript_SDK.js, line 2160
-
findFriends(friendsToFind)
Requests Master server for actors online status and joined rooms.
Override onFindFriendsResult to handle request results. -
Parameters:
Name Type Description friendsToFindstring[] Actors names. - Source:
- Photon-Javascript_SDK.js, line 2268
-
getMasterServerAddress() → {string}
Returns current Master server address.
-
- Source:
- Photon-Javascript_SDK.js, line 1805
Returns:
Master server address.- Type
- string
-
getNameServerAddress() → {string}
Returns current NameServer address.
-
- Source:
- Photon-Javascript_SDK.js, line 1789
Returns:
NameServer address address.- Type
- string
-
getRegions()
Requests NameServer for regions list.
Override onGetRegionsResult to handle request results. -
- Source:
- Photon-Javascript_SDK.js, line 2362
-
getUserId() → {string}
Returns previously set user id.
-
- Source:
- Photon-Javascript_SDK.js, line 1821
Returns:
User id.- Type
- string
-
isConnectedToMaster() → {boolean}
Checks if client is connected to Master server (usually joined to lobby and receives room list updates).
-
- Source:
- Photon-Javascript_SDK.js, line 2421
Returns:
True if client is connected to Master server.- 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
-
isInLobby() → {boolean}
Checks if client is in lobby and ready to join or create game.
-
- Source:
- Photon-Javascript_SDK.js, line 2437
Returns:
True if client is in lobby.- Type
- boolean
-
isJoinedToRoom() → {boolean}
Checks if client is joined to game.
-
- Source:
- Photon-Javascript_SDK.js, line 2445
Returns:
True if client is joined to game.- Type
- boolean
-
joinRandomRoom(options)
Joins a random, available room. This operation fails if all rooms are closed or full.
-
Parameters:
Name Type Argument Description optionsobject <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 2063
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Default Description expectedCustomRoomPropertiesobject <optional>
If specified, a room will only be joined, if it matches these custom properties. Use null to accept rooms with any properties. expectedMaxPlayersnumber <optional>
If specified, filters for a particular maxPlayer setting. Use 0 to accept any maxPlayer value. matchmakingModePhoton.LoadBalancing.Constants.MatchmakingMode <optional>
MatchmakingMode.FillRoom Selects one of the available matchmaking algorithms. lobbyNamestring <optional>
Name of the lobby to search rooms in. lobbyTypePhoton.LoadBalancing.Constants.LobbyType <optional>
LobbyType.Default Type of the lobby. sqlLobbyFilterstring <optional>
Basically the "where" clause of a sql statement. Examples: 'C0 = 1 AND C2 > 50'. 'C5 = "Map2" AND C2 > 10 AND C2 < 20' expectedUsersstring[] <optional>
Expected users. -
joinRoom(roomName, options, createOptions)
Joins a room by name and sets this player's properties.
-
Parameters:
Name Type Argument Description roomNamestring The name of the room to join. Must be existing already, open and non-full or can't be joined. optionsobject <optional>
Additional options createOptionsobject <optional>
Room options for creation - Source:
- Photon-Javascript_SDK.js, line 2016
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Default Description rejoinboolean <optional>
false Rejoin using current userId. createIfNotExistsboolean <optional>
false Create room if not exists. expectedUsersstring[] <optional>
Expected users. createOptionsobject Room options for creation Properties
Name Type Argument Default Description isVisibleboolean <optional>
true Shows the room in the lobby's room list. isOpenboolean <optional>
true Keeps players from joining the room (or opens it to everyone). maxPlayersnumber <optional>
0 Max players before room is considered full (but still listed). customGamePropertiesobject <optional>
Custom properties to apply to the room on creation (use string-typed keys but short ones). propsListedInLobbystring[] <optional>
Defines the custom room properties that get listed in the lobby. emptyRoomLiveTimenumber <optional>
0 Room live time (ms) in the server room cache after all clients have left the room. suspendedPlayerLiveTimenumber <optional>
0 Player live time (ms) in the room after player suspended. pluginsstring[] <optional>
Informs the server of the expected plugin setup. lobbyNamestring <optional>
"" Name of the lobby to create room in. lobbyTypePhoton.LoadBalancing.Constants.LobbyType <optional>
LobbyType.Default Type of the lobby. -
leaveRoom()
Leaves room and connects to Master server if not connected.
-
- Source:
- Photon-Javascript_SDK.js, line 2208
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Description sendAuthCookieboolean <optional>
Securely transmit the encrypted object AuthCookie to the web service in PathLeave webhook when available -
myActor() → {Photon.LoadBalancing.Actor}
Returns local actor. Client always has local actor even if not joined.
-
- Source:
- Photon-Javascript_SDK.js, line 1723
Returns:
Local actor. -
myRoom() → {Photon.LoadBalancing.Room}
Returns client's room. Client always has it's room even if not joined. It's used for room creation operation.
-
- Source:
- Photon-Javascript_SDK.js, line 1730
Returns:
Current room. -
myRoomActorCount() → {number}
Returns numer of actors in room client currently joined including local actor.
-
- Source:
- Photon-Javascript_SDK.js, line 1743
Returns:
Number of actors.- Type
- number
-
myRoomActors() → {object}
Returns actors in room client currently joined including local actor.
-
- Source:
- Photon-Javascript_SDK.js, line 1737
Returns:
actorNr -> Photon.LoadBalancing.Actor map of actors in room.- Type
- object
-
myRoomMasterActorNr() → {number}
Actor number of the player who's the master of this Room. Note: This changes when the current master leaves the room.
-
- Source:
- Photon-Javascript_SDK.js, line 1750
Returns:
- Type
- number
-
onActorJoin(actor)
Called when new actor joins the room client joined to. Override to handle it.
-
Parameters:
Name Type Description actorPhoton.LoadBalancing.Actor New actor. - Source:
- Photon-Javascript_SDK.js, line 1631
-
onActorLeave(actor, cleanup)
Called when actor leaves the room client joined to. Also called for every actor during room cleanup. Override to handle it.
-
Parameters:
Name Type Description actorPhoton.LoadBalancing.Actor Actor left the room. cleanupboolean True if called during room cleanup (e.g. on disconnect). - Source:
- Photon-Javascript_SDK.js, line 1637
-
onActorPropertiesChange(actor)
Called on actor properties changed event. Override to handle it.
-
Parameters:
Name Type Description actorPhoton.LoadBalancing.Actor Actor whose properties were changed. - Source:
- Photon-Javascript_SDK.js, line 1619
-
onActorSuspend(actor)
Called when actor suspended in the room client joined to.Override to handle it.
-
Parameters:
Name Type Description actorPhoton.LoadBalancing.Actor Actor suspended in the room. - Source:
- Photon-Javascript_SDK.js, line 1644
-
onAppStats(errorCode, errorMsg, stats)
Called when application statistics update received.
Override to handle request results. -
Parameters:
Name Type Description errorCodenumber Result error code. Currently is always 0. errorMsgstring Error message. Currently is always empty. statsobject Application statistics. - Source:
- Photon-Javascript_SDK.js, line 1677
Properties:
Name Type Description statsobject Application statistics. Properties
Name Type Description peerCountnumber Count of players currently online on Game servers. masterPeerCountnumber Count of players on Master server (looking for game). gameCountnumber Count of games currently in use (includes invisible and full rooms, so it doesn't match lobby list). -
onError(errorCode, errorMsg)
Called if client error occures. Override to handle it.
-
Parameters:
Name Type Description errorCodePhoton.LoadBalancing.LoadBalancingClient.PeerErrorCode Client error code. errorMsgstring Error message. - Source:
- Photon-Javascript_SDK.js, line 1574
-
onEvent(code, content, actorNr)
Called on custom event. Override to handle it.
-
Parameters:
Name Type Description codenumber Event code. contentobject Event content. actorNrnumber Actor ID event raised by. - Source:
- Photon-Javascript_SDK.js, line 1590
-
onFindFriendsResult(errorCode, errorMsg, friends)
Called when findFriends request completed.
Override to handle request results. -
Parameters:
Name Type Description errorCodenumber Result error code. 0 if request is successful. errorMsgstring Error message. friendsobject Table with actors names as keys and friend statuses as values: {name1: friendStatus1, name2: friendStatus2, ... }. - Source:
- Photon-Javascript_SDK.js, line 1650
Properties:
Name Type Description friendStatusobject Friend status. Properties
Name Type Description onlineboolean Online status. roomIdstring Joined room. -
onJoinRoom(createdByMe)
Called when client joins room. Override to handle it.
-
Parameters:
Name Type Description createdByMeboolean True if room is created by client. - Source:
- Photon-Javascript_SDK.js, line 1625
-
onLobbyStats(errorCode, errorMsg, lobbies)
Called when lobbies statistics update received.
Update can be automated by set up during connect or requested explicitly by requestLobbyStats.
Override to handle request results. -
Parameters:
Name Type Description errorCodenumber Result error code. 0 if request is successful. For automated updates is always 0. errorMsgstring Error message. For automated updates is always empty. lobbiesobject[] Array of lobbies statistics: [lobbyStats1, lobbyStats1, ... ]. - Source:
- Photon-Javascript_SDK.js, line 1662
Properties:
Name Type Description lobbyStatsobject Lobby statistics. Properties
Name Type Description lobbyNamestring Lobby name. lobbyTypenumber Lobby type. peerCountnumber The number of players in the lobby (on Master, not playing). gameCountnumber The number of games in the lobby. -
onMyRoomPropertiesChange()
Called on joined room properties changed event. Override to handle it.
-
- Source:
- Photon-Javascript_SDK.js, line 1614
-
onOperationResponse(errorCode, errorMsg, code, content)
Called on operation response. Override if need custom workflow or response error handling.
-
Parameters:
Name Type Description errorCodenumber Server error code. errorMsgstring Error message. codenumber Operation code. contentobject Operation response content. - Source:
- Photon-Javascript_SDK.js, line 1581
-
onRoomList(rooms)
Called on room list received from Master server (on connection). Override to handle it.
-
Parameters:
Name Type Description roomsPhoton.LoadBalancing.RoomInfo[] Room list. - Source:
- Photon-Javascript_SDK.js, line 1598
-
onRoomListUpdate(rooms, roomsUpdated, roomsAdded, roomsRemoved)
Called on room list updates received from Master server. Override to handle it.
-
Parameters:
Name Type Description roomsPhoton.LoadBalancing.RoomInfo[] Updated room list. roomsUpdatedPhoton.LoadBalancing.RoomInfo[] Rooms whose properties were changed. roomsAddedPhoton.LoadBalancing.RoomInfo[] New rooms in list. roomsRemovedPhoton.LoadBalancing.RoomInfo[] Rooms removed from list. - Source:
- Photon-Javascript_SDK.js, line 1604
-
onStateChange(state)
Called on client state change. Override to handle it.
-
Parameters:
Name Type Description statePhoton.LoadBalancing.LoadBalancingClient.State New client state. - Source:
- Photon-Javascript_SDK.js, line 1568
-
raiseEvent(eventCode, data, options)
Raises game custom event
-
Parameters:
Name Type Argument Description eventCodenumber Identifies this type of event (and the content). Your game's event codes can start with 0. dataobject <optional>
Custom data you want to send along (use null, if none). optionsobject <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 2236
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Default Description interestGroupnumber <optional>
The ID of the interest group this event goes to (exclusively). cachePhoton.LoadBalancing.Constants.EventCaching <optional>
EventCaching.DoNotCache Events can be cached (merged and removed) for players joining later on. receiversPhoton.LoadBalancing.Constants.ReceiverGroup <optional>
ReceiverGroup.Others Defines to which group of players the event is passed on. targetActorsnumber[] <optional>
Defines the target players who should receive the event (use only for small target groups). webForwardboolean <optional>
false Forward to web hook. -
requestLobbyStats(lobbiesToRequest)
Requests Master server for lobbies statistics.
Override onLobbyStats to handle request results.
Alternatively, automated updates can be set up during connect. -
Parameters:
Name Type Description lobbiesToRequestany[] Array of lobbies id pairs [ [lobbyName1, lobbyType1], [lobbyName2, lobbyType2], ... ]. If not specified or null, statistics for all lobbies requested. - Source:
- Photon-Javascript_SDK.js, line 2301
-
roomFactory(name)
Override with creation of custom room (extended from Room): { return new CustomRoom(...); }
-
Parameters:
Name Type Description namestring Room name. Pass to super() in custom actor constructor. - Source:
- Photon-Javascript_SDK.js, line 1708
-
setCustomAuthentication(authParameters, authType, authData)
Enables custom authentication and sets it's parameters.
-
Parameters:
Name Type Argument Default Description authParametersstring This string must contain any (http get) parameters expected by the used authentication service. authTypePhoton.LoadBalancing.Constants.CustomAuthenticationType <optional>
Photon.LoadBalancing.Constants.CustomAuthenticationType.Custom The type of custom authentication provider that should be used. authDataany <optional>
The data to be passed-on to the auth service via POST. String passed as is, objects as application/json - Source:
- Photon-Javascript_SDK.js, line 1829
-
setLogLevel(level)
Sets client logger level
-
Parameters:
Name Type Description levelExitgames.Common.Logger.Level Logging level. - Source:
- Photon-Javascript_SDK.js, line 2465
-
setMasterServerAddress(address)
Changes default Master server address and port before connecting to Master server.
-
Parameters:
Name Type Description addressstring New address and port. - Source:
- Photon-Javascript_SDK.js, line 1797
-
setNameServerAddress(address)
Changes default NameServer address and port before connecting to NameServer.
-
Parameters:
Name Type Description addressstring New address and port. - Source:
- Photon-Javascript_SDK.js, line 1781
-
setUserId(userId)
Sets user ID required for authentication and FindFriends service. The value will be used the next time you connect. Set this ID before you connect, not while being connected.
-
Parameters:
Name Type Description userIdstring New user id. - Source:
- Photon-Javascript_SDK.js, line 1813
-
suspendRoom()
Disconnects client from Game server keeping player in room (to rejoin later) and connects to Master server if not connected.
-
- Source:
- Photon-Javascript_SDK.js, line 2179
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Description sendAuthCookieboolean <optional>
Securely transmit the encrypted object AuthCookie to the web service in PathLeave webhook when available -
webRpc(uriPath, parameters, options)
Sends web rpc request to Master server.
Override onWebRpcResult to handle request results. -
Parameters:
Name Type Argument Description uriPathstring Request path. parametersobject Request parameters. optionsobject <optional>
Additional options - Source:
- Photon-Javascript_SDK.js, line 2377
Properties:
Name Type Description optionsobject Additional options Properties
Name Type Argument Description sendAuthCookieboolean <optional>
Defines if the authentication cookie gets sent to a WebHook (if setup)