@gjsify/webrtc 0.51.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,6 +40,33 @@ pc.onicecandidate = (event) => {
40
40
  };
41
41
  ```
42
42
 
43
+ ## Audio device selection
44
+
45
+ On `ensureGstInit()` (the first `RTCPeerConnection`, `getUserMedia`, or any
46
+ other GStreamer-touching call), this package sets the `openalsrc` and
47
+ `openalsink` GStreamer plugin features' rank to `Gst.Rank.NONE` in the
48
+ **process-wide** GStreamer registry — it affects every pipeline in the
49
+ process, including ones built outside this package.
50
+
51
+ Why: `getUserMedia({ audio: true })`'s capture source falls through to
52
+ `autoaudiosrc` when PipeWire/Pulse/V4L2 aren't reachable, and `autoaudiosrc`
53
+ tries registered audio sources in rank order until one opens. `openalsrc`
54
+ (and its sink counterpart, reachable the same way through `autoaudiosink`)
55
+ is the one candidate whose `open()` does not fail fast: OpenAL Soft's
56
+ device backend runs its own nested connection probe synchronously inside
57
+ the GStreamer state change, which can stall the whole process for tens of
58
+ seconds (measured in CI — `[ALSOFT] Failed to connect PipeWire` followed by
59
+ 30+ seconds of silence, hit while moving a shared track's source between
60
+ peer connections). `autoaudiosrc`/`autoaudiosink` already fall back to
61
+ `audiotestsrc`/`fakesink` when nothing opens, in well under 100ms —
62
+ deranking `openalsrc`/`openalsink` restores that existing fallback instead
63
+ of leaving it reachable through the one candidate that defeats it.
64
+
65
+ Set `GJSIFY_GST_KEEP_OPENAL=1` to opt out, if a host genuinely needs OpenAL
66
+ Soft as its audio backend. This also un-deranks `openalsink` for
67
+ `@gjsify/webaudio` if both are loaded in the same process — the two
68
+ packages share the one GStreamer registry.
69
+
43
70
  ## License
44
71
 
45
72
  MIT
@@ -1,4 +1,4 @@
1
- import"./_virtual/_rolldown/runtime.js";import e from"gi://Gst?version=1.0";import{DOMException as t}from"@gjsify/dom-exception";let n=!1;function ensureGstInit(){n||=(e.init(null),!0)}function ensureWebrtcbinAvailable(){ensureGstInit(),e.ElementFactory.find(`webrtcbin`)||throwNotSupported(e.ElementFactory.find(`dtlsenc`)!==null||e.ElementFactory.find(`sctpenc`)!==null?`GStreamer element "webrtcbin" not available, but gst-plugins-bad IS installed
1
+ import"./_virtual/_rolldown/runtime.js";import e from"gi://Gst?version=1.0";import t from"gi://GLib?version=2.0";import{DOMException as n}from"@gjsify/dom-exception";let r=!1;const i=[`openalsrc`,`openalsink`];function excludeUnboundedAutodetectCandidates(n=t.getenv(`GJSIFY_GST_KEEP_OPENAL`)===`1`){if(n)return;let r=e.Registry.get();for(let t of i)r.lookup_feature(t)?.set_rank(e.Rank.NONE)}function ensureGstInit(){r||=(e.init(null),excludeUnboundedAutodetectCandidates(),!0)}function ensureWebrtcbinAvailable(){ensureGstInit(),e.ElementFactory.find(`webrtcbin`)||throwNotSupported(e.ElementFactory.find(`dtlsenc`)!==null||e.ElementFactory.find(`sctpenc`)!==null?`GStreamer element "webrtcbin" not available, but gst-plugins-bad IS installed
2
2
  (its dtls/sctp elements are registered). This distro does not ship the
3
3
  plugin — verify with: ls /usr/lib/gstreamer-1.0/libgstwebrtc.so
4
4
  Alpine/postmarketOS: absent since Alpine v3.24; no package provides it.
@@ -8,4 +8,4 @@ plugin — verify with: ls /usr/lib/gstreamer-1.0/libgstwebrtc.so
8
8
  Alpine/postmarketOS: apk add gst-plugins-bad`),e.ElementFactory.find(`nicesrc`)||throwNotSupported(`GStreamer "nice" plugin (libnice-gstreamer) not available — required by webrtcbin.
9
9
  Fedora: dnf install libnice-gstreamer1
10
10
  Ubuntu/Debian: apt install gstreamer1.0-nice
11
- Verify with: gst-inspect-1.0 nicesrc`)}function throwNotSupported(e){throw new t(e,`NotSupportedError`)}export{e as Gst,ensureGstInit,ensureWebrtcbinAvailable};
11
+ Verify with: gst-inspect-1.0 nicesrc`)}function throwNotSupported(e){throw new n(e,`NotSupportedError`)}export{e as Gst,ensureGstInit,ensureWebrtcbinAvailable,excludeUnboundedAutodetectCandidates};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{Gst as e,ensureGstInit as t}from"./gst-init.js";import{getUserMedia as n}from"./get-user-media.js";import{MediaDeviceInfo as r}from"./media-device-info.js";import"@gjsify/dom-events/register/event-target";import i from"gi://GLib?version=2.0";const a={"Audio/Source":`audioinput`,"Video/Source":`videoinput`,"Audio/Sink":`audiooutput`};let o=!1;function isDeviceMonitorSafe(){return!(i.getenv(`CI`)||!i.getenv(`DISPLAY`)&&!i.getenv(`WAYLAND_DISPLAY`))}var MediaDevices=class extends EventTarget{_ondevicechange=null;get ondevicechange(){return this._ondevicechange}set ondevicechange(e){this._ondevicechange=e}async getUserMedia(e){if(!e)throw TypeError(`Failed to execute 'getUserMedia' on 'MediaDevices': At least one of audio or video must be requested`);let t=await n(e);return o=!0,t}async enumerateDevices(){t();let n=null,i=[];try{if(!isDeviceMonitorSafe())return i;n=new e.DeviceMonitor,n.set_show_all_devices(!0);let t=e.Caps.from_string(`audio/x-raw`),s=e.Caps.from_string(`video/x-raw`);if(t&&(n.add_filter(`Audio/Source`,t),n.add_filter(`Audio/Sink`,t)),s&&n.add_filter(`Video/Source`,s),!n.start())return i;let c;try{c=n.get_devices()??[]}catch{return i}for(let e of c){let t=e.get_device_class?.()??``,n=a[t];if(!n)continue;let s=e.get_display_name?.()??``,c=``,l=``;try{let t=e.get_properties?.();if(t){let e=t.n_fields();for(let n=0;n<e;n++){let e=t.nth_field_name(n);if(e===`persistent-id`||e===`node.name`){let n=t.get_value(e);n&&!c&&(c=String(n))}if(e===`group-id`){let n=t.get_value(e);n&&(l=String(n))}}}}catch{}c||=s||`${n}-${i.length}`,o?i.push(new r({deviceId:c,kind:n,label:s,groupId:l})):i.some(e=>e.kind===n)||i.push(new r({deviceId:``,kind:n,label:``,groupId:``}))}}catch{return i}finally{try{n?.stop()}catch{}}let s={audioinput:0,videoinput:1,audiooutput:2};return i.sort((e,t)=>(s[e.kind]??3)-(s[t.kind]??3)),i}getSupportedConstraints(){return{deviceId:!0,width:!0,height:!0,frameRate:!0,sampleRate:!0,channelCount:!0,aspectRatio:!1,facingMode:!1,resizeMode:!1,echoCancellation:!1,autoGainControl:!1,noiseSuppression:!1,latency:!1,groupId:!1}}};export{MediaDevices};
1
+ import"./_virtual/_rolldown/runtime.js";import{Gst as e,ensureGstInit as t}from"./gst-init.js";import{getUserMedia as n}from"./get-user-media.js";import{MediaDeviceInfo as r}from"./media-device-info.js";import i from"gi://GLib?version=2.0";import"@gjsify/dom-events/register/event-target";const a={"Audio/Source":`audioinput`,"Video/Source":`videoinput`,"Audio/Sink":`audiooutput`};let o=!1;function isDeviceMonitorSafe(){return!(i.getenv(`CI`)||!i.getenv(`DISPLAY`)&&!i.getenv(`WAYLAND_DISPLAY`))}var MediaDevices=class extends EventTarget{_ondevicechange=null;get ondevicechange(){return this._ondevicechange}set ondevicechange(e){this._ondevicechange=e}async getUserMedia(e){if(!e)throw TypeError(`Failed to execute 'getUserMedia' on 'MediaDevices': At least one of audio or video must be requested`);let t=await n(e);return o=!0,t}async enumerateDevices(){t();let n=null,i=[];try{if(!isDeviceMonitorSafe())return i;n=new e.DeviceMonitor,n.set_show_all_devices(!0);let t=e.Caps.from_string(`audio/x-raw`),s=e.Caps.from_string(`video/x-raw`);if(t&&(n.add_filter(`Audio/Source`,t),n.add_filter(`Audio/Sink`,t)),s&&n.add_filter(`Video/Source`,s),!n.start())return i;let c;try{c=n.get_devices()??[]}catch{return i}for(let e of c){let t=e.get_device_class?.()??``,n=a[t];if(!n)continue;let s=e.get_display_name?.()??``,c=``,l=``;try{let t=e.get_properties?.();if(t){let e=t.n_fields();for(let n=0;n<e;n++){let e=t.nth_field_name(n);if(e===`persistent-id`||e===`node.name`){let n=t.get_value(e);n&&!c&&(c=String(n))}if(e===`group-id`){let n=t.get_value(e);n&&(l=String(n))}}}}catch{}c||=s||`${n}-${i.length}`,o?i.push(new r({deviceId:c,kind:n,label:s,groupId:l})):i.some(e=>e.kind===n)||i.push(new r({deviceId:``,kind:n,label:``,groupId:``}))}}catch{return i}finally{try{n?.stop()}catch{}}let s={audioinput:0,videoinput:1,audiooutput:2};return i.sort((e,t)=>(s[e.kind]??3)-(s[t.kind]??3)),i}getSupportedConstraints(){return{deviceId:!0,width:!0,height:!0,frameRate:!0,sampleRate:!0,channelCount:!0,aspectRatio:!1,facingMode:!1,resizeMode:!1,echoCancellation:!1,autoGainControl:!1,noiseSuppression:!1,latency:!1,groupId:!1}}};export{MediaDevices};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{Gst as e}from"./gst-init.js";import"@gjsify/dom-events/register/event-target";import t from"gi://GLib?version=2.0";var n=class MediaStreamTrack extends EventTarget{id;kind;label;_enabled=!0;_muted;_ended=!1;_contentHint=``;_onended=null;_onmute=null;_onunmute=null;_gstSource=null;_gstPipeline=null;_gstTee=null;_teeMultiplexer=null;_senderConsumers=0;_enableCallback=null;constructor(e){super(),this.id=e.id??t.uuid_string_random(),this.kind=e.kind,this.label=e.label??``,this._muted=e.muted??!1,e._gst&&(this._gstSource=e._gst.source,this._gstPipeline=e._gst.pipeline)}get enabled(){return this._enabled}set enabled(e){let t=!!e;this._enabled!==t&&(this._enabled=t,this._enableCallback?.(t))}get muted(){return this._muted}get readyState(){return this._ended?`ended`:`live`}get contentHint(){return this._contentHint}set contentHint(e){if(this.kind===`audio`){if(e!==``&&e!==`speech`&&e!==`speech-recognition`&&e!==`music`)return}else if(e!==``&&e!==`motion`&&e!==`detail`&&e!==`text`)return;this._contentHint=e}get onended(){return this._onended}set onended(e){this._onended=e}get onmute(){return this._onmute}set onmute(e){this._onmute=e}get onunmute(){return this._onunmute}set onunmute(e){this._onunmute=e}clone(){let e=new MediaStreamTrack({kind:this.kind,label:this.label,muted:this._muted});return e._enabled=this._enabled,e}stop(){if(this._ended)return;if(this._ended=!0,this._gstSource||this._gstPipeline){try{this._gstPipeline?.set_state(e.State.NULL)}catch{}try{this._gstSource?.set_state(e.State.NULL)}catch{}this._gstSource=null,this._gstPipeline=null}let t=new Event(`ended`);this._onended?.call(this,t),this.dispatchEvent(t)}getCapabilities(){return{}}getConstraints(){return{}}getSettings(){return{}}applyConstraints(e){return Promise.reject(new DOMException(`applyConstraints is not supported`,`NotSupportedError`))}_setMuted(e){if(this._muted===e)return;this._muted=e;let t=new Event(e?`mute`:`unmute`);e?this._onmute?.call(this,t):this._onunmute?.call(this,t),this.dispatchEvent(t)}_setEnableCallback(e){this._enableCallback=e}};export{n as MediaStreamTrack};
1
+ import"./_virtual/_rolldown/runtime.js";import{Gst as e}from"./gst-init.js";import t from"gi://GLib?version=2.0";import"@gjsify/dom-events/register/event-target";var n=class MediaStreamTrack extends EventTarget{id;kind;label;_enabled=!0;_muted;_ended=!1;_contentHint=``;_onended=null;_onmute=null;_onunmute=null;_gstSource=null;_gstPipeline=null;_gstTee=null;_teeMultiplexer=null;_senderConsumers=0;_enableCallback=null;constructor(e){super(),this.id=e.id??t.uuid_string_random(),this.kind=e.kind,this.label=e.label??``,this._muted=e.muted??!1,e._gst&&(this._gstSource=e._gst.source,this._gstPipeline=e._gst.pipeline)}get enabled(){return this._enabled}set enabled(e){let t=!!e;this._enabled!==t&&(this._enabled=t,this._enableCallback?.(t))}get muted(){return this._muted}get readyState(){return this._ended?`ended`:`live`}get contentHint(){return this._contentHint}set contentHint(e){if(this.kind===`audio`){if(e!==``&&e!==`speech`&&e!==`speech-recognition`&&e!==`music`)return}else if(e!==``&&e!==`motion`&&e!==`detail`&&e!==`text`)return;this._contentHint=e}get onended(){return this._onended}set onended(e){this._onended=e}get onmute(){return this._onmute}set onmute(e){this._onmute=e}get onunmute(){return this._onunmute}set onunmute(e){this._onunmute=e}clone(){let e=new MediaStreamTrack({kind:this.kind,label:this.label,muted:this._muted});return e._enabled=this._enabled,e}stop(){if(this._ended)return;if(this._ended=!0,this._gstSource||this._gstPipeline){try{this._gstPipeline?.set_state(e.State.NULL)}catch{}try{this._gstSource?.set_state(e.State.NULL)}catch{}this._gstSource=null,this._gstPipeline=null}let t=new Event(`ended`);this._onended?.call(this,t),this.dispatchEvent(t)}getCapabilities(){return{}}getConstraints(){return{}}getSettings(){return{}}applyConstraints(e){return Promise.reject(new DOMException(`applyConstraints is not supported`,`NotSupportedError`))}_setMuted(e){if(this._muted===e)return;this._muted=e;let t=new Event(e?`mute`:`unmute`);e?this._onmute?.call(this,t):this._onunmute?.call(this,t),this.dispatchEvent(t)}_setEnableCallback(e){this._enableCallback=e}};export{n as MediaStreamTrack};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import"@gjsify/dom-events/register/event-target";import e from"gi://GLib?version=2.0";var t=class MediaStream extends EventTarget{id;_tracks=new Map;_onaddtrack=null;_onremovetrack=null;constructor(t){if(super(),this.id=e.uuid_string_random(),t instanceof MediaStream)for(let e of t.getTracks())this._tracks.set(e.id,e.clone());else if(Array.isArray(t))for(let e of t)this._tracks.set(e.id,e)}get active(){for(let e of this._tracks.values())if(e.readyState===`live`)return!0;return!1}get onaddtrack(){return this._onaddtrack}set onaddtrack(e){this._onaddtrack=e}get onremovetrack(){return this._onremovetrack}set onremovetrack(e){this._onremovetrack=e}getTracks(){return[...this._tracks.values()]}getAudioTracks(){return this.getTracks().filter(e=>e.kind===`audio`)}getVideoTracks(){return this.getTracks().filter(e=>e.kind===`video`)}getTrackById(e){return this._tracks.get(e)??null}addTrack(e){if(this._tracks.has(e.id))return;this._tracks.set(e.id,e);let t=new MediaStreamTrackEvent(`addtrack`,{track:e});this._onaddtrack?.call(this,t),this.dispatchEvent(t)}removeTrack(e){if(!this._tracks.delete(e.id))return;let t=new MediaStreamTrackEvent(`removetrack`,{track:e});this._onremovetrack?.call(this,t),this.dispatchEvent(t)}clone(){return new MediaStream(this)}},MediaStreamTrackEvent=class extends Event{track;constructor(e,t){super(e,t),this.track=t.track}};export{t as MediaStream,MediaStreamTrackEvent};
1
+ import"./_virtual/_rolldown/runtime.js";import e from"gi://GLib?version=2.0";import"@gjsify/dom-events/register/event-target";var t=class MediaStream extends EventTarget{id;_tracks=new Map;_onaddtrack=null;_onremovetrack=null;constructor(t){if(super(),this.id=e.uuid_string_random(),t instanceof MediaStream)for(let e of t.getTracks())this._tracks.set(e.id,e.clone());else if(Array.isArray(t))for(let e of t)this._tracks.set(e.id,e)}get active(){for(let e of this._tracks.values())if(e.readyState===`live`)return!0;return!1}get onaddtrack(){return this._onaddtrack}set onaddtrack(e){this._onaddtrack=e}get onremovetrack(){return this._onremovetrack}set onremovetrack(e){this._onremovetrack=e}getTracks(){return[...this._tracks.values()]}getAudioTracks(){return this.getTracks().filter(e=>e.kind===`audio`)}getVideoTracks(){return this.getTracks().filter(e=>e.kind===`video`)}getTrackById(e){return this._tracks.get(e)??null}addTrack(e){if(this._tracks.has(e.id))return;this._tracks.set(e.id,e);let t=new MediaStreamTrackEvent(`addtrack`,{track:e});this._onaddtrack?.call(this,t),this.dispatchEvent(t)}removeTrack(e){if(!this._tracks.delete(e.id))return;let t=new MediaStreamTrackEvent(`removetrack`,{track:e});this._onremovetrack?.call(this,t),this.dispatchEvent(t)}clone(){return new MediaStream(this)}},MediaStreamTrackEvent=class extends Event{track;constructor(e,t){super(e,t),this.track=t.track}};export{t as MediaStream,MediaStreamTrackEvent};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{RTCError as e}from"./rtc-error.js";import{RTCErrorEvent as t}from"./rtc-events.js";import{DOMException as n}from"@gjsify/dom-exception";import r from"gi://GLib?version=2.0";import{DataChannelBridge as i}from"@gjsify/webrtc-native";import{Blob as a}from"@gjsify/buffer";const o={1:`connecting`,2:`open`,3:`closing`,4:`closed`};function toGBytes(e){let t;return t=ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),new r.Bytes(t)}function bytesToArrayBuffer(e){let t=e,n=t.toArray?.();if(n instanceof Uint8Array)return n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength);let r=t.get_data?.();return r instanceof Uint8Array?r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):new ArrayBuffer(0)}var RTCDataChannel=class extends EventTarget{_native;_bridge;_binaryType=`arraybuffer`;_bufferedAmount=0;_closed=!1;_onopen=null;_onclose=null;_onerror=null;_onmessage=null;_onbufferedamountlow=null;_onclosing=null;_sctpTransport=null;constructor(e,t){super(),this._sctpTransport=t??null;let n=e;n.channel!==void 0&&typeof n.dispose_bridge==`function`?(this._bridge=e,this._native=this._bridge.channel):(this._native=e,this._bridge=new i({channel:this._native})),this._bridge.connect(`opened`,()=>this._handleOpen()),this._bridge.connect(`closed`,()=>this._handleClose()),this._bridge.connect(`error-occurred`,(e,t)=>this._handleError(t)),this._bridge.connect(`message-string`,(e,t)=>this._handleString(t)),this._bridge.connect(`message-data`,(e,t)=>this._handleData(t)),this._bridge.connect(`buffered-amount-low`,()=>this._handleBufferedAmountLow()),this._bridge.connect(`ready-state-changed`,()=>this._handleReadyStateChange())}get label(){return this._native.label}get ordered(){return this._native.ordered}get protocol(){return this._native.protocol}get negotiated(){return this._native.negotiated}get id(){return this._native.id>=0?this._native.id:null}get maxPacketLifeTime(){let e=this._native.max_packet_lifetime;return e>=0?e:null}get maxRetransmits(){let e=this._native.max_retransmits;return e>=0?e:null}get readyState(){return this._closed?`closed`:o[this._native.ready_state]??`connecting`}get bufferedAmount(){try{return Number(this._native.buffered_amount)||this._bufferedAmount}catch{return this._bufferedAmount}}get bufferedAmountLowThreshold(){return Number(this._native.buffered_amount_low_threshold)||0}set bufferedAmountLowThreshold(e){this._native.buffered_amount_low_threshold=e}get binaryType(){return this._binaryType}set binaryType(e){e!==`arraybuffer`&&e!==`blob`||(this._binaryType=e)}get onopen(){return this._onopen}set onopen(e){this._onopen=e}get onclose(){return this._onclose}set onclose(e){this._onclose=e}get onclosing(){return this._onclosing}set onclosing(e){this._onclosing=e}get onerror(){return this._onerror}set onerror(e){this._onerror=e}get onmessage(){return this._onmessage}set onmessage(e){this._onmessage=e}get onbufferedamountlow(){return this._onbufferedamountlow}set onbufferedamountlow(e){this._onbufferedamountlow=e}send(e){let t=this.readyState;if(t!==`open`)throw new n(`RTCDataChannel.send: readyState is '${t}', expected 'open'`,`InvalidStateError`);if(typeof e==`string`){let t=new TextEncoder().encode(e).byteLength;this._enforceMaxMessageSize(t),this._native.send_string(e),this._bufferedAmount+=t;return}if(e instanceof a){e.arrayBuffer().then(e=>{try{this._enforceMaxMessageSize(e.byteLength)}catch(e){this._handleError(e instanceof Error?e.message:String(e));return}try{this._native.send_data(toGBytes(e)),this._bufferedAmount+=e.byteLength}catch{}});return}if(ArrayBuffer.isView(e)){this._enforceMaxMessageSize(e.byteLength);let t=toGBytes(e);this._native.send_data(t),this._bufferedAmount+=e.byteLength;return}if(e instanceof ArrayBuffer){this._enforceMaxMessageSize(e.byteLength);let t=toGBytes(e);this._native.send_data(t),this._bufferedAmount+=e.byteLength;return}throw TypeError(`RTCDataChannel.send: unsupported data type`)}_enforceMaxMessageSize(e){if(!this._sctpTransport)return;let t=this._sctpTransport.maxMessageSize;if(!(t<=0)&&e>t)throw new n(`RTCDataChannel.send: data (${e} bytes) exceeds the SCTP max-message-size of ${t} bytes. Split into smaller frames before sending.`,`OperationError`)}close(){if(!this._closed){try{this._native.close()}catch{}this._disconnectSignals(),this._closed=!0}}_disconnectSignals(){try{this._bridge.dispose_bridge()}catch{}}_handleOpen(){let e=new Event(`open`);this._onopen?.call(this,e),this.dispatchEvent(e)}_handleClose(){this._closed=!0;let e=new Event(`close`);this._onclose?.call(this,e),this.dispatchEvent(e)}_handleError(n){let r=new t(`error`,{error:new e({errorDetail:`data-channel-failure`},n||`RTCDataChannel error`)});this._onerror?.call(this,r),this.dispatchEvent(r)}_handleString(e){let t=new MessageEvent(`message`,{data:e});this._onmessage?.call(this,t),this.dispatchEvent(t)}_handleData(e){if(!e)return;let t=bytesToArrayBuffer(e),n=this._binaryType===`blob`?new a([t]):t,r=new MessageEvent(`message`,{data:n});this._onmessage?.call(this,r),this.dispatchEvent(r)}_handleBufferedAmountLow(){this._bufferedAmount=Number(this._native.buffered_amount)||0;let e=new Event(`bufferedamountlow`);this._onbufferedamountlow?.call(this,e),this.dispatchEvent(e)}_handleReadyStateChange(){if(this.readyState===`closing`){let e=new Event(`closing`);this._onclosing?.call(this,e),this.dispatchEvent(e)}}};export{RTCDataChannel};
1
+ import"./_virtual/_rolldown/runtime.js";import{RTCError as e}from"./rtc-error.js";import{RTCErrorEvent as t}from"./rtc-events.js";import n from"gi://GLib?version=2.0";import{DOMException as r}from"@gjsify/dom-exception";import{DataChannelBridge as i}from"@gjsify/webrtc-native";import{Blob as a}from"@gjsify/buffer";const o={1:`connecting`,2:`open`,3:`closing`,4:`closed`};function toGBytes(e){let t;return t=ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),new n.Bytes(t)}function bytesToArrayBuffer(e){let t=e,n=t.toArray?.();if(n instanceof Uint8Array)return n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength);let r=t.get_data?.();return r instanceof Uint8Array?r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):new ArrayBuffer(0)}var RTCDataChannel=class extends EventTarget{_native;_bridge;_binaryType=`arraybuffer`;_bufferedAmount=0;_closed=!1;_onopen=null;_onclose=null;_onerror=null;_onmessage=null;_onbufferedamountlow=null;_onclosing=null;_sctpTransport=null;constructor(e,t){super(),this._sctpTransport=t??null;let n=e;n.channel!==void 0&&typeof n.dispose_bridge==`function`?(this._bridge=e,this._native=this._bridge.channel):(this._native=e,this._bridge=new i({channel:this._native})),this._bridge.connect(`opened`,()=>this._handleOpen()),this._bridge.connect(`closed`,()=>this._handleClose()),this._bridge.connect(`error-occurred`,(e,t)=>this._handleError(t)),this._bridge.connect(`message-string`,(e,t)=>this._handleString(t)),this._bridge.connect(`message-data`,(e,t)=>this._handleData(t)),this._bridge.connect(`buffered-amount-low`,()=>this._handleBufferedAmountLow()),this._bridge.connect(`ready-state-changed`,()=>this._handleReadyStateChange())}get label(){return this._native.label}get ordered(){return this._native.ordered}get protocol(){return this._native.protocol}get negotiated(){return this._native.negotiated}get id(){return this._native.id>=0?this._native.id:null}get maxPacketLifeTime(){let e=this._native.max_packet_lifetime;return e>=0?e:null}get maxRetransmits(){let e=this._native.max_retransmits;return e>=0?e:null}get readyState(){return this._closed?`closed`:o[this._native.ready_state]??`connecting`}get bufferedAmount(){try{return Number(this._native.buffered_amount)||this._bufferedAmount}catch{return this._bufferedAmount}}get bufferedAmountLowThreshold(){return Number(this._native.buffered_amount_low_threshold)||0}set bufferedAmountLowThreshold(e){this._native.buffered_amount_low_threshold=e}get binaryType(){return this._binaryType}set binaryType(e){e!==`arraybuffer`&&e!==`blob`||(this._binaryType=e)}get onopen(){return this._onopen}set onopen(e){this._onopen=e}get onclose(){return this._onclose}set onclose(e){this._onclose=e}get onclosing(){return this._onclosing}set onclosing(e){this._onclosing=e}get onerror(){return this._onerror}set onerror(e){this._onerror=e}get onmessage(){return this._onmessage}set onmessage(e){this._onmessage=e}get onbufferedamountlow(){return this._onbufferedamountlow}set onbufferedamountlow(e){this._onbufferedamountlow=e}send(e){let t=this.readyState;if(t!==`open`)throw new r(`RTCDataChannel.send: readyState is '${t}', expected 'open'`,`InvalidStateError`);if(typeof e==`string`){let t=new TextEncoder().encode(e).byteLength;this._enforceMaxMessageSize(t),this._native.send_string(e),this._bufferedAmount+=t;return}if(e instanceof a){e.arrayBuffer().then(e=>{try{this._enforceMaxMessageSize(e.byteLength)}catch(e){this._handleError(e instanceof Error?e.message:String(e));return}try{this._native.send_data(toGBytes(e)),this._bufferedAmount+=e.byteLength}catch{}});return}if(ArrayBuffer.isView(e)){this._enforceMaxMessageSize(e.byteLength);let t=toGBytes(e);this._native.send_data(t),this._bufferedAmount+=e.byteLength;return}if(e instanceof ArrayBuffer){this._enforceMaxMessageSize(e.byteLength);let t=toGBytes(e);this._native.send_data(t),this._bufferedAmount+=e.byteLength;return}throw TypeError(`RTCDataChannel.send: unsupported data type`)}_enforceMaxMessageSize(e){if(!this._sctpTransport)return;let t=this._sctpTransport.maxMessageSize;if(!(t<=0)&&e>t)throw new r(`RTCDataChannel.send: data (${e} bytes) exceeds the SCTP max-message-size of ${t} bytes. Split into smaller frames before sending.`,`OperationError`)}close(){if(!this._closed){try{this._native.close()}catch{}this._disconnectSignals(),this._closed=!0}}_disconnectSignals(){try{this._bridge.dispose_bridge()}catch{}}_handleOpen(){let e=new Event(`open`);this._onopen?.call(this,e),this.dispatchEvent(e)}_handleClose(){this._closed=!0;let e=new Event(`close`);this._onclose?.call(this,e),this.dispatchEvent(e)}_handleError(n){let r=new t(`error`,{error:new e({errorDetail:`data-channel-failure`},n||`RTCDataChannel error`)});this._onerror?.call(this,r),this.dispatchEvent(r)}_handleString(e){let t=new MessageEvent(`message`,{data:e});this._onmessage?.call(this,t),this.dispatchEvent(t)}_handleData(e){if(!e)return;let t=bytesToArrayBuffer(e),n=this._binaryType===`blob`?new a([t]):t,r=new MessageEvent(`message`,{data:n});this._onmessage?.call(this,r),this.dispatchEvent(r)}_handleBufferedAmountLow(){this._bufferedAmount=Number(this._native.buffered_amount)||0;let e=new Event(`bufferedamountlow`);this._onbufferedamountlow?.call(this,e),this.dispatchEvent(e)}_handleReadyStateChange(){if(this.readyState===`closing`){let e=new Event(`closing`);this._onclosing?.call(this,e),this.dispatchEvent(e)}}};export{RTCDataChannel};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{Gst as e,ensureWebrtcbinAvailable as t}from"./gst-init.js";import{MediaStream as n}from"./media-stream.js";import{gstToConnectionState as r,gstToIceConnectionState as i,gstToIceGatheringState as a,gstToSignalingState as o}from"./gst-enum-maps.js";import{asWebRtcBin as s,asWebRtcSrcPad as c,emitWebRtcBin as l}from"./internal/gst-types.js";import{RTCSessionDescription as u}from"./rtc-session-description.js";import{RTCIceCandidate as d}from"./rtc-ice-candidate.js";import{RTCDataChannelEvent as f,RTCPeerConnectionIceEvent as p}from"./rtc-events.js";import{RTCDataChannel as m}from"./rtc-data-channel.js";import{RTCRtpSender as h}from"./rtc-rtp-sender.js";import{RTCRtpReceiver as g}from"./rtc-rtp-receiver.js";import{RTCRtpTransceiver as _}from"./rtc-rtp-transceiver.js";import{RTCTrackEvent as v}from"./rtc-track-event.js";import{RTCIceTransport as y}from"./rtc-ice-transport.js";import{RTCDtlsTransport as b}from"./rtc-dtls-transport.js";import{RTCSctpTransport as x}from"./rtc-sctp-transport.js";import{RTCCertificate as S,generateCertificate as C}from"./rtc-certificate.js";import{installSdpNegotiationMethods as w}from"./rtc-peer-connection/sdp-negotiation.js";import{installDataChannelMethods as T}from"./rtc-peer-connection/data-channel.js";import{installTransceiverMethods as E}from"./rtc-peer-connection/transceivers.js";import{installTrackMethods as D}from"./rtc-peer-connection/tracks.js";import{installStatsAndConfigMethods as O}from"./rtc-peer-connection/stats-and-config.js";import{DOMException as k}from"@gjsify/dom-exception";import A from"gi://GLib?version=2.0";import j from"gi://GstWebRTC?version=1.0";import{WebrtcbinBridge as M}from"@gjsify/webrtc-native";import N from"gi://GObject?version=2.0";let P=0;var RTCPeerConnection=class extends EventTarget{_pipeline;_webrtcbin;_bridge;_conf;_closed=!1;_iceRestartNeeded=!1;_hasNegotiated=!1;_dataChannels=new Map;_transceivers=new Map;_senders=[];_receivers=[];_iceTransport=null;_dtlsTransport=null;_sctpTransport=null;canTrickleIceCandidates=!0;constructor(n){super(),t();let[r,i]=e.version();if(r<1||r===1&&i<20)throw new k(`@gjsify/webrtc requires GStreamer >= 1.20 (you have ${r}.${i}). webrtcbin is only stable from 1.20 onward.`,`NotSupportedError`);let a=++P;this._pipeline=new e.Pipeline({name:`gjsify-webrtc-pipeline-${a}`});let o=e.ElementFactory.make(`webrtcbin`,`gjsify-webrtcbin-${a}`);if(!o)throw Error(`Failed to create webrtcbin element`);if(this._webrtcbin=o,this._conf={...n},n?.certificates){for(let e of n.certificates)if(e instanceof S&&e.expires<=Date.now())throw new k(`RTCPeerConnection: one of the provided certificates has expired`,`InvalidAccessError`)}this._applyIceServers(n?.iceServers??[]),this._applyIceTransportPolicy(n?.iceTransportPolicy),this._applyBundlePolicy(n?.bundlePolicy),this._pipeline.add(this._webrtcbin),this._bridge=new M({bin:this._webrtcbin}),this._bridge.connect(`negotiation-needed`,()=>this._handleNegotiationNeeded()),this._bridge.connect(`icecandidate`,(e,t,n)=>this._handleIceCandidate(t,n)),this._bridge.connect(`datachannel`,(e,t)=>this._handleDataChannel(t)),this._bridge.connect(`new-transceiver`,(e,t)=>this._handleNewTransceiver(t)),this._bridge.connect(`pad-added`,(e,t)=>this._handlePadAdded(t)),this._bridge.connect(`connection-state-changed`,()=>this._dispatchStateChange(`connectionstatechange`)),this._bridge.connect(`ice-connection-state-changed`,()=>this._dispatchStateChange(`iceconnectionstatechange`)),this._bridge.connect(`ice-gathering-state-changed`,()=>this._dispatchStateChange(`icegatheringstatechange`)),this._bridge.connect(`signaling-state-changed`,()=>this._dispatchStateChange(`signalingstatechange`)),this._pipeline.set_state(e.State.PLAYING)}_applyIceServers(e){let t=!1;for(let n of e){let e=Array.isArray(n.urls)?n.urls:[n.urls];if(e.length===0)throw SyntaxError(`RTCIceServer.urls must not be empty`);for(let r of e){if(typeof r!=`string`||r.length===0)throw TypeError(`RTCIceServer.urls entries must be non-empty strings`);let e=r.indexOf(`:`);if(e<0)throw TypeError(`Invalid ICE server URL "${r}"`);let i=r.slice(0,e+1),a=r.slice(e+1);if(i===`stun:`||i===`stuns:`){if(t)continue;s(this._webrtcbin).stun_server=`${i}//${a}`,t=!0}else if(i===`turn:`||i===`turns:`){if(typeof n.username!=`string`||typeof n.credential!=`string`)throw TypeError(`TURN server credential for ${r} missing`);let e=`${i}//${encodeURIComponent(n.username)}:${encodeURIComponent(n.credential)}@${a}`;try{l(this._webrtcbin,`add-turn-server`,e)}catch{s(this._webrtcbin).turn_server=e}}else throw TypeError(`Unsupported ICE server protocol "${i}"`)}}}_applyIceTransportPolicy(e){if(!e)return;let t=e===`relay`?j.WebRTCICETransportPolicy.RELAY:j.WebRTCICETransportPolicy.ALL;try{s(this._webrtcbin).ice_transport_policy=t}catch{}}_applyBundlePolicy(e){if(!e)return;let t;switch(e){case`balanced`:t=j.WebRTCBundlePolicy.BALANCED;break;case`max-compat`:t=j.WebRTCBundlePolicy.MAX_COMPAT;break;case`max-bundle`:t=j.WebRTCBundlePolicy.MAX_BUNDLE;break;default:return}try{s(this._webrtcbin).bundle_policy=t}catch{}}get signalingState(){if(this._closed)return`closed`;try{return o(s(this._webrtcbin).signaling_state)}catch{return`stable`}}get connectionState(){if(this._closed)return`closed`;try{return r(s(this._webrtcbin).connection_state)}catch{return`new`}}get iceConnectionState(){if(this._closed)return`closed`;try{return i(s(this._webrtcbin).ice_connection_state)}catch{return`new`}}get iceGatheringState(){try{return a(s(this._webrtcbin).ice_gathering_state)}catch{return`new`}}_descProp(e){try{let t=s(this._webrtcbin)[e];return t?u.fromGstDesc(t):null}catch{return null}}get localDescription(){return this._descProp(`local_description`)}get remoteDescription(){return this._descProp(`remote_description`)}get currentLocalDescription(){return this._descProp(`current_local_description`)}get currentRemoteDescription(){return this._descProp(`current_remote_description`)}get pendingLocalDescription(){return this._descProp(`pending_local_description`)}get pendingRemoteDescription(){return this._descProp(`pending_remote_description`)}get sctp(){return this._sctpTransport}get peerIdentity(){return Promise.reject(TypeError(`peerIdentity assertions are not implemented`))}get idpErrorInfo(){return null}get idpLoginUrl(){return null}_rejectIfClosed(e){if(this._closed)throw new k(`RTCPeerConnection.${e}: connection is closed`,`InvalidStateError`)}_setStructureField(e,t,n,r){if(r==null)return;let i=new N.Value;n===`boolean`?(i.init(N.TYPE_BOOLEAN),i.set_boolean(!!r)):n===`int`?(i.init(N.TYPE_INT),i.set_int(Number(r))):n===`string`&&(i.init(N.TYPE_STRING),i.set_string(String(r))),e.set_value(t,i),i.unset()}close(){this._closed||(this._closed=!0,A.idle_add(A.PRIORITY_DEFAULT,()=>{try{this._pipeline.set_state(e.State.NULL)}catch{}for(let e of this._dataChannels.values())try{e._disconnectSignals()}catch{}this._dataChannels.clear();for(let e of this._senders)try{e._teardownPipeline()}catch{}for(let e of this._receivers)try{e._dispose()}catch{}this._transceivers.clear(),this._senders.length=0,this._receivers.length=0,this._dtlsTransport&&this._dtlsTransport._setState(`closed`),this._iceTransport&&this._iceTransport._setState(`closed`),this._sctpTransport&&this._sctpTransport._setState(`closed`);try{this._bridge.dispose_bridge()}catch{}return A.SOURCE_REMOVE}))}getIdentityAssertion(){return Promise.reject(Error(`getIdentityAssertion is not implemented`))}_findNewGstTransceiver(){for(let e=0;;e++){let t=l(this._webrtcbin,`get-transceiver`,e);if(!t)return null;if(!this._transceivers.has(t))return t}}_ensureTransports(){return this._dtlsTransport||=(this._iceTransport=new y,new b(this._iceTransport)),this._dtlsTransport}_ensureSctpTransport(){if(this._sctpTransport)return;let e=this._ensureTransports();this._sctpTransport=new x(e)}_assignTransports(){let e=this._ensureTransports();for(let t of this._senders)t._transport=e;for(let t of this._receivers)t._transport=e}_clearTransports(){for(let e of this._senders)e._transport=null;for(let e of this._receivers)e._transport=null}_createTransceiverWrapper(e){let t=`audio`;try{e.kind===j.WebRTCKind.VIDEO&&(t=`video`)}catch{}let n=e.receiver??null,r=e.sender??null,i=new g(t,n,this._pipeline),a=new h(r,this._pipeline,this._webrtcbin);a._kind=t,a._onPipelineChanged=e=>{this._pipeline=e};let statsDelegate=e=>this.getStats(e);if(a._getStatsForTrack=statsDelegate,i._getStatsForTrack=statsDelegate,this.localDescription){let e=this._ensureTransports();a._transport=e,i._transport=e}try{let t=e.mlineindex;typeof t==`number`&&t>=0&&a._setMlineIndex(t)}catch{}let o=new _(e,a,i);return a._transceiver=o,this._transceivers.set(e,o),this._senders.push(a),this._receivers.push(i),o}_handleNegotiationNeeded(){if(this._closed)return;let e=new Event(`negotiationneeded`);this._onnegotiationneeded?.call(this,e),this.dispatchEvent(e)}_negotiationNeededQueued=!1;_updateNegotiationNeeded(){this._closed||this._hasNegotiated&&this.signalingState===`stable`&&(this._negotiationNeededQueued||(this._negotiationNeededQueued=!0,Promise.resolve().then(()=>{this._negotiationNeededQueued=!1,this.signalingState===`stable`&&this._handleNegotiationNeeded()})))}_handleIceCandidate(e,t){let n=new p(`icecandidate`,{candidate:new d({candidate:t,sdpMLineIndex:e})});this._onicecandidate?.call(this,n),this.dispatchEvent(n)}_handleNewTransceiver(e){this._closed||this._transceivers.has(e)||this._createTransceiverWrapper(e)}_handlePadAdded(t){if(this._closed||t.direction!==e.PadDirection.SRC)return;let r=c(t).transceiver;if(!r)return;let i=this._transceivers.get(r);i||=this._createTransceiverWrapper(r),i.receiver._connectToPad(t);let a=new n([i.receiver.track]),o=new v(`track`,{receiver:i.receiver,track:i.receiver.track,streams:[a],transceiver:i});this._ontrack?.call(this,o),this.dispatchEvent(o)}_handleDataChannel(e){this._ensureSctpTransport();let t=e.channel,n=this._dataChannels.get(t);n||(n=new m(e,this._sctpTransport??void 0),this._dataChannels.set(t,n),n.addEventListener(`close`,()=>{this._dataChannels.delete(t)}));let r=new f(`datachannel`,{channel:n});this._ondatachannel?.call(this,r),this.dispatchEvent(r)}_dispatchStateChange(e){e===`connectionstatechange`?this._syncDtlsState():e===`iceconnectionstatechange`?this._syncIceState():e===`icegatheringstatechange`&&this._syncIceGatheringState();let t=new Event(e);switch(e){case`connectionstatechange`:this._onconnectionstatechange?.call(this,t);break;case`iceconnectionstatechange`:this._oniceconnectionstatechange?.call(this,t);break;case`icegatheringstatechange`:this._onicegatheringstatechange?.call(this,t);break;case`signalingstatechange`:this._onsignalingstatechange?.call(this,t);break}this.dispatchEvent(t)}_syncDtlsState(){if(!this._dtlsTransport)return;let e=this.connectionState;this._dtlsTransport._setState({new:`new`,connecting:`connecting`,connected:`connected`,disconnected:`connected`,failed:`failed`,closed:`closed`}[e]??`new`),e===`connected`&&this._sctpTransport&&this._sctpTransport._setState(`connected`)}_syncIceState(){if(!this._iceTransport)return;let e=this.iceConnectionState;this._iceTransport._setState(e)}_syncIceGatheringState(){if(!this._iceTransport)return;let e=this.iceGatheringState;this._iceTransport._setGatheringState(e)}_onconnectionstatechange=null;_ondatachannel=null;_onicecandidate=null;_oniceconnectionstatechange=null;_onicegatheringstatechange=null;_onnegotiationneeded=null;_onsignalingstatechange=null;get onconnectionstatechange(){return this._onconnectionstatechange}set onconnectionstatechange(e){this._onconnectionstatechange=e}get ondatachannel(){return this._ondatachannel}set ondatachannel(e){this._ondatachannel=e}get onicecandidate(){return this._onicecandidate}set onicecandidate(e){this._onicecandidate=e}get oniceconnectionstatechange(){return this._oniceconnectionstatechange}set oniceconnectionstatechange(e){this._oniceconnectionstatechange=e}get onicegatheringstatechange(){return this._onicegatheringstatechange}set onicegatheringstatechange(e){this._onicegatheringstatechange=e}get onnegotiationneeded(){return this._onnegotiationneeded}set onnegotiationneeded(e){this._onnegotiationneeded=e}get onsignalingstatechange(){return this._onsignalingstatechange}set onsignalingstatechange(e){this._onsignalingstatechange=e}_ontrack=null;get ontrack(){return this._ontrack}set ontrack(e){this._ontrack=e}get onicecandidateerror(){return null}set onicecandidateerror(e){}static generateCertificate(e){return C(e)}};w(RTCPeerConnection.prototype),T(RTCPeerConnection.prototype),E(RTCPeerConnection.prototype),D(RTCPeerConnection.prototype),O(RTCPeerConnection.prototype);export{RTCPeerConnection};
1
+ import"./_virtual/_rolldown/runtime.js";import{Gst as e,ensureWebrtcbinAvailable as t}from"./gst-init.js";import{MediaStream as n}from"./media-stream.js";import{gstToConnectionState as r,gstToIceConnectionState as i,gstToIceGatheringState as a,gstToSignalingState as o}from"./gst-enum-maps.js";import{asWebRtcBin as s,asWebRtcSrcPad as c,emitWebRtcBin as l}from"./internal/gst-types.js";import{RTCSessionDescription as u}from"./rtc-session-description.js";import{RTCIceCandidate as d}from"./rtc-ice-candidate.js";import{RTCDataChannelEvent as f,RTCPeerConnectionIceEvent as p}from"./rtc-events.js";import{RTCDataChannel as m}from"./rtc-data-channel.js";import{RTCRtpSender as h}from"./rtc-rtp-sender.js";import{RTCRtpReceiver as g}from"./rtc-rtp-receiver.js";import{RTCRtpTransceiver as _}from"./rtc-rtp-transceiver.js";import{RTCTrackEvent as v}from"./rtc-track-event.js";import{RTCIceTransport as y}from"./rtc-ice-transport.js";import{RTCDtlsTransport as b}from"./rtc-dtls-transport.js";import{RTCSctpTransport as x}from"./rtc-sctp-transport.js";import{RTCCertificate as S,generateCertificate as C}from"./rtc-certificate.js";import{installSdpNegotiationMethods as w}from"./rtc-peer-connection/sdp-negotiation.js";import{installDataChannelMethods as T}from"./rtc-peer-connection/data-channel.js";import{installTransceiverMethods as E}from"./rtc-peer-connection/transceivers.js";import{installTrackMethods as D}from"./rtc-peer-connection/tracks.js";import{installStatsAndConfigMethods as O}from"./rtc-peer-connection/stats-and-config.js";import k from"gi://GLib?version=2.0";import{DOMException as A}from"@gjsify/dom-exception";import j from"gi://GstWebRTC?version=1.0";import{WebrtcbinBridge as M}from"@gjsify/webrtc-native";import N from"gi://GObject?version=2.0";let P=0;var RTCPeerConnection=class extends EventTarget{_pipeline;_webrtcbin;_bridge;_conf;_closed=!1;_iceRestartNeeded=!1;_hasNegotiated=!1;_dataChannels=new Map;_transceivers=new Map;_senders=[];_receivers=[];_iceTransport=null;_dtlsTransport=null;_sctpTransport=null;canTrickleIceCandidates=!0;constructor(n){super(),t();let[r,i]=e.version();if(r<1||r===1&&i<20)throw new A(`@gjsify/webrtc requires GStreamer >= 1.20 (you have ${r}.${i}). webrtcbin is only stable from 1.20 onward.`,`NotSupportedError`);let a=++P;this._pipeline=new e.Pipeline({name:`gjsify-webrtc-pipeline-${a}`});let o=e.ElementFactory.make(`webrtcbin`,`gjsify-webrtcbin-${a}`);if(!o)throw Error(`Failed to create webrtcbin element`);if(this._webrtcbin=o,this._conf={...n},n?.certificates){for(let e of n.certificates)if(e instanceof S&&e.expires<=Date.now())throw new A(`RTCPeerConnection: one of the provided certificates has expired`,`InvalidAccessError`)}this._applyIceServers(n?.iceServers??[]),this._applyIceTransportPolicy(n?.iceTransportPolicy),this._applyBundlePolicy(n?.bundlePolicy),this._pipeline.add(this._webrtcbin),this._bridge=new M({bin:this._webrtcbin}),this._bridge.connect(`negotiation-needed`,()=>this._handleNegotiationNeeded()),this._bridge.connect(`icecandidate`,(e,t,n)=>this._handleIceCandidate(t,n)),this._bridge.connect(`datachannel`,(e,t)=>this._handleDataChannel(t)),this._bridge.connect(`new-transceiver`,(e,t)=>this._handleNewTransceiver(t)),this._bridge.connect(`pad-added`,(e,t)=>this._handlePadAdded(t)),this._bridge.connect(`connection-state-changed`,()=>this._dispatchStateChange(`connectionstatechange`)),this._bridge.connect(`ice-connection-state-changed`,()=>this._dispatchStateChange(`iceconnectionstatechange`)),this._bridge.connect(`ice-gathering-state-changed`,()=>this._dispatchStateChange(`icegatheringstatechange`)),this._bridge.connect(`signaling-state-changed`,()=>this._dispatchStateChange(`signalingstatechange`)),this._pipeline.set_state(e.State.PLAYING)}_applyIceServers(e){let t=!1;for(let n of e){let e=Array.isArray(n.urls)?n.urls:[n.urls];if(e.length===0)throw SyntaxError(`RTCIceServer.urls must not be empty`);for(let r of e){if(typeof r!=`string`||r.length===0)throw TypeError(`RTCIceServer.urls entries must be non-empty strings`);let e=r.indexOf(`:`);if(e<0)throw TypeError(`Invalid ICE server URL "${r}"`);let i=r.slice(0,e+1),a=r.slice(e+1);if(i===`stun:`||i===`stuns:`){if(t)continue;s(this._webrtcbin).stun_server=`${i}//${a}`,t=!0}else if(i===`turn:`||i===`turns:`){if(typeof n.username!=`string`||typeof n.credential!=`string`)throw TypeError(`TURN server credential for ${r} missing`);let e=`${i}//${encodeURIComponent(n.username)}:${encodeURIComponent(n.credential)}@${a}`;try{l(this._webrtcbin,`add-turn-server`,e)}catch{s(this._webrtcbin).turn_server=e}}else throw TypeError(`Unsupported ICE server protocol "${i}"`)}}}_applyIceTransportPolicy(e){if(!e)return;let t=e===`relay`?j.WebRTCICETransportPolicy.RELAY:j.WebRTCICETransportPolicy.ALL;try{s(this._webrtcbin).ice_transport_policy=t}catch{}}_applyBundlePolicy(e){if(!e)return;let t;switch(e){case`balanced`:t=j.WebRTCBundlePolicy.BALANCED;break;case`max-compat`:t=j.WebRTCBundlePolicy.MAX_COMPAT;break;case`max-bundle`:t=j.WebRTCBundlePolicy.MAX_BUNDLE;break;default:return}try{s(this._webrtcbin).bundle_policy=t}catch{}}get signalingState(){if(this._closed)return`closed`;try{return o(s(this._webrtcbin).signaling_state)}catch{return`stable`}}get connectionState(){if(this._closed)return`closed`;try{return r(s(this._webrtcbin).connection_state)}catch{return`new`}}get iceConnectionState(){if(this._closed)return`closed`;try{return i(s(this._webrtcbin).ice_connection_state)}catch{return`new`}}get iceGatheringState(){try{return a(s(this._webrtcbin).ice_gathering_state)}catch{return`new`}}_descProp(e){try{let t=s(this._webrtcbin)[e];return t?u.fromGstDesc(t):null}catch{return null}}get localDescription(){return this._descProp(`local_description`)}get remoteDescription(){return this._descProp(`remote_description`)}get currentLocalDescription(){return this._descProp(`current_local_description`)}get currentRemoteDescription(){return this._descProp(`current_remote_description`)}get pendingLocalDescription(){return this._descProp(`pending_local_description`)}get pendingRemoteDescription(){return this._descProp(`pending_remote_description`)}get sctp(){return this._sctpTransport}get peerIdentity(){return Promise.reject(TypeError(`peerIdentity assertions are not implemented`))}get idpErrorInfo(){return null}get idpLoginUrl(){return null}_rejectIfClosed(e){if(this._closed)throw new A(`RTCPeerConnection.${e}: connection is closed`,`InvalidStateError`)}_setStructureField(e,t,n,r){if(r==null)return;let i=new N.Value;n===`boolean`?(i.init(N.TYPE_BOOLEAN),i.set_boolean(!!r)):n===`int`?(i.init(N.TYPE_INT),i.set_int(Number(r))):n===`string`&&(i.init(N.TYPE_STRING),i.set_string(String(r))),e.set_value(t,i),i.unset()}close(){this._closed||(this._closed=!0,k.idle_add(k.PRIORITY_DEFAULT,()=>{try{this._pipeline.set_state(e.State.NULL)}catch{}for(let e of this._dataChannels.values())try{e._disconnectSignals()}catch{}this._dataChannels.clear();for(let e of this._senders)try{e._teardownPipeline()}catch{}for(let e of this._receivers)try{e._dispose()}catch{}this._transceivers.clear(),this._senders.length=0,this._receivers.length=0,this._dtlsTransport&&this._dtlsTransport._setState(`closed`),this._iceTransport&&this._iceTransport._setState(`closed`),this._sctpTransport&&this._sctpTransport._setState(`closed`);try{this._bridge.dispose_bridge()}catch{}return k.SOURCE_REMOVE}))}getIdentityAssertion(){return Promise.reject(Error(`getIdentityAssertion is not implemented`))}_findNewGstTransceiver(){for(let e=0;;e++){let t=l(this._webrtcbin,`get-transceiver`,e);if(!t)return null;if(!this._transceivers.has(t))return t}}_ensureTransports(){return this._dtlsTransport||=(this._iceTransport=new y,new b(this._iceTransport)),this._dtlsTransport}_ensureSctpTransport(){if(this._sctpTransport)return;let e=this._ensureTransports();this._sctpTransport=new x(e)}_assignTransports(){let e=this._ensureTransports();for(let t of this._senders)t._transport=e;for(let t of this._receivers)t._transport=e}_clearTransports(){for(let e of this._senders)e._transport=null;for(let e of this._receivers)e._transport=null}_createTransceiverWrapper(e){let t=`audio`;try{e.kind===j.WebRTCKind.VIDEO&&(t=`video`)}catch{}let n=e.receiver??null,r=e.sender??null,i=new g(t,n,this._pipeline),a=new h(r,this._pipeline,this._webrtcbin);a._kind=t,a._onPipelineChanged=e=>{this._pipeline=e};let statsDelegate=e=>this.getStats(e);if(a._getStatsForTrack=statsDelegate,i._getStatsForTrack=statsDelegate,this.localDescription){let e=this._ensureTransports();a._transport=e,i._transport=e}try{let t=e.mlineindex;typeof t==`number`&&t>=0&&a._setMlineIndex(t)}catch{}let o=new _(e,a,i);return a._transceiver=o,this._transceivers.set(e,o),this._senders.push(a),this._receivers.push(i),o}_handleNegotiationNeeded(){if(this._closed)return;let e=new Event(`negotiationneeded`);this._onnegotiationneeded?.call(this,e),this.dispatchEvent(e)}_negotiationNeededQueued=!1;_updateNegotiationNeeded(){this._closed||this._hasNegotiated&&this.signalingState===`stable`&&(this._negotiationNeededQueued||(this._negotiationNeededQueued=!0,Promise.resolve().then(()=>{this._negotiationNeededQueued=!1,this.signalingState===`stable`&&this._handleNegotiationNeeded()})))}_handleIceCandidate(e,t){let n=new p(`icecandidate`,{candidate:new d({candidate:t,sdpMLineIndex:e})});this._onicecandidate?.call(this,n),this.dispatchEvent(n)}_handleNewTransceiver(e){this._closed||this._transceivers.has(e)||this._createTransceiverWrapper(e)}_handlePadAdded(t){if(this._closed||t.direction!==e.PadDirection.SRC)return;let r=c(t).transceiver;if(!r)return;let i=this._transceivers.get(r);i||=this._createTransceiverWrapper(r),i.receiver._connectToPad(t);let a=new n([i.receiver.track]),o=new v(`track`,{receiver:i.receiver,track:i.receiver.track,streams:[a],transceiver:i});this._ontrack?.call(this,o),this.dispatchEvent(o)}_handleDataChannel(e){this._ensureSctpTransport();let t=e.channel,n=this._dataChannels.get(t);n||(n=new m(e,this._sctpTransport??void 0),this._dataChannels.set(t,n),n.addEventListener(`close`,()=>{this._dataChannels.delete(t)}));let r=new f(`datachannel`,{channel:n});this._ondatachannel?.call(this,r),this.dispatchEvent(r)}_dispatchStateChange(e){e===`connectionstatechange`?this._syncDtlsState():e===`iceconnectionstatechange`?this._syncIceState():e===`icegatheringstatechange`&&this._syncIceGatheringState();let t=new Event(e);switch(e){case`connectionstatechange`:this._onconnectionstatechange?.call(this,t);break;case`iceconnectionstatechange`:this._oniceconnectionstatechange?.call(this,t);break;case`icegatheringstatechange`:this._onicegatheringstatechange?.call(this,t);break;case`signalingstatechange`:this._onsignalingstatechange?.call(this,t);break}this.dispatchEvent(t)}_syncDtlsState(){if(!this._dtlsTransport)return;let e=this.connectionState;this._dtlsTransport._setState({new:`new`,connecting:`connecting`,connected:`connected`,disconnected:`connected`,failed:`failed`,closed:`closed`}[e]??`new`),e===`connected`&&this._sctpTransport&&this._sctpTransport._setState(`connected`)}_syncIceState(){if(!this._iceTransport)return;let e=this.iceConnectionState;this._iceTransport._setState(e)}_syncIceGatheringState(){if(!this._iceTransport)return;let e=this.iceGatheringState;this._iceTransport._setGatheringState(e)}_onconnectionstatechange=null;_ondatachannel=null;_onicecandidate=null;_oniceconnectionstatechange=null;_onicegatheringstatechange=null;_onnegotiationneeded=null;_onsignalingstatechange=null;get onconnectionstatechange(){return this._onconnectionstatechange}set onconnectionstatechange(e){this._onconnectionstatechange=e}get ondatachannel(){return this._ondatachannel}set ondatachannel(e){this._ondatachannel=e}get onicecandidate(){return this._onicecandidate}set onicecandidate(e){this._onicecandidate=e}get oniceconnectionstatechange(){return this._oniceconnectionstatechange}set oniceconnectionstatechange(e){this._oniceconnectionstatechange=e}get onicegatheringstatechange(){return this._onicegatheringstatechange}set onicegatheringstatechange(e){this._onicegatheringstatechange=e}get onnegotiationneeded(){return this._onnegotiationneeded}set onnegotiationneeded(e){this._onnegotiationneeded=e}get onsignalingstatechange(){return this._onsignalingstatechange}set onsignalingstatechange(e){this._onsignalingstatechange=e}_ontrack=null;get ontrack(){return this._ontrack}set ontrack(e){this._ontrack=e}get onicecandidateerror(){return null}set onicecandidateerror(e){}static generateCertificate(e){return C(e)}};w(RTCPeerConnection.prototype),T(RTCPeerConnection.prototype),E(RTCPeerConnection.prototype),D(RTCPeerConnection.prototype),O(RTCPeerConnection.prototype);export{RTCPeerConnection};
@@ -1,4 +1,6 @@
1
1
  import Gst from 'gi://Gst?version=1.0';
2
+ /** TEST SEAM (exported) — see the `keepOpenal` parameter doc above. */
3
+ export declare function excludeUnboundedAutodetectCandidates(keepOpenal?: boolean): void;
2
4
  export declare function ensureGstInit(): void;
3
5
  /** Throws if the `webrtcbin` element is not registered (gst-plugins-bad missing). */
4
6
  export declare function ensureWebrtcbinAvailable(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/webrtc",
3
- "version": "0.51.0",
3
+ "version": "0.52.0",
4
4
  "description": "W3C WebRTC API for GJS using GStreamer webrtcbin as the peer-connection backend",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -61,21 +61,22 @@
61
61
  "peer-connection"
62
62
  ],
63
63
  "dependencies": {
64
- "@gjsify/buffer": "^0.51.0",
65
- "@gjsify/dom-events": "^0.51.0",
66
- "@gjsify/dom-exception": "^0.51.0",
67
- "@gjsify/webcrypto": "^0.51.0",
68
- "@gjsify/webrtc-native": "^0.51.0"
64
+ "@gjsify/buffer": "^0.52.0",
65
+ "@gjsify/dom-events": "^0.52.0",
66
+ "@gjsify/dom-exception": "^0.52.0",
67
+ "@gjsify/webcrypto": "^0.52.0",
68
+ "@gjsify/webrtc-native": "^0.52.0"
69
69
  },
70
70
  "devDependencies": {
71
- "@girs/gjs": "5.0.0",
72
- "@girs/glib-2.0": "5.0.0",
73
- "@girs/gobject-2.0": "5.0.0",
74
- "@girs/gst-1.0": "5.0.0",
75
- "@girs/gstsdp-1.0": "5.0.0",
76
- "@girs/gstwebrtc-1.0": "5.0.0",
77
- "@gjsify/cli": "^0.51.0",
78
- "@gjsify/unit": "^0.51.0",
71
+ "@girs/gjs": "5.4.0",
72
+ "@girs/glib-2.0": "5.4.0",
73
+ "@girs/gobject-2.0": "5.4.0",
74
+ "@girs/gst-1.0": "5.4.0",
75
+ "@girs/gstsdp-1.0": "5.4.0",
76
+ "@girs/gstwebrtc-1.0": "5.4.0",
77
+ "@gjsify/child_process": "^0.52.0",
78
+ "@gjsify/cli": "^0.52.0",
79
+ "@gjsify/unit": "^0.52.0",
79
80
  "@types/node": "^25.9.2",
80
81
  "typescript": "^6.0.3"
81
82
  },