mockrtc 0.3.2 → 0.5.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/.github/workflows/ci.yml +5 -3
- package/README.md +2 -10
- package/dist/handling/handler-builder.js +13 -13
- package/dist/handling/handler-builder.js.map +1 -1
- package/dist/handling/handler-step-definitions.d.ts +36 -22
- package/dist/handling/handler-step-definitions.js +47 -34
- package/dist/handling/handler-step-definitions.js.map +1 -1
- package/dist/handling/handler-step-impls.d.ts +56 -0
- package/dist/handling/handler-step-impls.js +228 -0
- package/dist/handling/handler-step-impls.js.map +1 -0
- package/dist/main-browser.d.ts +2 -2
- package/dist/main-browser.js +3 -3
- package/dist/main-browser.js.map +1 -1
- package/dist/main.d.ts +3 -3
- package/dist/main.js +3 -3
- package/dist/main.js.map +1 -1
- package/dist/matching/matcher-definition-impls.d.ts +51 -0
- package/dist/matching/matcher-definition-impls.js +94 -0
- package/dist/matching/matcher-definition-impls.js.map +1 -0
- package/dist/matching/matcher-definition.d.ts +51 -0
- package/dist/matching/matcher-definition.js +94 -0
- package/dist/matching/matcher-definition.js.map +1 -0
- package/dist/matching/matcher-definitions.d.ts +14 -14
- package/dist/matching/matcher-definitions.js +22 -22
- package/dist/matching/matcher-definitions.js.map +1 -1
- package/dist/matching/matcher-impls.d.ts +27 -0
- package/dist/matching/matcher-impls.js +87 -0
- package/dist/matching/matcher-impls.js.map +1 -0
- package/dist/matching/matchers.d.ts +9 -9
- package/dist/matching/matchers.js +23 -23
- package/dist/matching/matchers.js.map +1 -1
- package/dist/rule-builder.js +7 -7
- package/dist/rule-builder.js.map +1 -1
- package/dist/server/mockrtc-admin-plugin.d.ts +1 -1
- package/dist/server/mockrtc-admin-plugin.js +7 -7
- package/dist/server/mockrtc-admin-plugin.js.map +1 -1
- package/dist/server/mockrtc-server-peer.d.ts +2 -2
- package/dist/server/mockrtc-server-peer.js.map +1 -1
- package/dist/server/mockrtc-server.js +6 -6
- package/dist/server/mockrtc-server.js.map +1 -1
- package/dist/webrtc/mockrtc-connection.d.ts +1 -1
- package/dist/webrtc/mockrtc-connection.js +1 -0
- package/dist/webrtc/mockrtc-connection.js.map +1 -1
- package/dist/webrtc/rtc-connection.d.ts +3 -3
- package/dist/webrtc/rtc-connection.js +3 -6
- package/dist/webrtc/rtc-connection.js.map +1 -1
- package/package.json +5 -6
- package/src/handling/handler-builder.ts +24 -24
- package/src/handling/handler-step-definitions.ts +38 -22
- package/src/handling/{handler-steps.ts → handler-step-impls.ts} +36 -39
- package/src/main-browser.ts +2 -2
- package/src/main.ts +3 -3
- package/src/matching/matcher-definitions.ts +14 -14
- package/src/matching/{matchers.ts → matcher-impls.ts} +22 -22
- package/src/rule-builder.ts +14 -14
- package/src/server/mockrtc-admin-plugin.ts +8 -8
- package/src/server/mockrtc-server-peer.ts +3 -3
- package/src/server/mockrtc-server.ts +8 -8
- package/src/webrtc/mockrtc-connection.ts +1 -0
- package/src/webrtc/rtc-connection.ts +9 -20
|
@@ -8,18 +8,7 @@ import { randomUUID } from 'crypto';
|
|
|
8
8
|
import { EventEmitter } from 'events';
|
|
9
9
|
import * as SDP from 'sdp-transform';
|
|
10
10
|
|
|
11
|
-
import
|
|
12
|
-
PeerConnection as NDCPeerConnection,
|
|
13
|
-
Track as NDCTrack,
|
|
14
|
-
DataChannel as NDCDataChannel,
|
|
15
|
-
Direction as NDCDirection
|
|
16
|
-
} from 'node-datachannel';
|
|
17
|
-
|
|
18
|
-
// Node-DataChannel is now an ES6 module, but we're not - work around
|
|
19
|
-
// that with a synchronous import wrapper:
|
|
20
|
-
const importSync = require('import-sync');
|
|
21
|
-
const NodeDataChannel = importSync('node-datachannel') as
|
|
22
|
-
typeof import('node-datachannel');
|
|
11
|
+
import * as NodeDataChannel from 'node-datachannel';
|
|
23
12
|
|
|
24
13
|
import type { MockRTCSessionDescription } from '../mockrtc';
|
|
25
14
|
import {
|
|
@@ -47,7 +36,7 @@ export class RTCConnection extends EventEmitter {
|
|
|
47
36
|
|
|
48
37
|
// Set to null when the connection is closed, as otherwise calling any method (including checking
|
|
49
38
|
// the connection state) will segfault the process.
|
|
50
|
-
private rawConn:
|
|
39
|
+
private rawConn: NodeDataChannel.PeerConnection | null
|
|
51
40
|
= new NodeDataChannel.PeerConnection("MockRTCConnection", { iceServers: [], forceMediaTransport: true });
|
|
52
41
|
|
|
53
42
|
private remoteDescription: RTCSessionDescriptionInit & ParsedSDP | undefined;
|
|
@@ -105,7 +94,7 @@ export class RTCConnection extends EventEmitter {
|
|
|
105
94
|
this.trackNewChannel(channel, { isLocal: false });
|
|
106
95
|
});
|
|
107
96
|
|
|
108
|
-
this.rawConn!.onTrack((track:
|
|
97
|
+
this.rawConn!.onTrack((track: NodeDataChannel.Track) => {
|
|
109
98
|
if (!this.rawConn) return; // https://github.com/murat-dogan/node-datachannel/issues/103
|
|
110
99
|
|
|
111
100
|
this.trackNewMediaTrack(track, { isLocal: false });
|
|
@@ -134,7 +123,7 @@ export class RTCConnection extends EventEmitter {
|
|
|
134
123
|
return this.trackNewChannel(channel, { isLocal: true });
|
|
135
124
|
}
|
|
136
125
|
|
|
137
|
-
protected trackNewChannel(channel:
|
|
126
|
+
protected trackNewChannel(channel: NodeDataChannel.DataChannel, options: { isLocal: boolean }) {
|
|
138
127
|
const channelStream = new DataChannelStream(channel);
|
|
139
128
|
this.trackedChannels.push({ stream: channelStream, isLocal: options.isLocal });
|
|
140
129
|
|
|
@@ -159,7 +148,7 @@ export class RTCConnection extends EventEmitter {
|
|
|
159
148
|
return channelStream;
|
|
160
149
|
}
|
|
161
150
|
|
|
162
|
-
protected trackNewMediaTrack(track:
|
|
151
|
+
protected trackNewMediaTrack(track: NodeDataChannel.Track, options: { isLocal: boolean }) {
|
|
163
152
|
const trackStream = new MediaTrackStream(track);
|
|
164
153
|
this.trackedMediaTracks.push({ stream: trackStream, isLocal: options.isLocal });
|
|
165
154
|
|
|
@@ -205,7 +194,7 @@ export class RTCConnection extends EventEmitter {
|
|
|
205
194
|
async buildLocalDescription(): Promise<MockRTCSessionDescription> {
|
|
206
195
|
if (!this.rawConn) throw new Error("Can't get local description after connection is closed");
|
|
207
196
|
|
|
208
|
-
let setupChannel:
|
|
197
|
+
let setupChannel: NodeDataChannel.DataChannel | undefined;
|
|
209
198
|
if (this.rawConn.gatheringState() === 'new') {
|
|
210
199
|
// We can't create an offer until we have something to negotiate, but we don't want to
|
|
211
200
|
// negotiate ourselves when we don't really know what's being negotiated here. To work
|
|
@@ -316,7 +305,7 @@ export class RTCConnection extends EventEmitter {
|
|
|
316
305
|
this.trackNewMediaTrack(track, { isLocal: true });
|
|
317
306
|
});
|
|
318
307
|
|
|
319
|
-
let setupChannel:
|
|
308
|
+
let setupChannel: NodeDataChannel.DataChannel | undefined;
|
|
320
309
|
const channelRequiredForDescription = this.rawConn.gatheringState() === 'new' &&
|
|
321
310
|
!mediaStreamsToMirror.length;
|
|
322
311
|
if (shouldMirrorDataStream || channelRequiredForDescription || options.addDataStream) {
|
|
@@ -442,13 +431,13 @@ export class RTCConnection extends EventEmitter {
|
|
|
442
431
|
this.localDescription = undefined;
|
|
443
432
|
|
|
444
433
|
if (rawConn.state() === 'closed') return;
|
|
445
|
-
rawConn.
|
|
434
|
+
rawConn.close();
|
|
446
435
|
this.emit('connection-closed');
|
|
447
436
|
}
|
|
448
437
|
|
|
449
438
|
}
|
|
450
439
|
|
|
451
|
-
function sdpDirectionToNDCDirection(direction: SDP.SharedAttributes['direction']):
|
|
440
|
+
function sdpDirectionToNDCDirection(direction: SDP.SharedAttributes['direction']): NodeDataChannel.Direction {
|
|
452
441
|
if (direction === 'inactive') return NodeDataChannel.Direction.Inactive;
|
|
453
442
|
else if (direction?.length === 8) {
|
|
454
443
|
return direction[0].toUpperCase() +
|