Skip to Content
defold-typescript libraries
VitusVeit

VitusVeit/extension-webrtc/webrtc

Functions and constants for using webrtc.

  • GitHub: VitusVeit/extension-webrtc — pinned to f41d30a
    1. This repo publishes no releases or tags. Add a commit archive URL — for the pinned commit, https://github.com/VitusVeit/extension-webrtc/archive/f41d30a334b4502f2ab803086664e94e20041467.zip — to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as webrtc from "webrtc"
  • Asset Portal: extension-webrtc

Functions

webrtc.set_configuration(ice_servers: string, webrtc_callback: function)

Sets the configuration for the peer connection

Parameters

  • ice_servers: string — A string containg a list of stun or turn servers (eg "stun_url:PORT;turn_url:PORT:USER:PASSWORD"), a section is delimited by ';' and subdivided by ':'
  • webrtc_callback: function — callback for all webrtc events
    • self: object — The script instance that was used to register the callback
    • event: number — The current event. One of the following
      • webrtc.EVENT_CHANNEL_OPENED
      • webrtc.EVENT_CHANNEL_CLOSED
      • webrtc.EVENT_SIGNALING_DATA
      • webrtc.EVENT_MESSAGE
    • data: table — the event payload
      • id: number — the id of the sender peer, not present if event is webrtc.EVENT_SIGNALING_DATA.
      • label: string — the label of the DataChannel, not present if event is webrtc.EVENT_SIGNALING_DATA.
      • msg: string — the message sent from the peer, only present if event is webrtc.EVENT_MESSAGE.
      • signaling: string — the signaling data to send to the other peer, only present if event is webrtc.EVENT_SIGNALING_DATA.

webrtc.process_data(data: string)

Processes the signaling data that was received by a peer.

Parameters

  • data: string — The data that needs to be processed.

webrtc.create_channel(id: number, label: string, type: int)

Creates a datachannel with a specified peer and type

Parameters

  • id: number — The id for which the datachannel is to be created
  • label: string — The label for the datachannel
  • type: int — The type of the datachannel, it can be any of the TYPE_* constants

webrtc.send_message(id: number, label: string, message: string)

Sends a message to a peer by a channel

Parameters

  • id: number — The id to which the message is to be sent
  • label: string — The label of the channel to be used, the datachannel needs to be already created
  • message: string — The message to send

Constants

webrtc.TYPE_UNRELIABLE

An unreliable DataChannel connection with unordered packets

webrtc.TYPE_UNRELIABLE_ORDERED

An unreliable DataChannel connection with ordered packets

webrtc.TYPE_RELIABLE

A reliable DataChannel connection with ordered packets

webrtc.EVENT_CHANNEL_OPENED

An event called when a new DataChannel is opened

webrtc.EVENT_CHANNEL_CLOSED

An event called when a new DataChannel is closed

webrtc.EVENT_SIGNALING_DATA

An event called when webrtc generates new signaling data

webrtc.EVENT_MESSAGE

An event called when a new message has arrived

On this page