VitusVeit
VitusVeit/extension-webrtc/webrtc
Functions and constants for using webrtc.
- GitHub: VitusVeit/extension-webrtc — pinned to
f41d30a- 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— 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 webrtc from "webrtc"
- This repo publishes no releases or tags. Add a commit archive URL — for the pinned commit,
- 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 eventsself:object— The script instance that was used to register the callbackevent:number— The current event. One of the followingwebrtc.EVENT_CHANNEL_OPENEDwebrtc.EVENT_CHANNEL_CLOSEDwebrtc.EVENT_SIGNALING_DATAwebrtc.EVENT_MESSAGE
data:table— the event payloadid:number— the id of the sender peer, not present if event iswebrtc.EVENT_SIGNALING_DATA.label:string— the label of the DataChannel, not present if event iswebrtc.EVENT_SIGNALING_DATA.msg:string— the message sent from the peer, only present if event iswebrtc.EVENT_MESSAGE.signaling:string— the signaling data to send to the other peer, only present if event iswebrtc.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 createdlabel:string— The label for the datachanneltype: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 sentlabel:string— The label of the channel to be used, the datachannel needs to be already createdmessage: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