Skip to content

crossfire

YYBartT edited this page Jan 18, 2026 · 1 revision

Crossfire

Namazu Crossfire provides a complete foundation for cross-platform multiplayer. It handles session discovery, matchmaking, and connection signaling, making it easy to establish direct or relayed peer connections between players. Crossfire builds on open standards like WebRTC to ensure compatibility across diverse runtimes, from native builds to browsers.

Developers can use Crossfire alongside other Elements such as Identity, Data, and Cloud Functions to deliver seamless real-time multiplayer experiences.

See: Namazu Crossfire

Functions

This function these are the functions in the Crossfire module:



Back To Top

elements_crossfire_set_identity

This function sets the Crossfire identity (profile, session key) used for matchmaking.


Syntax:

elements_crossfire_set_identity(_profile_id, _session_key)
Argument Type Description
_profile_id String The Elements profile ID for this client.
_session_key String The session key obtained from the Elements REST API.



Returns:

N/A




Back To Top

elements_crossfire_connect

This function opens the WebSocket connection to Crossfire and enters the HANDSHAKE phase.


Syntax:

elements_crossfire_connect()



Returns:

Boolean

True if the async connect request was started, false if already connected.




Back To Top

elements_crossfire_disconnect

This function closes the Crossfire WebSocket connection and resets the client phase to DISCONNECTED.


Syntax:

elements_crossfire_disconnect()



Returns:

N/A




Back To Top

elements_crossfire_find_match

This function sends a FIND handshake to start matchmaking on the current connection.


Syntax:

elements_crossfire_find_match(_configuration)
Argument Type Description
_configuration String The matchmaking configuration name or ID.



Returns:

Boolean

True if the message was sent, false if phase/identity/handshake state is invalid.




Back To Top

elements_crossfire_join_match

This function sends a JOIN handshake to rejoin a known match by its match ID.


Syntax:

elements_crossfire_join_match(_match_id)
Argument Type Description
_match_id String The match ID to rejoin.



Returns:

Boolean

True if the message was sent, false if phase/identity/handshake state is invalid.




Back To Top

elements_crossfire_leave_match

This function sends a LEAVE control message to leave the current match.


Syntax:

elements_crossfire_leave_match()



Returns:

Boolean

True if the message was sent, false otherwise.




Back To Top

elements_crossfire_open_match

This function sends an OPEN control message to allow new participants to join the match.


Syntax:

elements_crossfire_open_match()



Returns:

Boolean

True if the message was sent, false otherwise.




Back To Top

elements_crossfire_close_match

This function sends a CLOSE control message to prevent new participants from joining the match.


Syntax:

elements_crossfire_close_match()



Returns:

Boolean

True if the message was sent, false otherwise.




Back To Top

elements_crossfire_end_match

This function sends an END control message to terminate the current match.


Syntax:

elements_crossfire_end_match()



Returns:

Boolean

True if the message was sent, false otherwise.




Back To Top

elements_crossfire_send_string_relay

This function sends a direct STRING_RELAY to a specific participant in the match.


Syntax:

elements_crossfire_send_string_relay(_recipient_profile_id, _text, _lifecycle)
Argument Type Description
_recipient_profile_id String The profile ID of the target participant.
_text String The string payload to send.
_lifecycle String The lifecycle for this message ("ONCE", "SESSION", or "MATCH"). Defaults to "ONCE".



Returns:

Boolean

True if the message was sent, false otherwise.




Back To Top

elements_crossfire_send_string_broadcast

This function broadcasts a STRING_BROADCAST message to all other participants in the match.


Syntax:

elements_crossfire_send_string_broadcast(_text, _lifecycle)
Argument Type Description
_text String The string payload to broadcast.
_lifecycle String The lifecycle for this message ("ONCE", "SESSION", or "MATCH"). Defaults to "ONCE".



Returns:

Boolean

True if the message was sent, false otherwise.




Back To Top

elements_crossfire_send_binary_relay

This function sends a direct BINARY_RELAY to a specific participant using a base64-encoded buffer.


Syntax:

elements_crossfire_send_binary_relay(_recipient_profile_id, _buffer, _lifecycle)
Argument Type Description
_recipient_profile_id String The profile ID of the target participant.
_buffer Buffer The buffer whose contents will be relayed as base64.
_lifecycle String The lifecycle for this message ("ONCE", "SESSION", or "MATCH"). Defaults to "ONCE".



Returns:

Boolean

True if the message was sent, false otherwise.




Back To Top

elements_crossfire_send_binary_broadcast

This function broadcasts a BINARY_BROADCAST message to all other participants using a base64-encoded buffer.


Syntax:

elements_crossfire_send_binary_broadcast(_buffer, _lifecycle)
Argument Type Description
_buffer Buffer The buffer whose contents will be broadcast as base64.
_lifecycle String The lifecycle for this message ("ONCE", "SESSION", or "MATCH"). Defaults to "ONCE".



Returns:

Boolean

True if the message was sent, false otherwise.




Back To Top

elements_crossfire_is_socket_open

This function returns whether the underlying WebSocket is currently open (HANDSHAKE or SIGNALING).


Syntax:

elements_crossfire_is_socket_open()



Returns:

Boolean

True if the socket is open, false otherwise.




Back To Top

elements_crossfire_is_ready

This function returns whether the Crossfire client is fully ready (SIGNALING phase) for messaging.


Syntax:

elements_crossfire_is_ready()



Returns:

Boolean

True if the client is in SIGNALING phase, false otherwise.




Back To Top

elements_crossfire_is_host

This function returns whether this client is currently the host of the match.


Syntax:

elements_crossfire_is_host()



Returns:

Boolean

True if this client is the host, false otherwise.




Back To Top

elements_crossfire_get_participants

This function returns a struct of all the current participants in the match (profile_id : { connected }).


Syntax:

elements_crossfire_get_participants()



Returns:

Struct




Back To Top

elements_crossfire_get_match_id

This function returns the ID of a previously joined match (useful for reconnecting).


Syntax:

elements_crossfire_get_match_id()



Returns:

String or Undefined




Back To Top

elements_crossfire_events_on_connected_callback

This function sets the callback invoked when the WebSocket successfully connects.


Syntax:

elements_crossfire_events_on_connected_callback(_callback)
Argument Type Description
_callback Function The function to call on successful socket connection.



Returns:

N/A




Back To Top

elements_crossfire_events_on_connection_error_callback

This function sets the callback invoked when the WebSocket connection fails.


Syntax:

elements_crossfire_events_on_connection_error_callback(_callback)
Argument Type Description
_callback Function The function to call on connection error.



Returns:

N/A




Back To Top

elements_crossfire_events_on_matched_callback

This function sets the callback invoked when a MATCHED message is received and the match is assigned.


Syntax:

elements_crossfire_events_on_matched_callback(_callback)
Argument Type Description
_callback Function The function to call when the client receives MATCHED.



Returns:

N/A




Back To Top

elements_crossfire_events_on_signal_callback

This function sets the callback invoked for signaling messages (SIGNAL_*, CONNECT/DISCONNECT, STRING/BINARY relays/broadcasts).


Syntax:

elements_crossfire_events_on_signal_callback(_callback)
Argument Type Description
_callback Function The function to call for incoming signal messages.



Returns:

N/A




Back To Top

elements_crossfire_events_on_control_callback

This function sets the callback invoked for incoming control messages (LEAVE, OPEN, CLOSE, END) if sent by the server.


Syntax:

elements_crossfire_events_on_control_callback(_callback)
Argument Type Description
_callback Function The function to call for incoming control messages.



Returns:

N/A




Back To Top

elements_crossfire_events_on_error_callback

This function sets the callback invoked when an ERROR message is received from the server.


Syntax:

elements_crossfire_events_on_error_callback(_callback)
Argument Type Description
_callback Function The function to call for protocol error messages.



Returns:

N/A




Back To Top

elements_crossfire_events_on_disconnected_callback

This function sets the callback invoked when the WebSocket disconnects.


Syntax:

elements_crossfire_events_on_disconnected_callback(_callback)
Argument Type Description
_callback Function The function to call on socket disconnection.



Returns:

N/A




Back To Top

elements_crossfire_events_on_unknown_callback

This function sets the callback invoked when an unrecognized message type is received.


Syntax:

elements_crossfire_events_on_unknown_callback(_callback)
Argument Type Description
_callback Function The function to call for unknown message types.



Returns:

N/A




Back To Top

elements_crossfire_events_on_phase_changed_callback

This function sets the callback invoked whenever the client's internal CF_PHASE changes.


Syntax:

elements_crossfire_events_on_phase_changed_callback(_callback)
Argument Type Description
_callback Function The function to call when the connection phase is updated.



Returns:

N/A



Clone this wiki locally