Skip to content
Francisco Dias edited this page Jul 9, 2026 · 2 revisions

Chat

The Chat module connects to the Photon Chat service for channel-based and private text messaging, presence and friend status. It is independent of Realtime: initialise, connect and service it separately. Connection diagnostics live in Chat Peer.

Note

After connecting you must call photon_chat_service every step for the Chat client to send and receive.

Lifecycle

Initialise, connect and service the Chat client:

Operations

Subscribe to channels, send messages and manage friends:

State & info

Query Chat connection state:

Channels & messages

Inspect subscribed channels and their cached messages:

Broadcast queue

Read binary broadcast payloads:

Callbacks

Register and remove the Chat event callbacks:

Structs

The Chat module uses the following structs:

Constants

The Chat module defines the following constants:



Back To Top

photon_chat_init

Initialises the Chat client. Call this once before any other Chat function.


Syntax:

photon_chat_init()

Returns:

Boolean

Whether initialisation succeeded.



Back To Top

photon_chat_shutdown

Shuts the Chat client down and releases its resources.


Syntax:

photon_chat_shutdown()

Returns:

Boolean

Whether the client was shut down.



Back To Top

photon_chat_service

Dispatches queued incoming and outgoing traffic for the Chat client. This must be called every step while connected.


Syntax:

photon_chat_service()

Returns:

Boolean

Whether the client was serviced.



Back To Top

photon_chat_select_region

Selects the Chat (Name Server) region to connect to (for example "eu", "us", "asia"). Call before photon_chat_connect — unlike Realtime, Chat has no available-regions callback to pick from.


Syntax:

photon_chat_select_region(region)
Argument Type Description
region String The region token to use.

Returns:

Boolean

Whether the region was recorded.



Back To Top

photon_chat_connect

Connects to the Photon Chat service using the given Application ID and application version. The result is delivered to photon_chat_set_callback_connected.


Syntax:

photon_chat_connect(app_id, app_version, options=undefined)
Argument Type Description
app_id String Your Photon Chat Application ID.
app_version String A version string of your choosing for your game build.
options PhotonChatConnectOptions Optional connection options.

Returns:

Boolean

Whether the connection attempt started.


Example:

var _app_id = extension_get_option_value("GMPhoton", "appIdChat");
photon_chat_connect(_app_id, "1.0", new PhotonChatConnectOptions());


Back To Top

photon_chat_disconnect

Disconnects the Chat client. The photon_chat_set_callback_disconnected callback fires once the disconnect completes.


Syntax:

photon_chat_disconnect()

Returns:

Boolean

Whether the disconnect started.



Back To Top

photon_chat_operation_subscribe

Subscribes to one or more chat channels. Messages then arrive via photon_chat_set_callback_get_messages.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_operation_subscribe(channels, messages_from_history=undefined, callback=undefined)
Argument Type Description
channels Array of String The channel names to subscribe to.
messages_from_history Real How many historical messages to fetch per channel (0 for none).
callback Function Optional callback invoked with the subscription results.

Returns:

Boolean

Whether the operation was sent.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
results Array of PhotonChatSubscribeResult The per-channel subscription results.


Back To Top

photon_chat_operation_unsubscribe

Unsubscribes from one or more chat channels.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_operation_unsubscribe(channels, callback=undefined)
Argument Type Description
channels Array of String The channel names to unsubscribe from.
callback Function Optional callback invoked with the unsubscribed channels.

Returns:

Boolean

Whether the operation was sent.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
channels Array of String The channel names that were unsubscribed.


Back To Top

photon_chat_operation_publish_message

Publishes a message to a subscribed channel. Subscribers receive it via photon_chat_set_callback_get_messages.


Syntax:

photon_chat_operation_publish_message(channel_name, message)
Argument Type Description
channel_name String The channel to publish to.
message String The message text.

Returns:

Boolean

Whether the operation was sent.



Back To Top

photon_chat_operation_send_private_message

Sends a private message to another user. The recipient receives it via photon_chat_set_callback_private_message.


Syntax:

photon_chat_operation_send_private_message(user_name, message, encrypt=undefined)
Argument Type Description
user_name String The recipient's user ID.
message String The message text.
encrypt Boolean Whether to encrypt the message.

Returns:

Boolean

Whether the operation was sent.



Back To Top

photon_chat_operation_set_online_status

Sets the local user's online status, optionally with a status message. Friends are notified via photon_chat_set_callback_status_update.


Syntax:

photon_chat_operation_set_online_status(status, message=undefined)
Argument Type Description
status PhotonChatUserStatus The status to broadcast.
message String An optional status message.

Returns:

Boolean

Whether the operation was sent.



Back To Top

photon_chat_operation_add_friends

Adds users to the local user's friend list to receive their status updates.


Syntax:

photon_chat_operation_add_friends(user_ids)
Argument Type Description
user_ids Array of String The user IDs to add.

Returns:

Boolean

Whether the operation was sent.



Back To Top

photon_chat_operation_remove_friends

Removes users from the local user's friend list.


Syntax:

photon_chat_operation_remove_friends(user_ids)
Argument Type Description
user_ids Array of String The user IDs to remove.

Returns:

Boolean

Whether the operation was sent.



Back To Top

photon_chat_is_initialized

Returns whether the Chat client has been initialised.


Syntax:

photon_chat_is_initialized()

Returns:

Boolean

Whether the client is initialised.



Back To Top

photon_chat_is_connected

Returns whether the Chat client is connected.


Syntax:

photon_chat_is_connected()

Returns:

Boolean

Whether the client is connected.



Back To Top

photon_chat_get_state

Returns the current Chat client state.


Syntax:

photon_chat_get_state()

Returns:

PhotonChatState

The current state.



Back To Top

photon_chat_get_disconnect_cause

Returns the cause of the most recent Chat disconnect.


Syntax:

photon_chat_get_disconnect_cause()

Returns:

PhotonChatDisconnectCause

The disconnect cause.



Back To Top

photon_chat_get_user_id

Returns the local user's ID.


Syntax:

photon_chat_get_user_id()

Returns:

String

The local user ID.



Back To Top

photon_chat_get_region

Returns the region the Chat client is connected to.


Syntax:

photon_chat_get_region()

Returns:

String

The current region.



Back To Top

photon_chat_get_server_time

Returns the current Chat server time in milliseconds.


Syntax:

photon_chat_get_server_time()

Returns:

Real

The server time in milliseconds.



Back To Top

photon_chat_get_server_time_offset

Returns the offset between local time and Chat server time, in milliseconds.


Syntax:

photon_chat_get_server_time_offset()

Returns:

Real

The server time offset in milliseconds.



Back To Top

photon_chat_get_bytes_in

Returns the total number of bytes received by the Chat client.


Syntax:

photon_chat_get_bytes_in()

Returns:

Real

The number of bytes received.



Back To Top

photon_chat_get_bytes_out

Returns the total number of bytes sent by the Chat client.


Syntax:

photon_chat_get_bytes_out()

Returns:

Real

The number of bytes sent.



Back To Top

photon_chat_get_channel_count

Returns the number of channels of the given type the client is currently subscribed to.


Syntax:

photon_chat_get_channel_count(channel_type)
Argument Type Description
channel_type PhotonChatChannelType The channel type (public or private).

Returns:

Real

The number of channels.



Back To Top

photon_chat_get_channel_name

Returns the name of a subscribed channel of the given type by index.


Syntax:

photon_chat_get_channel_name(channel_type, index)
Argument Type Description
channel_type PhotonChatChannelType The channel type.
index Real The zero-based channel index.

Returns:

String

The channel name.



Back To Top

photon_chat_get_channel_message_count

Returns the number of cached messages in the given channel.


Syntax:

photon_chat_get_channel_message_count(channel_type, channel_name)
Argument Type Description
channel_type PhotonChatChannelType The channel type.
channel_name String The channel name.

Returns:

Real

The number of cached messages.



Back To Top

photon_chat_get_channel_message

Returns a cached message from the given channel by index.


Syntax:

photon_chat_get_channel_message(channel_type, channel_name, index)
Argument Type Description
channel_type PhotonChatChannelType The channel type.
channel_name String The channel name.
index Real The zero-based message index.

Returns:

String

The message text.



Back To Top

photon_chat_get_channel_sender

Returns the sender of a cached message from the given channel by index.


Syntax:

photon_chat_get_channel_sender(channel_type, channel_name, index)
Argument Type Description
channel_type PhotonChatChannelType The channel type.
channel_name String The channel name.
index Real The zero-based message index.

Returns:

String

The sender's user ID.



Back To Top

photon_chat_get_broadcast_queue_count

Returns the number of buffered binary broadcast messages waiting to be read.


Syntax:

photon_chat_get_broadcast_queue_count()

Returns:

Real

The number of queued broadcasts.



Back To Top

photon_chat_clear_broadcast_queue

Clears all buffered binary broadcast messages without reading them.


Syntax:

photon_chat_clear_broadcast_queue()

Returns:

Boolean

Whether the queue was cleared.



Back To Top

photon_chat_peek_next_broadcast_size

Returns the size in bytes of the next buffered broadcast without removing it from the queue.


Syntax:

photon_chat_peek_next_broadcast_size()

Returns:

Real

The size of the next broadcast in bytes.



Back To Top

photon_chat_peek_next_broadcast_channel

Returns the channel name of the next buffered broadcast without removing it from the queue.


Syntax:

photon_chat_peek_next_broadcast_channel()

Returns:

String

The channel of the next broadcast.



Back To Top

photon_chat_receive_one_broadcast_buffer

Removes the next buffered broadcast from the queue and writes its payload into the given buffer.


Syntax:

photon_chat_receive_one_broadcast_buffer(out_data, max_bytes, offset)
Argument Type Description
out_data Buffer The buffer to write the payload into.
max_bytes Real The maximum number of bytes to write.
offset Real The offset within the buffer to start writing at.

Returns:

PhotonRealtimeEventBufferReceived

A struct describing the received broadcast.



Back To Top

photon_chat_set_callback_debug

Registers the callback fired with Chat SDK debug output.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_debug(callback)
Argument Type Description
callback Function The function to call with debug output.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
debug_level Real The debug level of the message.
message String The debug message.


Back To Top

photon_chat_set_callback_connected

Registers the callback fired when the Chat client finishes connecting.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_connected(callback)
Argument Type Description
callback Function The function to call on connect.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
error_code Real The connect result code (0 on success).
error_string String A human-readable result message.


Back To Top

photon_chat_set_callback_state_change

Registers the callback fired when the Chat client state changes.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_state_change(callback)
Argument Type Description
callback Function The function to call on a state change.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
state PhotonChatState The new client state.


Back To Top

photon_chat_set_callback_connection_error

Registers the callback fired on a low-level connection error.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_connection_error(callback)
Argument Type Description
callback Function The function to call on a connection error.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
error_code Real The connection error code.


Back To Top

photon_chat_set_callback_client_error

Registers the callback fired on a client-side error.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_client_error(callback)
Argument Type Description
callback Function The function to call on a client error.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
error_code Real The client error code.


Back To Top

photon_chat_set_callback_warning

Registers the callback fired on a client warning.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_warning(callback)
Argument Type Description
callback Function The function to call on a warning.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
warning_code Real The warning code.


Back To Top

photon_chat_set_callback_server_error

Registers the callback fired on a server-reported error.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_server_error(callback)
Argument Type Description
callback Function The function to call on a server error.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
error_code Real The server error code.


Back To Top

photon_chat_set_callback_disconnected

Registers the callback fired when the Chat client has disconnected. The callback takes no arguments.


Syntax:

photon_chat_set_callback_disconnected(callback)
Argument Type Description
callback Function The function to call on disconnect.

Returns:

Boolean

Whether the callback was set.



Back To Top

photon_chat_set_callback_status_update

Registers the callback fired when a friend's status changes.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_status_update(callback)
Argument Type Description
callback Function The function to call on a status update.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
user String The user whose status changed.
status PhotonChatUserStatus The user's new status.
got_message Boolean Whether a status message accompanied the update.
message String The status message, or empty if none.


Back To Top

photon_chat_set_callback_get_messages

Registers the callback fired when messages are received on a subscribed channel.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_get_messages(callback)
Argument Type Description
callback Function The function to call when messages arrive.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
channel_name String The channel the messages arrived on.
messages Array of PhotonChatMessage The received messages.


Back To Top

photon_chat_set_callback_private_message

Registers the callback fired when a private message is received.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_private_message(callback)
Argument Type Description
callback Function The function to call on a private message.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
sender String The sender's user ID.
channel_name String The private channel name.
message String The message text.


Back To Top

photon_chat_set_callback_receive_broadcast

Registers the callback fired when a binary broadcast is received. The payload is queued; read it with photon_chat_receive_one_broadcast_buffer.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

photon_chat_set_callback_receive_broadcast(callback)
Argument Type Description
callback Function The function to call on a broadcast.

Returns:

Boolean

Whether the callback was set.


Triggers:

Callback

The callback is invoked with the following arguments:

Key Type Description
channel_name String The channel the broadcast arrived on.
byte_length Real The size of the broadcast payload in bytes.


Back To Top

photon_chat_remove_callback_debug

Removes the debug callback registered with photon_chat_set_callback_debug.


Syntax:

photon_chat_remove_callback_debug()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_connected

Removes the connected callback registered with photon_chat_set_callback_connected.


Syntax:

photon_chat_remove_callback_connected()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_state_change

Removes the state-change callback registered with photon_chat_set_callback_state_change.


Syntax:

photon_chat_remove_callback_state_change()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_connection_error

Removes the connection-error callback registered with photon_chat_set_callback_connection_error.


Syntax:

photon_chat_remove_callback_connection_error()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_client_error

Removes the client-error callback registered with photon_chat_set_callback_client_error.


Syntax:

photon_chat_remove_callback_client_error()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_warning

Removes the warning callback registered with photon_chat_set_callback_warning.


Syntax:

photon_chat_remove_callback_warning()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_server_error

Removes the server-error callback registered with photon_chat_set_callback_server_error.


Syntax:

photon_chat_remove_callback_server_error()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_disconnected

Removes the disconnected callback registered with photon_chat_set_callback_disconnected.


Syntax:

photon_chat_remove_callback_disconnected()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_status_update

Removes the status-update callback registered with photon_chat_set_callback_status_update.


Syntax:

photon_chat_remove_callback_status_update()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_get_messages

Removes the get-messages callback registered with photon_chat_set_callback_get_messages.


Syntax:

photon_chat_remove_callback_get_messages()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_private_message

Removes the private-message callback registered with photon_chat_set_callback_private_message.


Syntax:

photon_chat_remove_callback_private_message()

Returns:

Boolean

Whether the callback was removed.



Back To Top

photon_chat_remove_callback_receive_broadcast

Removes the receive-broadcast callback registered with photon_chat_set_callback_receive_broadcast.


Syntax:

photon_chat_remove_callback_receive_broadcast()

Returns:

Boolean

Whether the callback was removed.



Back To Top

PhotonChatState

The states the Chat client moves through, returned by photon_chat_get_state.

These constants are referenced by the following functions:


Member Description
Unknown Unknown state.
Uninitialized The client has not been initialised.
ConnectingToNameServer Connecting to the name server.
ConnectedToNameServer Connected to the name server.
Authenticating Authenticating.
Authenticated Authenticated.
DisconnectingFromNameServer Disconnecting from the name server.
ConnectingToFrontEnd Connecting to the chat front-end server.
ConnectedToFrontEnd Connected to the chat front-end server (ready to chat).
Disconnecting Disconnecting.
Disconnected Fully disconnected.


Back To Top

PhotonChatDisconnectCause

The reasons the Chat client can be disconnected, returned by photon_chat_get_disconnect_cause.

These constants are referenced by the following functions:


Member Description
Unknown Unknown cause.
None No disconnect.
ServerUserLimit The server's user limit was reached.
ExceptionOnConnect An exception occurred while connecting.
DisconnectByServer The server closed the connection.
DisconnectByServerLogic Server-side logic closed the connection.
TimeoutDisconnect The connection timed out.
Exception A client-side exception occurred.
InvalidAuthentication Authentication was invalid.
MaxCcuReached The application's maximum concurrent-user limit was reached.
InvalidRegion The requested region was invalid.
OperationNotAllowed An operation was not allowed in the current state.
CustomAuthenticationFailed Custom authentication failed.


Back To Top

PhotonChatAppErrorCode

Application-level result codes reported by the Chat service.


Member Description
Ok The operation succeeded.
OperationDenied The operation was denied.
OperationInvalid The operation was invalid.
InternalServerError An internal server error occurred.
InvalidAuthentication Authentication was invalid.
GameIdAlreadyExists The game ID already exists.
GameFull The game is full.
GameClosed The game is closed.
AlreadyMatched Already matched.
ServerFull The server is full.
UserBlocked The user is blocked.
NoMatchFound No match was found.
GameDoesNotExist The game does not exist.
MaxCcuReached The maximum concurrent-user limit was reached.
InvalidRegion The region was invalid.
CustomAuthenticationFailed Custom authentication failed.


Back To Top

PhotonChatUserStatus

The user statuses that can be broadcast with photon_chat_operation_set_online_status.

These constants are referenced by the following functions:


Member Description
Offline The user is offline.
Invisible The user appears offline to others.
Online The user is online.
Away The user is away.
Dnd The user does not want to be disturbed.
Lfg The user is looking for a game.
Playing The user is playing.


Back To Top

PhotonChatChannelType

The chat channel types.

These constants are referenced by the following functions:


Member Description
Public A public channel (subscribed via photon_chat_operation_subscribe).
Private A private channel (created by private messages).


Back To Top

PhotonChatOperationCode

The Chat operation codes. Primarily useful for low-level diagnostics.


Member Description
Authenticate Authenticate with the chat service.
Subscribe Subscribe to channels.
Unsubscribe Unsubscribe from channels.
Publish Publish a message.
SendPrivate Send a private message.
ChannelHistory Fetch channel history.
UpdateStatus Update the user's status.
AddFriends Add friends.
RemoveFriends Remove friends.


Back To Top

PhotonChatEventCode

The Chat event codes. Primarily useful for low-level diagnostics.


Member Description
ChatMessages Channel messages were received.
Users A user list was received.
PrivateMessage A private message was received.
FriendList A friend list was received.
StatusUpdate A friend status update was received.
Subscribe A subscribe result was received.
Unsubscribe An unsubscribe result was received.


Back To Top

PhotonChatParameterCode

The Chat protocol parameter codes. Primarily useful for low-level diagnostics.


Member Description
Channels The channels parameter.
Messages The messages parameter.
Message A single message parameter.
Senders The senders parameter.
Sender A single sender parameter.
ChannelUserCount The channel user count parameter.
MessageId A message ID parameter.
MessageIds A message IDs parameter.
Status A status parameter.
Friends The friends parameter.
SkipMessage The skip-message flag parameter.
HistoryLength The history-length parameter.
SubscribeResults The subscribe-results parameter.
Properties The properties parameter.
ChannelId A channel ID parameter.
Region The region parameter.
AppVersion The application version parameter.
Secret The authentication secret parameter.
AuthType The authentication type parameter.
AuthParams The authentication parameters parameter.
AuthData The authentication data parameter.
UserId The user ID parameter.
AppId The application ID parameter.
Address The address parameter.


Back To Top

PhotonChatConnectOptions

Options passed to photon_chat_connect.

This struct is referenced by the following functions:


Member Type Description
authentication_values PhotonRealtimeAuthenticationValues Authentication values for a custom auth provider.
server_address String Override the Photon name server address. Leave unset to use the default cloud.
use_background_thread Boolean Whether to use a background send/receive thread. Honored only on Nintendo Switch; ignored on other platforms.


Back To Top

PhotonChatMessage

A single chat message delivered by photon_chat_set_callback_get_messages.

This struct is referenced by the following functions:


Member Type Description
sender String The sender's user ID.
content String The message text.


Back To Top

PhotonChatSubscribeResult

A per-channel result delivered by the photon_chat_operation_subscribe callback.

This struct is referenced by the following functions:


Member Type Description
channel_name String The channel name.
success Boolean Whether the subscription to this channel succeeded.


Clone this wiki locally