GizStack
View .mdOpen in ChatGPTOpen in Claude

gizlang:webrtc

WebRTC media and data channels through libdatachannel's stable C API. No inference or application policy lives here.

gizlang
import * as Webrtc from "gizlang:webrtc";

Types

Peer

gizlang
type Peer

One WebRTC peer connection: its audio and video tracks and data channels (-1: absent) over libdatachannel.

  • id: i64
  • audio: i64
  • video: i64
  • data: i64
  • remoteData: i64

Functions

iceUrl

gizlang
function iceUrl(url: string, username: string, password: string): string throws string

libdatachannel carries TURN credentials in the URL, with user-info percent encoding.

Effects: fail.

h264Payload

gizlang
function h264Payload(offer: string): i64 throws string

A baseline H.264 payload with non-interleaved packets, matching the stream the encoder emits.

Effects: fail.

answer

gizlang
function answer(sys: System, offer: string, iceServers: Vec<string>, audioOnly: bool): Peer throws string

Answers a receive-only browser offer. iceServers use STUN/TURN URLs understood by libdatachannel.

Effects: fail, io.

Methods

Peer.description

gizlang
function Peer.description(self: Peer, timeoutMs: i64 = 3000): string throws string

Current gathered SDP. Wait until candidates have appeared, bounded by timeoutMs.

Effects: fail, io.

Peer.candidate

gizlang
function Peer.candidate(self: Peer, candidate: string, mid: string): void throws string

Adds the remote ICE candidate candidate of media section mid.

Effects: fail, io.

Peer.receive

gizlang
function Peer.receive(self: mut Peer): Vec<string> throws string

The data-channel messages that arrived since the last call; it also takes in the connection's state changes.

Effects: fail, io.

Peer.connected

gizlang
function Peer.connected(self: Peer): bool

Whether the connection is up.

Peer.ended

gizlang
function Peer.ended(self: Peer): bool

Whether the connection failed or closed.

Peer.event

gizlang
function Peer.event(self: Peer, message: string): void throws string

Sends message on the first open data channel (the own, else the remote one); without one it is dropped.

Effects: fail, io.

Peer.send

gizlang
function Peer.send(self: Peer, video: bool, data: bytes, timestamp: u64): void throws string

A packetized H264 length-prefixed access unit or an Opus packet at the track's timestamp.

Effects: fail, io.

Peer.close

gizlang
function Peer.close(self: mut Peer): void

Closes the connection and releases its callbacks; a second close does nothing.

Effects: fail, io.