defold/extension-photon-realtime/realtime
Functions and constants for interacting with Photon Realtime
- GitHub: defold/extension-photon-realtime — pinned to
1.0.0(released while Defold 1.10.4 was current)- This repo publishes no stable release. Pick a tag from defold/extension-photon-realtime tags and add its Source code (zip) URL — for the pinned tag,
https://github.com/defold/extension-photon-realtime/archive/refs/tags/1.0.0.zip— togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as realtime from "realtime"
- This repo publishes no stable release. Pick a tag from defold/extension-photon-realtime tags and add its Source code (zip) URL — for the pinned tag,
Functions
realtime.init(app_id: string)realtime.connect(options: None, callback: None)realtime.update()realtime.disconnect()realtime.join_lobby(lobby_name: string, lobby_type: number)realtime.leave_lobby()realtime.create_room(game_id: string, room_options: table, expected_users: table)realtime.join_room(game_id: string, join_options: table)realtime.join_or_create_room(game_id: string, room_options: table, join_options: table)realtime.join_or_create_random_room(game_id: string, room_options: table, join_options: table)realtime.leave_room(will_come_back: boolean, send_auth_cookie: boolean)realtime.get_room_list()realtime.raise_event(reliable: boolean, parameter: number, event_code: number, options: table): boolearealtime.set_auto_join_lobby(auto_join: boolean)
realtime.init(app_id: string)
Initialize Realtime by creating a load balanced client
Parameters
app_id:string
realtime.connect(options: None, callback: None)
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 optionscallback:None
realtime.update()
Update Realtime. Call this from a script component.
realtime.disconnect()
Disconnect from server.
realtime.join_lobby(lobby_name: string, lobby_type: number)
Join lobby.
Parameters
lobby_name:stringlobby_type:number
realtime.leave_lobby()
Leave lobby.
realtime.create_room(game_id: string, room_options: table, expected_users: table)
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:tableexpected_users:table
realtime.join_room(game_id: string, join_options: table)
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(game_id: string, room_options: table, join_options: table)
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:tablejoin_options:table
realtime.join_or_create_random_room(game_id: string, room_options: table, join_options: table)
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:tablejoin_options:table
realtime.leave_room(will_come_back: boolean, send_auth_cookie: boolean)
Leave room.
Parameters
will_come_back:booleansend_auth_cookie:boolean
realtime.get_room_list()
Get room list.
realtime.raise_event(reliable: boolean, parameter: number, event_code: number, options: table): boolea
Sends in-game data to other players in the game.
Parameters
reliable:booleanparameter:numberevent_code:numberoptions:table— (channel_id, event_caching, receiver_group, interest_group, cache_slice_index, target_players, web_flags, encrypt)
Returns
n:boolea
realtime.set_auto_join_lobby(auto_join: boolean)
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
realtime.EVENT_CONNECTIONERRORRETURN
EVENT_CONNECTIONERRORRETURN
realtime.EVENT_CLIENTERRORRETURN
EVENT_CLIENTERRORRETURN
realtime.EVENT_WARNINGRETURN
EVENT_WARNINGRETURN
realtime.EVENT_SERVERERRORRETURN
EVENT_SERVERERRORRETURN
realtime.EVENT_JOINROOMEVENTACTION
EVENT_JOINROOMEVENTACTION
realtime.EVENT_LEAVEROOMEVENTACTION
EVENT_LEAVEROOMEVENTACTION
realtime.EVENT_CUSTOMEVENTACTION
EVENT_CUSTOMEVENTACTION
realtime.EVENT_CONNECTRETURN
EVENT_CONNECTRETURN
realtime.EVENT_DISCONNECTRETURN
EVENT_DISCONNECTRETURN
realtime.EVENT_CREATEROOMRETURN
EVENT_CREATEROOMRETURN
realtime.EVENT_JOINORCREATEROOMRETURN
EVENT_JOINORCREATEROOMRETURN
realtime.EVENT_JOINRANDOMORCREATEROOMRETURN
EVENT_JOINRANDOMORCREATEROOMRETURN
realtime.EVENT_JOINROOMRETURN
EVENT_JOINROOMRETURN
realtime.EVENT_JOINRANDOMROOMRETURN
EVENT_JOINRANDOMROOMRETURN
realtime.EVENT_LEAVEROOMRETURN
EVENT_LEAVEROOMRETURN
realtime.EVENT_JOINLOBBYRETURN
EVENT_JOINLOBBYRETURN
realtime.EVENT_LEAVELOBBYRETURN
EVENT_LEAVELOBBYRETURN
realtime.EVENT_ONFINDFRIENDSRESPONSE
EVENT_ONFINDFRIENDSRESPONSE
realtime.EVENT_ONLOBBYSTATSRESPONSE
EVENT_ONLOBBYSTATSRESPONSE
realtime.EVENT_WEBRPCRETURN
EVENT_WEBRPCRETURN
realtime.EVENT_ONROOMLISTUPDATE
EVENT_ONROOMLISTUPDATE
realtime.EVENT_ONROOMPROPERTIESCHANGE
EVENT_ONROOMPROPERTIESCHANGE
realtime.EVENT_ONPLAYERPROPERTIESCHANGE
EVENT_ONPLAYERPROPERTIESCHANGE
realtime.EVENT_ONAPPSTATSUPDATE
EVENT_ONAPPSTATSUPDATE
realtime.EVENT_ONLOBBYSTATSUPDATE
EVENT_ONLOBBYSTATSUPDATE
realtime.EVENT_ONCACHESLICECHANGED
EVENT_ONCACHESLICECHANGED
realtime.EVENT_ONMASTERCLIENTCHANGED
EVENT_ONMASTERCLIENTCHANGED
realtime.EVENT_ONCUSTOMAUTHENTICATIONINTERMEDIATESTEP
EVENT_ONCUSTOMAUTHENTICATIONINTERMEDIATESTEP
realtime.EVENT_ONAVAILABLEREGIONS
EVENT_ONAVAILABLEREGIONS
realtime.EVENT_ONSECRETRECEIVAL
EVENT_ONSECRETRECEIVAL
realtime.EVENT_ONDIRECTCONNECTIONESTABLISHED
EVENT_ONDIRECTCONNECTIONESTABLISHED
realtime.EVENT_ONDIRECTCONNECTIONFAILEDTOESTABLISH
EVENT_ONDIRECTCONNECTIONFAILEDTOESTABLISH
realtime.EVENT_ONDIRECTMESSAGE
EVENT_ONDIRECTMESSAGE
realtime.EVENT_ONCUSTOMOPERATIONRESPONSE
EVENT_ONCUSTOMOPERATIONRESPONSE
realtime.EVENT_ONGETROOMLISTRESPONSE
EVENT_ONGETROOMLISTRESPONSE
realtime.AUTH_CUSTOM
Use a custom authentication service.
realtime.AUTH_STEAM
Authenticates users by their Steam Account. Pass L"ticket=[ticket]" to setParameters().
realtime.AUTH_FACEBOOK
Authenticates users by their Facebook Account. Pass L"token=[token]" to setParameters().
realtime.AUTH_OCULUS
Authenticates users by their Oculus Account. Pass L"userid=[userid]&nonce=[nonce]" to setParameters().
realtime.AUTH_PLAYSTATION_4
Authenticates users by their PSN Account. Pass L"token=[token]&env=[env]&userName=[userName]" to setParameters().
realtime.AUTH_XBOX
Authenticates users by their XBox Network Account. Pass the XSTS token to setData().
realtime.AUTH_VIVEPORT
Authenticates users by their HTC Viveport Account and user token. Pass L"userToken=[userToken]" to setParameters().
realtime.AUTH_NINTENDO_SWITCH
Authenticates users by their Nintendo Account. Pass L"token=[token]&appversion=[appversion]" to setParameters(). The appversion is optional.
realtime.AUTH_PLAYSTATION_5
Authenticates users by their PSN Account. Pass L"token=[token]&env=[env]&userName=[userName]" to setParameters().
realtime.AUTH_EPIC
Authenticates users by their Epic Online Services (EOS) Account. Pass L"token=[token]&ownershipToken=[ownershipToken]" to setParameters(). The ownershipToken is optional.
realtime.AUTH_FACEBOOK_GAMING
Authenticates users by their Facebook Account. Pass L"token=[token]" to setParameters().
realtime.AUTH_NONE
Disables custom authentication.
realtime.SERVER_TYPE_NAME_SERVER
Photon Cloud and for self-hosted Photon 5 or higher Server instances
realtime.SERVER_TYPE_MASTER_SERVER
Self-hosted Photon 4 Server instances
realtime.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.
realtime.MATCHMAKINGMODE_SERIAL_MATCHING
Distributes players across available rooms sequentially but takes filters into account. Without filters, rooms get players evenly distributed.
realtime.MATCHMAKINGMODE_RANDOM_MATCHING
Joins a (fully) random room. Expected properties must match, but aside from this, any available room might be selected.
realtime.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.
realtime.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.
realtime.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.
realtime.DIRECTMODE_NONE
Do not create any 2p2 connections between the clients. This is the default.
realtime.DIRECTMODE_ALL_TO_OTHERS
Each client establishes a direct connection with every other client inside the room.
realtime.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.
realtime.DIRECTMODE_ALL_TO_ALL
Each client establishes a direct connection with every client inside the room, including itself.
realtime.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.