1 module libwasm.bindings.RTCPeerConnection;
2 
3 import libwasm.types;
4 
5 import memutils.ct: tuple;
6 import libwasm.bindings.DOMException;
7 import libwasm.bindings.EventHandler;
8 import libwasm.bindings.EventTarget;
9 import libwasm.bindings.Function;
10 import libwasm.bindings.MediaStream;
11 import libwasm.bindings.MediaStreamTrack;
12 import libwasm.bindings.Performance;
13 import libwasm.bindings.RTCCertificate;
14 import libwasm.bindings.RTCConfiguration;
15 import libwasm.bindings.RTCDataChannel;
16 import libwasm.bindings.RTCIceCandidate;
17 import libwasm.bindings.RTCIdentityAssertion;
18 import libwasm.bindings.RTCIdentityProvider;
19 import libwasm.bindings.RTCRtpReceiver;
20 import libwasm.bindings.RTCRtpSender;
21 import libwasm.bindings.RTCRtpTransceiver;
22 import libwasm.bindings.RTCSessionDescription;
23 import libwasm.bindings.RTCStatsReport;
24 import libwasm.bindings.SubtleCrypto;
25 
26 @safe:
27 nothrow:
28 
29 struct RTCAnswerOptions {
30   nothrow:
31   libwasm.bindings.RTCPeerConnection.RTCOfferAnswerOptions _parent;
32   alias _parent this;
33   this(Handle h) {
34     _parent = .RTCOfferAnswerOptions(h);
35   }
36   static auto create() {
37     return RTCAnswerOptions(libwasm_add__object());
38   }
39 }
40 struct RTCDataChannelInit {
41   nothrow:
42   JsHandle handle;
43   alias handle this;
44   this(Handle h) {
45     this.handle = JsHandle(h);
46   }
47   static auto create() {
48     return RTCDataChannelInit(libwasm_add__object());
49   }
50   void ordered()(bool ordered) {
51     Object_Call_bool__void(this.handle, "ordered", ordered);
52   }
53   bool ordered()() {
54     return Object_Getter__bool(this.handle, "ordered");
55   }
56   void maxPacketLifeTime()(ushort maxPacketLifeTime) {
57     Serialize_Object_VarArgCall!void(this.handle, "maxPacketLifeTime", "ushort", tuple(maxPacketLifeTime));
58   }
59   ushort maxPacketLifeTime()() {
60     return Object_Getter__ushort(this.handle, "maxPacketLifeTime");
61   }
62   void maxRetransmits()(ushort maxRetransmits) {
63     Serialize_Object_VarArgCall!void(this.handle, "maxRetransmits", "ushort", tuple(maxRetransmits));
64   }
65   ushort maxRetransmits()() {
66     return Object_Getter__ushort(this.handle, "maxRetransmits");
67   }
68   void protocol()(string protocol) {
69     Object_Call_string__void(this.handle, "protocol", protocol);
70   }
71   string protocol()() {
72     return Object_Getter__string(this.handle, "protocol");
73   }
74   void negotiated()(bool negotiated) {
75     Object_Call_bool__void(this.handle, "negotiated", negotiated);
76   }
77   bool negotiated()() {
78     return Object_Getter__bool(this.handle, "negotiated");
79   }
80   void id()(ushort id) {
81     Serialize_Object_VarArgCall!void(this.handle, "id", "ushort", tuple(id));
82   }
83   ushort id()() {
84     return Object_Getter__ushort(this.handle, "id");
85   }
86   void maxRetransmitTime()(ushort maxRetransmitTime) {
87     Serialize_Object_VarArgCall!void(this.handle, "maxRetransmitTime", "ushort", tuple(maxRetransmitTime));
88   }
89   ushort maxRetransmitTime()() {
90     return Object_Getter__ushort(this.handle, "maxRetransmitTime");
91   }
92 }
93 enum RTCIceConnectionState {
94   new_,
95   checking,
96   connected,
97   completed,
98   failed,
99   disconnected,
100   closed
101 }
102 enum RTCIceGatheringState {
103   new_,
104   gathering,
105   complete
106 }
107 struct RTCOfferAnswerOptions {
108   nothrow:
109   JsHandle handle;
110   alias handle this;
111   this(Handle h) {
112     this.handle = JsHandle(h);
113   }
114   static auto create() {
115     return RTCOfferAnswerOptions(libwasm_add__object());
116   }
117 }
118 struct RTCOfferOptions {
119   nothrow:
120   libwasm.bindings.RTCPeerConnection.RTCOfferAnswerOptions _parent;
121   alias _parent this;
122   this(Handle h) {
123     _parent = .RTCOfferAnswerOptions(h);
124   }
125   static auto create() {
126     return RTCOfferOptions(libwasm_add__object());
127   }
128   void offerToReceiveVideo()(bool offerToReceiveVideo) {
129     Object_Call_bool__void(this._parent, "offerToReceiveVideo", offerToReceiveVideo);
130   }
131   bool offerToReceiveVideo()() {
132     return Object_Getter__bool(this._parent, "offerToReceiveVideo");
133   }
134   void offerToReceiveAudio()(bool offerToReceiveAudio) {
135     Object_Call_bool__void(this._parent, "offerToReceiveAudio", offerToReceiveAudio);
136   }
137   bool offerToReceiveAudio()() {
138     return Object_Getter__bool(this._parent, "offerToReceiveAudio");
139   }
140   void iceRestart()(bool iceRestart) {
141     Object_Call_bool__void(this._parent, "iceRestart", iceRestart);
142   }
143   bool iceRestart()() {
144     return Object_Getter__bool(this._parent, "iceRestart");
145   }
146 }
147 struct RTCPeerConnection {
148   nothrow:
149   libwasm.bindings.EventTarget.EventTarget _parent;
150   alias _parent this;
151   this(Handle h) {
152     _parent = .EventTarget(h);
153   }
154   auto generateCertificate()(scope ref AlgorithmIdentifier keygenAlgorithm) {
155     return JsPromise!(RTCCertificate)(Serialize_Object_VarArgCall!Handle(this._parent, "generateCertificate", "SumType!(Handle,string)", tuple(libwasm.sumtype.match!(((ref keygenAlgorithm.Types[0] v) => 0),((string v) => 1))(keygenAlgorithm),tuple(libwasm.sumtype.match!(((ref keygenAlgorithm.Types[0] v) => cast(Handle)v.handle),((string v) => Handle.init))(keygenAlgorithm),libwasm.sumtype.match!(((ref keygenAlgorithm.Types[0] v) => string.init),((string v) => v))(keygenAlgorithm)))));
156   }
157   void setIdentityProvider()(string provider, scope ref RTCIdentityProviderOptions options) {
158     Serialize_Object_VarArgCall!void(this._parent, "setIdentityProvider", "string;Handle", tuple(provider, cast(Handle)options.handle));
159   }
160   void setIdentityProvider()(string provider) {
161     Object_Call_string__void(this._parent, "setIdentityProvider", provider);
162   }
163   auto getIdentityAssertion()() {
164     return JsPromise!(string)(Object_Getter__Handle(this._parent, "getIdentityAssertion"));
165   }
166   auto createOffer()(scope ref RTCOfferOptions options) {
167     return JsPromise!(RTCSessionDescriptionInit)(Object_Call_Handle__Handle(this._parent, "createOffer", options._parent));
168   }
169   auto createOffer()() {
170     return JsPromise!(RTCSessionDescriptionInit)(Object_Getter__Handle(this._parent, "createOffer"));
171   }
172   auto createAnswer()(scope ref RTCAnswerOptions options) {
173     return JsPromise!(RTCSessionDescriptionInit)(Object_Call_Handle__Handle(this._parent, "createAnswer", options._parent));
174   }
175   auto createAnswer()() {
176     return JsPromise!(RTCSessionDescriptionInit)(Object_Getter__Handle(this._parent, "createAnswer"));
177   }
178   auto setLocalDescription()(scope ref RTCSessionDescriptionInit description) {
179     return JsPromise!(void)(Object_Call_Handle__Handle(this._parent, "setLocalDescription", description.handle));
180   }
181   auto setRemoteDescription()(scope ref RTCSessionDescriptionInit description) {
182     return JsPromise!(void)(Object_Call_Handle__Handle(this._parent, "setRemoteDescription", description.handle));
183   }
184   auto localDescription()() {
185     return recastOpt!(RTCSessionDescription)(Object_Getter__OptionalHandle(this._parent, "localDescription"));
186   }
187   auto currentLocalDescription()() {
188     return recastOpt!(RTCSessionDescription)(Object_Getter__OptionalHandle(this._parent, "currentLocalDescription"));
189   }
190   auto pendingLocalDescription()() {
191     return recastOpt!(RTCSessionDescription)(Object_Getter__OptionalHandle(this._parent, "pendingLocalDescription"));
192   }
193   auto remoteDescription()() {
194     return recastOpt!(RTCSessionDescription)(Object_Getter__OptionalHandle(this._parent, "remoteDescription"));
195   }
196   auto currentRemoteDescription()() {
197     return recastOpt!(RTCSessionDescription)(Object_Getter__OptionalHandle(this._parent, "currentRemoteDescription"));
198   }
199   auto pendingRemoteDescription()() {
200     return recastOpt!(RTCSessionDescription)(Object_Getter__OptionalHandle(this._parent, "pendingRemoteDescription"));
201   }
202   RTCSignalingState signalingState()() {
203     return Object_Getter__int(this._parent, "signalingState");
204   }
205   auto addIceCandidate(T0)(scope auto ref Optional!(T0) candidate) if (isTOrPointer!(T0, SumType!(RTCIceCandidateInit, RTCIceCandidate))) {
206     return JsPromise!(void)(Serialize_Object_VarArgCall!Handle(this._parent, "addIceCandidate", "Optional!SumType!(Handle,Handle)", tuple(!candidate.empty, libwasm.sumtype.match!(((ref candidate.Types[0] v) => 0),((ref candidate.Types[1] v) => 1))(candidate),tuple(libwasm.sumtype.match!(((ref candidate.Types[0] v) => cast(Handle)v.handle),((ref candidate.Types[1] v) => Handle.init))(candidate),libwasm.sumtype.match!(((ref candidate.Types[0] v) => Handle.init),((ref candidate.Types[1] v) => cast(Handle)v.handle))(candidate)))));
207   }
208   Optional!(bool) canTrickleIceCandidates()() {
209     return Object_Getter__OptionalBool(this._parent, "canTrickleIceCandidates");
210   }
211   RTCIceGatheringState iceGatheringState()() {
212     return Object_Getter__int(this._parent, "iceGatheringState");
213   }
214   RTCIceConnectionState iceConnectionState()() {
215     return Object_Getter__int(this._parent, "iceConnectionState");
216   }
217   auto peerIdentity()() {
218     return JsPromise!(RTCIdentityAssertion)(Object_Getter__Handle(this._parent, "peerIdentity"));
219   }
220   Optional!(string) idpLoginUrl()() {
221     return Object_Getter__OptionalString(this._parent, "idpLoginUrl");
222   }
223   void id()(string id) {
224     Object_Call_string__void(this._parent, "id", id);
225   }
226   string id()() {
227     return Object_Getter__string(this._parent, "id");
228   }
229   auto getConfiguration()() {
230     return RTCConfiguration(Object_Getter__Handle(this._parent, "getConfiguration"));
231   }
232   auto getLocalStreams()() {
233     return Sequence!(MediaStream)(Object_Getter__Handle(this._parent, "getLocalStreams"));
234   }
235   auto getRemoteStreams()() {
236     return Sequence!(MediaStream)(Object_Getter__Handle(this._parent, "getRemoteStreams"));
237   }
238   void addStream()(scope ref MediaStream stream) {
239     Object_Call_Handle__void(this._parent, "addStream", stream._parent);
240   }
241   auto addTrack()(scope ref MediaStreamTrack track, scope ref MediaStream streams) {
242     return RTCRtpSender(Serialize_Object_VarArgCall!Handle(this._parent, "addTrack", "Handle;Handle", tuple(cast(Handle)track._parent, cast(Handle)streams._parent)));
243   }
244   void removeTrack()(scope ref RTCRtpSender sender) {
245     Object_Call_Handle__void(this._parent, "removeTrack", sender.handle);
246   }
247   auto addTransceiver()(scope ref SumType!(MediaStreamTrack, string) trackOrKind, scope ref RTCRtpTransceiverInit init) {
248     return RTCRtpTransceiver(Serialize_Object_VarArgCall!Handle(this._parent, "addTransceiver", "SumType!(Handle,string);Handle", tuple(libwasm.sumtype.match!(((ref trackOrKind.Types[0] v) => 0),((string v) => 1))(trackOrKind),tuple(libwasm.sumtype.match!(((ref trackOrKind.Types[0] v) => cast(Handle)v.handle),((string v) => Handle.init))(trackOrKind),libwasm.sumtype.match!(((ref trackOrKind.Types[0] v) => string.init),((string v) => v))(trackOrKind)), cast(Handle)init.handle)));
249   }
250   auto addTransceiver()(scope ref SumType!(MediaStreamTrack, string) trackOrKind) {
251     return RTCRtpTransceiver(Serialize_Object_VarArgCall!Handle(this._parent, "addTransceiver", "SumType!(Handle,string)", tuple(libwasm.sumtype.match!(((ref trackOrKind.Types[0] v) => 0),((string v) => 1))(trackOrKind),tuple(libwasm.sumtype.match!(((ref trackOrKind.Types[0] v) => cast(Handle)v.handle),((string v) => Handle.init))(trackOrKind),libwasm.sumtype.match!(((ref trackOrKind.Types[0] v) => string.init),((string v) => v))(trackOrKind)))));
252   }
253   auto getSenders()() {
254     return Sequence!(RTCRtpSender)(Object_Getter__Handle(this._parent, "getSenders"));
255   }
256   auto getReceivers()() {
257     return Sequence!(RTCRtpReceiver)(Object_Getter__Handle(this._parent, "getReceivers"));
258   }
259   auto getTransceivers()() {
260     return Sequence!(RTCRtpTransceiver)(Object_Getter__Handle(this._parent, "getTransceivers"));
261   }
262   double mozGetNowInRtpSourceReferenceTime()() {
263     return Object_Getter__double(this._parent, "mozGetNowInRtpSourceReferenceTime");
264   }
265   void mozInsertAudioLevelForContributingSource()(scope ref RTCRtpReceiver receiver, uint source, double timestamp, bool hasLevel, byte level) {
266     Serialize_Object_VarArgCall!void(this._parent, "mozInsertAudioLevelForContributingSource", "Handle;uint;double;bool;byte", tuple(cast(Handle)receiver.handle, source, timestamp, hasLevel, level));
267   }
268   void mozAddRIDExtension()(scope ref RTCRtpReceiver receiver, ushort extensionId) {
269     Serialize_Object_VarArgCall!void(this._parent, "mozAddRIDExtension", "Handle;ushort", tuple(cast(Handle)receiver.handle, extensionId));
270   }
271   void mozAddRIDFilter()(scope ref RTCRtpReceiver receiver, string rid) {
272     Serialize_Object_VarArgCall!void(this._parent, "mozAddRIDFilter", "Handle;string", tuple(cast(Handle)receiver.handle, rid));
273   }
274   void mozSetPacketCallback()(mozPacketCallback callback) {
275     RTCPeerConnection_mozSetPacketCallback(this._parent, callback);
276   }
277   void mozEnablePacketDump()(uint level, mozPacketDumpType type, bool sending) {
278     Serialize_Object_VarArgCall!void(this._parent, "mozEnablePacketDump", "uint;Enum;bool", tuple(level, type, sending));
279   }
280   void mozDisablePacketDump()(uint level, mozPacketDumpType type, bool sending) {
281     Serialize_Object_VarArgCall!void(this._parent, "mozDisablePacketDump", "uint;Enum;bool", tuple(level, type, sending));
282   }
283   void close()() {
284     Object_Call__void(this._parent, "close");
285   }
286   void onnegotiationneeded(T0)(scope auto ref Optional!(T0) onnegotiationneeded) if (isTOrPointer!(T0, EventHandlerNonNull)) {
287     Object_Call_EventHandler__void(this._parent, "onnegotiationneeded", !onnegotiationneeded.empty, onnegotiationneeded.front);
288   }
289   EventHandler onnegotiationneeded()() {
290     return Object_Getter__EventHandler(this._parent, "onnegotiationneeded");
291   }
292   void onicecandidate(T0)(scope auto ref Optional!(T0) onicecandidate) if (isTOrPointer!(T0, EventHandlerNonNull)) {
293     Object_Call_EventHandler__void(this._parent, "onicecandidate", !onicecandidate.empty, onicecandidate.front);
294   }
295   EventHandler onicecandidate()() {
296     return Object_Getter__EventHandler(this._parent, "onicecandidate");
297   }
298   void onsignalingstatechange(T0)(scope auto ref Optional!(T0) onsignalingstatechange) if (isTOrPointer!(T0, EventHandlerNonNull)) {
299     Object_Call_EventHandler__void(this._parent, "onsignalingstatechange", !onsignalingstatechange.empty, onsignalingstatechange.front);
300   }
301   EventHandler onsignalingstatechange()() {
302     return Object_Getter__EventHandler(this._parent, "onsignalingstatechange");
303   }
304   void onaddstream(T0)(scope auto ref Optional!(T0) onaddstream) if (isTOrPointer!(T0, EventHandlerNonNull)) {
305     Object_Call_EventHandler__void(this._parent, "onaddstream", !onaddstream.empty, onaddstream.front);
306   }
307   EventHandler onaddstream()() {
308     return Object_Getter__EventHandler(this._parent, "onaddstream");
309   }
310   void onaddtrack(T0)(scope auto ref Optional!(T0) onaddtrack) if (isTOrPointer!(T0, EventHandlerNonNull)) {
311     Object_Call_EventHandler__void(this._parent, "onaddtrack", !onaddtrack.empty, onaddtrack.front);
312   }
313   EventHandler onaddtrack()() {
314     return Object_Getter__EventHandler(this._parent, "onaddtrack");
315   }
316   void ontrack(T0)(scope auto ref Optional!(T0) ontrack) if (isTOrPointer!(T0, EventHandlerNonNull)) {
317     Object_Call_EventHandler__void(this._parent, "ontrack", !ontrack.empty, ontrack.front);
318   }
319   EventHandler ontrack()() {
320     return Object_Getter__EventHandler(this._parent, "ontrack");
321   }
322   void onremovestream(T0)(scope auto ref Optional!(T0) onremovestream) if (isTOrPointer!(T0, EventHandlerNonNull)) {
323     Object_Call_EventHandler__void(this._parent, "onremovestream", !onremovestream.empty, onremovestream.front);
324   }
325   EventHandler onremovestream()() {
326     return Object_Getter__EventHandler(this._parent, "onremovestream");
327   }
328   void oniceconnectionstatechange(T0)(scope auto ref Optional!(T0) oniceconnectionstatechange) if (isTOrPointer!(T0, EventHandlerNonNull)) {
329     Object_Call_EventHandler__void(this._parent, "oniceconnectionstatechange", !oniceconnectionstatechange.empty, oniceconnectionstatechange.front);
330   }
331   EventHandler oniceconnectionstatechange()() {
332     return Object_Getter__EventHandler(this._parent, "oniceconnectionstatechange");
333   }
334   void onicegatheringstatechange(T0)(scope auto ref Optional!(T0) onicegatheringstatechange) if (isTOrPointer!(T0, EventHandlerNonNull)) {
335     Object_Call_EventHandler__void(this._parent, "onicegatheringstatechange", !onicegatheringstatechange.empty, onicegatheringstatechange.front);
336   }
337   EventHandler onicegatheringstatechange()() {
338     return Object_Getter__EventHandler(this._parent, "onicegatheringstatechange");
339   }
340   auto getStats(T0)(scope auto ref Optional!(T0) selector) if (isTOrPointer!(T0, MediaStreamTrack)) {
341     return JsPromise!(RTCStatsReport)(Serialize_Object_VarArgCall!Handle(this._parent, "getStats", "Optional!Handle", tuple(!selector.empty, cast(Handle)selector.front._parent)));
342   }
343   auto getStats()() {
344     return JsPromise!(RTCStatsReport)(Object_Getter__Handle(this._parent, "getStats"));
345   }
346   auto createDataChannel()(string label, scope ref RTCDataChannelInit dataChannelDict) {
347     return RTCDataChannel(Serialize_Object_VarArgCall!Handle(this._parent, "createDataChannel", "string;Handle", tuple(label, cast(Handle)dataChannelDict.handle)));
348   }
349   auto createDataChannel()(string label) {
350     return RTCDataChannel(Object_Call_string__Handle(this._parent, "createDataChannel", label));
351   }
352   void ondatachannel(T0)(scope auto ref Optional!(T0) ondatachannel) if (isTOrPointer!(T0, EventHandlerNonNull)) {
353     Object_Call_EventHandler__void(this._parent, "ondatachannel", !ondatachannel.empty, ondatachannel.front);
354   }
355   EventHandler ondatachannel()() {
356     return Object_Getter__EventHandler(this._parent, "ondatachannel");
357   }
358   auto createOffer()(RTCSessionDescriptionCallback successCallback, RTCPeerConnectionErrorCallback failureCallback, scope ref RTCOfferOptions options) {
359     return JsPromise!(void)(RTCPeerConnection_createOffer__Handle_Handle_Handle(this._parent, successCallback, failureCallback, options._parent));
360   }
361   auto createOffer()(RTCSessionDescriptionCallback successCallback, RTCPeerConnectionErrorCallback failureCallback) {
362     return JsPromise!(void)(RTCPeerConnection_createOffer_0_Handle_Handle(this._parent, successCallback, failureCallback));
363   }
364   auto createAnswer()(RTCSessionDescriptionCallback successCallback, RTCPeerConnectionErrorCallback failureCallback) {
365     return JsPromise!(void)(RTCPeerConnection_createAnswer__Handle_Handle(this._parent, successCallback, failureCallback));
366   }
367   auto setLocalDescription()(scope ref RTCSessionDescriptionInit description, VoidFunction successCallback, RTCPeerConnectionErrorCallback failureCallback) {
368     return JsPromise!(void)(RTCPeerConnection_setLocalDescription__Handle_Handle_Handle(this._parent, description.handle, successCallback, failureCallback));
369   }
370   auto setRemoteDescription()(scope ref RTCSessionDescriptionInit description, VoidFunction successCallback, RTCPeerConnectionErrorCallback failureCallback) {
371     return JsPromise!(void)(RTCPeerConnection_setRemoteDescription__Handle_Handle_Handle(this._parent, description.handle, successCallback, failureCallback));
372   }
373   auto addIceCandidate()(scope ref RTCIceCandidate candidate, VoidFunction successCallback, RTCPeerConnectionErrorCallback failureCallback) {
374     return JsPromise!(void)(RTCPeerConnection_addIceCandidate__Handle_Handle_Handle(this._parent, candidate.handle, successCallback, failureCallback));
375   }
376 }
377 alias RTCPeerConnectionErrorCallback = void delegate(DOMException);
378 alias RTCSessionDescriptionCallback = void delegate(RTCSessionDescriptionInit);
379 enum RTCSignalingState {
380   stable,
381   have_local_offer,
382   have_remote_offer,
383   have_local_pranswer,
384   have_remote_pranswer,
385   closed
386 }
387 alias RTCStatsCallback = void delegate(RTCStatsReport);
388 alias mozPacketCallback = void delegate(uint, mozPacketDumpType, bool, ArrayBuffer);
389 enum mozPacketDumpType {
390   rtp,
391   srtp,
392   rtcp,
393   srtcp
394 }
395 
396 
397 extern (C) void RTCPeerConnection_mozSetPacketCallback(Handle, mozPacketCallback);
398 extern (C) Handle RTCPeerConnection_createOffer__Handle_Handle_Handle(Handle, RTCSessionDescriptionCallback, RTCPeerConnectionErrorCallback, Handle);
399 extern (C) Handle RTCPeerConnection_createOffer_0_Handle_Handle(Handle, RTCSessionDescriptionCallback, RTCPeerConnectionErrorCallback);
400 extern (C) Handle RTCPeerConnection_createAnswer__Handle_Handle(Handle, RTCSessionDescriptionCallback, RTCPeerConnectionErrorCallback);
401 extern (C) Handle RTCPeerConnection_setLocalDescription__Handle_Handle_Handle(Handle, Handle, VoidFunction, RTCPeerConnectionErrorCallback);
402 extern (C) Handle RTCPeerConnection_setRemoteDescription__Handle_Handle_Handle(Handle, Handle, VoidFunction, RTCPeerConnectionErrorCallback);
403 extern (C) Handle RTCPeerConnection_addIceCandidate__Handle_Handle_Handle(Handle, Handle, VoidFunction, RTCPeerConnectionErrorCallback);