Skip to content

Commit 7c7fe3a

Browse files
committed
add implements clauses
1 parent 3068cd4 commit 7c7fe3a

11 files changed

+72
-73
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@
103103
"node-domexception": "^2.0.1",
104104
"prebuild-install": "^7.0.1"
105105
}
106-
}
106+
}

src/polyfill/Events.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import RTCDataChannel from './RTCDataChannel';
22
import RTCIceCandidate from './RTCIceCandidate';
33

4-
interface EventInit {
5-
bubbles?: boolean;
6-
cancelable?: boolean;
7-
composed?: boolean;
8-
}
94

10-
export class RTCPeerConnectionIceEvent extends Event {
5+
export class RTCPeerConnectionIceEvent extends Event implements globalThis.RTCPeerConnectionIceEvent {
116
#candidate: RTCIceCandidate;
127

138
constructor(candidate: RTCIceCandidate) {
@@ -21,19 +16,15 @@ export class RTCPeerConnectionIceEvent extends Event {
2116
}
2217
}
2318

24-
export interface RTCDataChannelEventInit extends EventInit {
25-
channel: RTCDataChannel;
26-
}
27-
28-
export class RTCDataChannelEvent extends Event {
19+
export class RTCDataChannelEvent extends Event implements globalThis.RTCDataChannelEvent {
2920
#channel: RTCDataChannel;
3021

31-
constructor(type: string, eventInitDict: RTCDataChannelEventInit) {
22+
constructor(type: string, eventInitDict: globalThis.RTCDataChannelEventInit) {
3223
super(type);
3324

3425
if (type && !eventInitDict.channel) throw new TypeError('channel member is required');
3526

36-
this.#channel = eventInitDict?.channel;
27+
this.#channel = eventInitDict?.channel as RTCDataChannel;
3728
}
3829

3930
get channel(): RTCDataChannel {

src/polyfill/RTCCertificate.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export default class RTCCertificate {
1+
export default class RTCCertificate implements globalThis.RTCCertificate {
22
#expires: number;
3-
#fingerprints: RTCDtlsFingerprint[];
3+
#fingerprints: globalThis.RTCDtlsFingerprint[];
44

55
constructor() {
66
this.#expires = null;
@@ -11,7 +11,7 @@ export default class RTCCertificate {
1111
return this.#expires;
1212
}
1313

14-
getFingerprints(): RTCDtlsFingerprint[] {
14+
getFingerprints(): globalThis.RTCDtlsFingerprint[] {
1515
return this.#fingerprints;
1616
}
1717
}

src/polyfill/RTCDataChannel.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import 'node-domexception';
23
import * as exceptions from './Exception';
34
import { DataChannel } from '../lib/index';
45

5-
export default class RTCDataChannel extends EventTarget {
6+
export default class RTCDataChannel extends EventTarget implements globalThis.RTCDataChannel {
67
#dataChannel: DataChannel;
78
#readyState: RTCDataChannelState;
89
#bufferedAmountLowThreshold: number;
@@ -22,7 +23,7 @@ export default class RTCDataChannel extends EventTarget {
2223
onmessage: ((this: RTCDataChannel, ev: MessageEvent) => any) | null;
2324
onopen: ((this: RTCDataChannel, ev: Event) => any) | null;
2425

25-
constructor(dataChannel: DataChannel, opts: RTCDataChannelInit = {}) {
26+
constructor(dataChannel: DataChannel, opts: globalThis.RTCDataChannelInit = {}) {
2627
super();
2728

2829
this.#dataChannel = dataChannel;
@@ -55,7 +56,7 @@ export default class RTCDataChannel extends EventTarget {
5556

5657
this.#dataChannel.onError((msg) => {
5758
this.dispatchEvent(
58-
new RTCErrorEvent('error', {
59+
new globalThis.RTCErrorEvent('error', {
5960
error: new RTCError(
6061
{
6162
errorDetail: 'data-channel-failure',
@@ -155,7 +156,7 @@ export default class RTCDataChannel extends EventTarget {
155156
return this.#dataChannel.getProtocol();
156157
}
157158

158-
get readyState(): RTCDataChannelState {
159+
get readyState(): globalThis.RTCDataChannelState {
159160
return this.#readyState;
160161
}
161162

src/polyfill/RTCDtlsTransport.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import RTCIceTransport from './RTCIceTransport';
23
import RTCPeerConnection from './RTCPeerConnection';
34

4-
export default class RTCDtlsTransport extends EventTarget {
5+
export default class RTCDtlsTransport extends EventTarget implements globalThis.RTCDtlsTransport {
56
#pc: RTCPeerConnection = null;
67
#iceTransport = null;
78

src/polyfill/RTCError.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
export default class RTCError extends DOMException {
1+
export default class RTCError extends DOMException implements globalThis.RTCError {
22
#errorDetail: RTCErrorDetailType;
33
#receivedAlert: number | null;
44
#sctpCauseCode: number | null;
55
#sdpLineNumber: number | null;
66
#sentAlert: number | null;
77

8-
constructor(init: RTCErrorInit, message?: string) {
8+
constructor(init: globalThis.RTCErrorInit, message?: string) {
99
super(message, 'OperationError');
1010

1111
if (!init || !init.errorDetail) throw new TypeError('Cannot construct RTCError, errorDetail is required');
@@ -29,7 +29,7 @@ export default class RTCError extends DOMException {
2929
this.#sentAlert = init.sentAlert ?? null;
3030
}
3131

32-
get errorDetail(): RTCErrorDetailType {
32+
get errorDetail(): globalThis.RTCErrorDetailType {
3333
return this.#errorDetail;
3434
}
3535

src/polyfill/RTCIceCandidate.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44

55
import 'node-domexception';
66

7-
export default class RTCIceCandidate {
7+
export default class RTCIceCandidate implements globalThis.RTCIceCandidate {
88
#address: string | null;
99
#candidate: string;
10-
#component: RTCIceComponent | null;
10+
#component: globalThis.RTCIceComponent | null;
1111
#foundation: string | null;
1212
#port: number | null;
1313
#priority: number | null;
14-
#protocol: RTCIceProtocol | null;
14+
#protocol: globalThis.RTCIceProtocol | null;
1515
#relatedAddress: string | null;
1616
#relatedPort: number | null;
1717
#sdpMLineIndex: number | null;
1818
#sdpMid: string | null;
19-
#tcpType: RTCIceTcpCandidateType | null;
20-
#type: RTCIceCandidateType | null;
19+
#tcpType: globalThis.RTCIceTcpCandidateType | null;
20+
#type: globalThis.RTCIceCandidateType | null;
2121
#usernameFragment: string | null;
2222

23-
constructor({ candidate, sdpMLineIndex, sdpMid, usernameFragment }: RTCIceCandidateInit) {
23+
constructor({ candidate, sdpMLineIndex, sdpMid, usernameFragment }: globalThis.RTCIceCandidateInit) {
2424
if (sdpMLineIndex == null && sdpMid == null)
2525
throw new TypeError('At least one of sdpMLineIndex or sdpMid must be specified');
2626

@@ -33,11 +33,11 @@ export default class RTCIceCandidate {
3333
const fields = candidate.split(' ');
3434
this.#foundation = fields[0].replace('candidate:', ''); // remove text candidate:
3535
this.#component = fields[1] == '1' ? 'rtp' : 'rtcp';
36-
this.#protocol = fields[2] as RTCIceProtocol;
36+
this.#protocol = fields[2] as globalThis.RTCIceProtocol;
3737
this.#priority = parseInt(fields[3], 10);
3838
this.#address = fields[4];
3939
this.#port = parseInt(fields[5], 10);
40-
this.#type = fields[7] as RTCIceCandidateType;
40+
this.#type = fields[7] as globalThis.RTCIceCandidateType;
4141
this.#tcpType = null;
4242
this.#relatedAddress = null;
4343
this.#relatedPort = null;
@@ -52,7 +52,7 @@ export default class RTCIceCandidate {
5252
}
5353

5454
if (this.#protocol === 'tcp' && field === 'tcptype') {
55-
this.#tcpType = fields[i + 1] as RTCIceTcpCandidateType;
55+
this.#tcpType = fields[i + 1] as globalThis.RTCIceTcpCandidateType;
5656
}
5757
}
5858
}
@@ -66,7 +66,7 @@ export default class RTCIceCandidate {
6666
return this.#candidate;
6767
}
6868

69-
get component(): RTCIceComponent | null {
69+
get component(): globalThis.RTCIceComponent | null {
7070
return this.#component;
7171
}
7272

@@ -82,7 +82,7 @@ export default class RTCIceCandidate {
8282
return this.#priority || null;
8383
}
8484

85-
get protocol(): RTCIceProtocol | null {
85+
get protocol(): globalThis.RTCIceProtocol | null {
8686
return this.#protocol || null;
8787
}
8888

@@ -102,19 +102,19 @@ export default class RTCIceCandidate {
102102
return this.#sdpMid;
103103
}
104104

105-
get tcpType(): RTCIceTcpCandidateType | null {
105+
get tcpType(): globalThis.RTCIceTcpCandidateType | null {
106106
return this.#tcpType;
107107
}
108108

109-
get type(): RTCIceCandidateType | null {
109+
get type(): globalThis.RTCIceCandidateType | null {
110110
return this.#type || null;
111111
}
112112

113113
get usernameFragment(): string | null {
114114
return this.#usernameFragment;
115115
}
116116

117-
toJSON(): RTCIceCandidateInit {
117+
toJSON(): globalThis.RTCIceCandidateInit {
118118
return {
119119
candidate: this.#candidate,
120120
sdpMLineIndex: this.#sdpMLineIndex,

src/polyfill/RTCIceTransport.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import RTCIceCandidate from './RTCIceCandidate';
23
import RTCPeerConnection from './RTCPeerConnection';
34

4-
export default class RTCIceTransport extends EventTarget {
5+
export default class RTCIceTransport extends EventTarget implements globalThis.RTCIceTransport {
56
#pc: RTCPeerConnection = null;
67
#extraFunctions = null;
78

@@ -31,21 +32,21 @@ export default class RTCIceTransport extends EventTarget {
3132
});
3233
}
3334

34-
get component(): RTCIceComponent {
35+
get component(): globalThis.RTCIceComponent {
3536
const cp = this.getSelectedCandidatePair();
3637
if (!cp) return null;
3738
return cp.local.component;
3839
}
3940

40-
get gatheringState(): RTCIceGatheringState {
41+
get gatheringState(): globalThis.RTCIceGatheringState {
4142
return this.#pc ? this.#pc.iceGatheringState : 'new';
4243
}
4344

4445
get role(): string {
4546
return this.#pc.localDescription.type == 'offer' ? 'controlling' : 'controlled';
4647
}
4748

48-
get state(): RTCIceTransportState {
49+
get state(): globalThis.RTCIceTransportState {
4950
return this.#pc ? this.#pc.iceConnectionState : 'new';
5051
}
5152

@@ -65,7 +66,7 @@ export default class RTCIceTransport extends EventTarget {
6566
/** */
6667
}
6768

68-
getSelectedCandidatePair(): RTCIceCandidatePair | null {
69+
getSelectedCandidatePair(): globalThis.RTCIceCandidatePair | null {
6970
const cp = this.#extraFunctions.selectedCandidatePair();
7071
if (!cp) return null;
7172
return {

0 commit comments

Comments
 (0)