-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRTCDtlsTransport.ts
47 lines (38 loc) · 1.6 KB
/
RTCDtlsTransport.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* eslint-disable @typescript-eslint/no-explicit-any */
import RTCIceTransport from './RTCIceTransport';
import RTCPeerConnection from './RTCPeerConnection';
export default class RTCDtlsTransport extends EventTarget implements globalThis.RTCDtlsTransport {
#pc: RTCPeerConnection = null;
#iceTransport = null;
onstatechange: ((this: RTCDtlsTransport, ev: Event) => any) | null = null;
onerror: ((this: RTCDtlsTransport, ev: Event) => any) | null = null;
constructor(init: { pc: RTCPeerConnection, extraFunctions }) {
super();
this.#pc = init.pc;
this.#iceTransport = new RTCIceTransport({ pc: init.pc, extraFunctions: init.extraFunctions });
// forward peerConnection events
this.#pc.addEventListener('connectionstatechange', () => {
this.dispatchEvent(new Event('statechange'));
});
// forward events to properties
this.addEventListener('statechange', (e) => {
if (this.onstatechange) this.onstatechange(e);
});
}
get iceTransport(): RTCIceTransport {
return this.#iceTransport;
}
get state(): RTCDtlsTransportState {
// reduce state from new, connecting, connected, disconnected, failed, closed, unknown
// to RTCDtlsTRansport states new, connecting, connected, closed, failed
let state = this.#pc ? this.#pc.connectionState : 'new';
if (state === 'disconnected') {
state = 'closed';
}
return state;
}
getRemoteCertificates(): ArrayBuffer[] {
// TODO: implement
return [new ArrayBuffer(0)];
}
}