realtime

Functions and constants for interacting with Photon Realtime

Version: stable

FUNCTIONS
realtime.init()
realtime.connect()
realtime.update()
realtime.disconnect()
realtime.join_lobby()
realtime.leave_lobby()
realtime.create_room()
realtime.join_room()
realtime.join_or_create_room()
realtime.join_or_create_random_room()
realtime.int JoinRandomRoom()
realtime.leave_room()
realtime.get_room_list()
realtime.raise_event()
realtime.set_auto_join_lobby()
CONSTANTS
EVENT_CONNECTIONERRORRETURN
EVENT_CLIENTERRORRETURN
EVENT_WARNINGRETURN
EVENT_SERVERERRORRETURN
EVENT_JOINROOMEVENTACTION
EVENT_LEAVEROOMEVENTACTION
EVENT_CUSTOMEVENTACTION
EVENT_CONNECTRETURN
EVENT_DISCONNECTRETURN
EVENT_CREATEROOMRETURN
EVENT_JOINORCREATEROOMRETURN
EVENT_JOINRANDOMORCREATEROOMRETURN
EVENT_JOINROOMRETURN
EVENT_JOINRANDOMROOMRETURN
EVENT_LEAVEROOMRETURN
EVENT_JOINLOBBYRETURN
EVENT_LEAVELOBBYRETURN
EVENT_ONFINDFRIENDSRESPONSE
EVENT_ONLOBBYSTATSRESPONSE
EVENT_WEBRPCRETURN
EVENT_ONROOMLISTUPDATE
EVENT_ONROOMPROPERTIESCHANGE
EVENT_ONPLAYERPROPERTIESCHANGE
EVENT_ONAPPSTATSUPDATE
EVENT_ONLOBBYSTATSUPDATE
EVENT_ONCACHESLICECHANGED
EVENT_ONMASTERCLIENTCHANGED
EVENT_ONCUSTOMAUTHENTICATIONINTERMEDIATESTEP
EVENT_ONAVAILABLEREGIONS
EVENT_ONSECRETRECEIVAL
EVENT_ONDIRECTCONNECTIONESTABLISHED
EVENT_ONDIRECTCONNECTIONFAILEDTOESTABLISH
EVENT_ONDIRECTMESSAGE
EVENT_ONCUSTOMOPERATIONRESPONSE
EVENT_ONGETROOMLISTRESPONSE
AUTH_CUSTOM
AUTH_STEAM
AUTH_FACEBOOK
AUTH_OCULUS
AUTH_PLAYSTATION_4
AUTH_XBOX
AUTH_VIVEPORT
AUTH_NINTENDO_SWITCH
AUTH_PLAYSTATION_5
AUTH_EPIC
AUTH_FACEBOOK_GAMING
AUTH_NONE
SERVER_TYPE_NAME_SERVER
SERVER_TYPE_MASTER_SERVER
MATCHMAKINGMODE_FILL_ROOM
MATCHMAKINGMODE_SERIAL_MATCHING
MATCHMAKINGMODE_RANDOM_MATCHING
LOBBYTYPE_DEFAULT
LOBBYTYPE_SQL_LOBBY
LOBBYTYPE_ASYNC_RANDOM_LOBBY
DIRECTMODE_NONE
DIRECTMODE_ALL_TO_OTHERS
DIRECTMODE_MASTER_TO_OTHERS
DIRECTMODE_ALL_TO_ALL
DIRECTMODE_MASTER_TO_ALL

Functions

realtime.init()

realtime.init(app_id)

Initialize Realtime by creating a load balanced client

PARAMETERS

app_id string

realtime.connect()

realtime.connect(options,callback)

Connect to the server. - username - use_datagram_encryption - server_type See SERVER_TYPE_* enums - server_address The IP address or domain name and optionally the port number to connect to. IP addresses can be in IPv4 or IPv6 format - auth_data Sets the HTTP POST data, that will be forwarded to the authentication service, to the provided data. - auth_parameters The HTTP GET parameters that will be forwarded to the authentication service to the provided parameters. - auth_type The type of the "Custom Authentication" service that will be used. See AUTH_* enums

PARAMETERS

options None
Table with connection options
callback None

realtime.update()

realtime.update()

Update Realtime. Call this from a script component.

PARAMETERS

None


realtime.disconnect()

realtime.disconnect()

Disconnect from server.

PARAMETERS

None


realtime.join_lobby()

realtime.join_lobby(lobby_name,lobby_type)

Join lobby.

PARAMETERS

lobby_name string
lobby_type number

realtime.leave_lobby()

realtime.leave_lobby()

Leave lobby.

PARAMETERS

None


realtime.create_room()

realtime.create_room(game_id,room_options,expected_users)

Create room. Local game_id = "1234" local room_options = { is_visible = false, is_open = false, supress_room_events = false, max_players = 4, player_ttl = 0, empty_room_ttl = 0, lobby_type = realtime.LOBBYTYPE_DEFAULT, lobby_name = "", publish_user_id = "", direct_mode = realtime.DIRECTMODE_NONE, props_listed_in_lobby = {}, custom_room_properties = {}, } local expected_users = {} realtime.create_room(game_id, room_options, expected_users)

PARAMETERS

game_id string
The name to create a room with. Must be unique and not in use or the room can't be created. If this is an empty string, then the server will assign a GUID as name.
room_options table
expected_users table

realtime.join_room()

realtime.join_room(game_id,join_options)

Join room. Local game_id = "1234" local join_options = { rejoin = false, cache_slice_index = 0, expected_users = {}, } realtime.join_room(game_id, join_options)

PARAMETERS

game_id string
The name to create a room with. Must be unique and not in use or the room can't be created. If this is an empty string, then the server will assign a GUID as name.
join_options table

realtime.join_or_create_room()

realtime.join_or_create_room(game_id,room_options,join_options)

Join or create room. Local game_id = "1234" local room_options = { is_visible = false, is_open = false, supress_room_events = false, max_players = 4, player_ttl = 0, empty_room_ttl = 0, lobby_type = realtime.LOBBYTYPE_DEFAULT, lobby_name = "", publish_user_id = "", direct_mode = realtime.DIRECTMODE_NONE, props_listed_in_lobby = {}, custom_room_properties = {}, } local join_options = { custom_room_properties = {}, max_players = 0, matchmaking_mode = realtime.MATCHMAKINGMODE_FILL_ROOM, lobby_name = "", lobby_type = realtime.LOBBYTYPE_DEFAULT, sql_lobby_filter = "", expected_users = {}, }

PARAMETERS

game_id string
The name to create a room with. Must be unique and not in use or the room can't be created. If this is an empty string, then the server will assign a GUID as name.
room_options table
join_options table

realtime.join_or_create_random_room()

realtime.join_or_create_random_room(game_id,room_options,join_options)

Join or create random room. Local game_id = "1234" local room_options = { is_visible = false, is_open = false, supress_room_events = false, max_players = 4, player_ttl = 0, empty_room_ttl = 0, lobby_type = realtime.LOBBYTYPE_DEFAULT, lobby_name = "", publish_user_id = "", direct_mode = realtime.DIRECTMODE_NONE, props_listed_in_lobby = {}, custom_room_properties = {}, } local join_options = { custom_room_properties = {}, max_players = 0, matchmaking_mode = realtime.MATCHMAKINGMODE_FILL_ROOM, lobby_name = "", lobby_type = realtime.LOBBYTYPE_DEFAULT, sql_lobby_filter = "", expected_users = {}, } realtime.join_or_create_random_room(game_id, room_options, join_options)

PARAMETERS

game_id string
The name to create a room with. Must be unique and not in use or the room can't be created. If this is an empty string, then the server will assign a GUID as name.
room_options table
join_options table

realtime.int JoinRandomRoom()

realtime.int JoinRandomRoom(join_options)

Join random room. Local join_options = { custom_room_properties = {}, max_players = 0, matchmaking_mode = realtime.MATCHMAKINGMODE_FILL_ROOM, lobby_name = "", lobby_type = realtime.LOBBYTYPE_DEFAULT, sql_lobby_filter = "", expected_users = {}, } realtime.join_random_room(join_options)

PARAMETERS

join_options table

realtime.leave_room()

realtime.leave_room(will_come_back,send_auth_cookie)

Leave room.

PARAMETERS

will_come_back boolean
send_auth_cookie boolean

realtime.get_room_list()

realtime.get_room_list()

Get room list.

PARAMETERS

None


realtime.raise_event()

realtime.raise_event(reliable,parameter,event_code,options)

Sends in-game data to other players in the game.

PARAMETERS

reliable boolean
parameter number
event_code number
options table
(channel_id, event_caching, receiver_group, interest_group, cache_slice_index, target_players, web_flags, encrypt)

RETURNS

boolea

realtime.set_auto_join_lobby()

realtime.set_auto_join_lobby(auto_join)

Set the auto join lobby flag. The value of the autoJoinLobby flag determines if the client will automatically join the default lobby whenever it has successfully connected and whenever it leaves a game room.

PARAMETERS

auto_join boolean

Constants

EVENT_CONNECTIONERRORRETURN

EVENT_CONNECTIONERRORRETURN


EVENT_CLIENTERRORRETURN

EVENT_CLIENTERRORRETURN


EVENT_WARNINGRETURN

EVENT_WARNINGRETURN


EVENT_SERVERERRORRETURN

EVENT_SERVERERRORRETURN


EVENT_JOINROOMEVENTACTION

EVENT_JOINROOMEVENTACTION


EVENT_LEAVEROOMEVENTACTION

EVENT_LEAVEROOMEVENTACTION


EVENT_CUSTOMEVENTACTION

EVENT_CUSTOMEVENTACTION


EVENT_CONNECTRETURN

EVENT_CONNECTRETURN


EVENT_DISCONNECTRETURN

EVENT_DISCONNECTRETURN


EVENT_CREATEROOMRETURN

EVENT_CREATEROOMRETURN


EVENT_JOINORCREATEROOMRETURN

EVENT_JOINORCREATEROOMRETURN


EVENT_JOINRANDOMORCREATEROOMRETURN

EVENT_JOINRANDOMORCREATEROOMRETURN


EVENT_JOINROOMRETURN

EVENT_JOINROOMRETURN


EVENT_JOINRANDOMROOMRETURN

EVENT_JOINRANDOMROOMRETURN


EVENT_LEAVEROOMRETURN

EVENT_LEAVEROOMRETURN


EVENT_JOINLOBBYRETURN

EVENT_JOINLOBBYRETURN


EVENT_LEAVELOBBYRETURN

EVENT_LEAVELOBBYRETURN


EVENT_ONFINDFRIENDSRESPONSE

EVENT_ONFINDFRIENDSRESPONSE


EVENT_ONLOBBYSTATSRESPONSE

EVENT_ONLOBBYSTATSRESPONSE


EVENT_WEBRPCRETURN

EVENT_WEBRPCRETURN


EVENT_ONROOMLISTUPDATE

EVENT_ONROOMLISTUPDATE


EVENT_ONROOMPROPERTIESCHANGE

EVENT_ONROOMPROPERTIESCHANGE


EVENT_ONPLAYERPROPERTIESCHANGE

EVENT_ONPLAYERPROPERTIESCHANGE


EVENT_ONAPPSTATSUPDATE

EVENT_ONAPPSTATSUPDATE


EVENT_ONLOBBYSTATSUPDATE

EVENT_ONLOBBYSTATSUPDATE


EVENT_ONCACHESLICECHANGED

EVENT_ONCACHESLICECHANGED


EVENT_ONMASTERCLIENTCHANGED

EVENT_ONMASTERCLIENTCHANGED


EVENT_ONCUSTOMAUTHENTICATIONINTERMEDIATESTEP

EVENT_ONCUSTOMAUTHENTICATIONINTERMEDIATESTEP


EVENT_ONAVAILABLEREGIONS

EVENT_ONAVAILABLEREGIONS


EVENT_ONSECRETRECEIVAL

EVENT_ONSECRETRECEIVAL


EVENT_ONDIRECTCONNECTIONESTABLISHED

EVENT_ONDIRECTCONNECTIONESTABLISHED


EVENT_ONDIRECTCONNECTIONFAILEDTOESTABLISH

EVENT_ONDIRECTCONNECTIONFAILEDTOESTABLISH


EVENT_ONDIRECTMESSAGE

EVENT_ONDIRECTMESSAGE


EVENT_ONCUSTOMOPERATIONRESPONSE

EVENT_ONCUSTOMOPERATIONRESPONSE


EVENT_ONGETROOMLISTRESPONSE

EVENT_ONGETROOMLISTRESPONSE


AUTH_CUSTOM

Use a custom authentication service.


AUTH_STEAM

Authenticates users by their Steam Account. Pass L"ticket=[ticket]" to setParameters().


AUTH_FACEBOOK

Authenticates users by their Facebook Account. Pass L"token=[token]" to setParameters().


AUTH_OCULUS

Authenticates users by their Oculus Account. Pass L"userid=[userid]&nonce=[nonce]" to setParameters().


AUTH_PLAYSTATION_4

Authenticates users by their PSN Account. Pass L"token=[token]&env=[env]&userName=[userName]" to setParameters().


AUTH_XBOX

Authenticates users by their XBox Network Account. Pass the XSTS token to setData().


AUTH_VIVEPORT

Authenticates users by their HTC Viveport Account and user token. Pass L"userToken=[userToken]" to setParameters().


AUTH_NINTENDO_SWITCH

Authenticates users by their Nintendo Account. Pass L"token=[token]&appversion=[appversion]" to setParameters(). The appversion is optional.


AUTH_PLAYSTATION_5

Authenticates users by their PSN Account. Pass L"token=[token]&env=[env]&userName=[userName]" to setParameters().


AUTH_EPIC

Authenticates users by their Epic Online Services (EOS) Account. Pass L"token=[token]&ownershipToken=[ownershipToken]" to setParameters(). The ownershipToken is optional.


AUTH_FACEBOOK_GAMING

Authenticates users by their Facebook Account. Pass L"token=[token]" to setParameters().


AUTH_NONE

Disables custom authentication.


SERVER_TYPE_NAME_SERVER

Photon Cloud and for self-hosted Photon 5 or higher Server instances


SERVER_TYPE_MASTER_SERVER

Self-hosted Photon 4 Server instances


MATCHMAKINGMODE_FILL_ROOM

Fills up rooms (oldest first) to get players together as fast as possible. Default. Makes most sense with MaxPlayers > 0 and games that can only start with more players.


MATCHMAKINGMODE_SERIAL_MATCHING

Distributes players across available rooms sequentially but takes filters into account. Without filters, rooms get players evenly distributed.


MATCHMAKINGMODE_RANDOM_MATCHING

Joins a (fully) random room. Expected properties must match, but aside from this, any available room might be selected.


LOBBYTYPE_DEFAULT

This lobby type is used unless another lobby type is specified. Room lists will be sent and Client::opJoinRandomRoom() can filter by matching properties.


LOBBYTYPE_SQL_LOBBY

This lobby type lists rooms like type DEFAULT but SQL-like "where" clauses for filtering can be used with Client::opJoinRandomRoom(). This allows 'bigger', 'less', 'or' and 'and' combinations.


LOBBYTYPE_ASYNC_RANDOM_LOBBY

This lobby does not send room lists. It is only used for Client::opJoinRandomRoom(). It keeps rooms available for matchmaking for a while even when there are only inactive users left.


DIRECTMODE_NONE

Do not create any 2p2 connections between the clients. This is the default.


DIRECTMODE_ALL_TO_OTHERS

Each client establishes a direct connection with every other client inside the room.


DIRECTMODE_MASTER_TO_OTHERS

The master client establishes a direct connection with every other client inside the room. All other clients only establish a direct connection with the master client but not with each other.


DIRECTMODE_ALL_TO_ALL

Each client establishes a direct connection with every client inside the room, including itself.


DIRECTMODE_MASTER_TO_ALL

The master client establishes a direct connection with every client inside the room, including itself. All other clients only establish a direct connection with the master client but not with each other.