mockrtc 0.1.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 +29 -0
- package/LICENSE +201 -0
- package/README.md +290 -0
- package/dist/admin-bin.d.ts +2 -0
- package/dist/admin-bin.js +67 -0
- package/dist/admin-bin.js.map +1 -0
- package/dist/client/mockrtc-client.d.ts +12 -0
- package/dist/client/mockrtc-client.js +67 -0
- package/dist/client/mockrtc-client.js.map +1 -0
- package/dist/client/mockrtc-remote-peer.d.ts +15 -0
- package/dist/client/mockrtc-remote-peer.js +246 -0
- package/dist/client/mockrtc-remote-peer.js.map +1 -0
- package/dist/control-channel.d.ts +8 -0
- package/dist/control-channel.js +11 -0
- package/dist/control-channel.js.map +1 -0
- package/dist/handling/handler-builder.d.ts +138 -0
- package/dist/handling/handler-builder.js +164 -0
- package/dist/handling/handler-builder.js.map +1 -0
- package/dist/handling/handler-step-definitions.d.ts +63 -0
- package/dist/handling/handler-step-definitions.js +123 -0
- package/dist/handling/handler-step-definitions.js.map +1 -0
- package/dist/handling/handler-steps.d.ts +48 -0
- package/dist/handling/handler-steps.js +218 -0
- package/dist/handling/handler-steps.js.map +1 -0
- package/dist/main-browser.d.ts +9 -0
- package/dist/main-browser.js +26 -0
- package/dist/main-browser.js.map +1 -0
- package/dist/main.d.ts +58 -0
- package/dist/main.js +67 -0
- package/dist/main.js.map +1 -0
- package/dist/mockrtc-admin-plugin.d.ts +56 -0
- package/dist/mockrtc-admin-plugin.js +151 -0
- package/dist/mockrtc-admin-plugin.js.map +1 -0
- package/dist/mockrtc-admin-server.d.ts +7 -0
- package/dist/mockrtc-admin-server.js +18 -0
- package/dist/mockrtc-admin-server.js.map +1 -0
- package/dist/mockrtc-client.d.ts +12 -0
- package/dist/mockrtc-client.js +64 -0
- package/dist/mockrtc-client.js.map +1 -0
- package/dist/mockrtc-handler-builder.d.ts +15 -0
- package/dist/mockrtc-handler-builder.js +24 -0
- package/dist/mockrtc-handler-builder.js.map +1 -0
- package/dist/mockrtc-peer.d.ts +147 -0
- package/dist/mockrtc-peer.js +7 -0
- package/dist/mockrtc-peer.js.map +1 -0
- package/dist/mockrtc-remote-peer.d.ts +15 -0
- package/dist/mockrtc-remote-peer.js +234 -0
- package/dist/mockrtc-remote-peer.js.map +1 -0
- package/dist/mockrtc-server-peer.d.ts +29 -0
- package/dist/mockrtc-server-peer.js +145 -0
- package/dist/mockrtc-server-peer.js.map +1 -0
- package/dist/mockrtc-server.d.ts +14 -0
- package/dist/mockrtc-server.js +53 -0
- package/dist/mockrtc-server.js.map +1 -0
- package/dist/mockrtc.d.ts +25 -0
- package/dist/mockrtc.js +7 -0
- package/dist/mockrtc.js.map +1 -0
- package/dist/package.json +52 -0
- package/dist/server/mockrtc-admin-plugin.d.ts +17 -0
- package/dist/server/mockrtc-admin-plugin.js +163 -0
- package/dist/server/mockrtc-admin-plugin.js.map +1 -0
- package/dist/server/mockrtc-admin-server.d.ts +7 -0
- package/dist/server/mockrtc-admin-server.js +18 -0
- package/dist/server/mockrtc-admin-server.js.map +1 -0
- package/dist/server/mockrtc-server-peer.d.ts +24 -0
- package/dist/server/mockrtc-server-peer.js +141 -0
- package/dist/server/mockrtc-server-peer.js.map +1 -0
- package/dist/server/mockrtc-server.d.ts +14 -0
- package/dist/server/mockrtc-server.js +53 -0
- package/dist/server/mockrtc-server.js.map +1 -0
- package/dist/src/main.d.ts +1 -0
- package/dist/src/main.js +24 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/mockrtc-peer.d.ts +0 -0
- package/dist/src/mockrtc-peer.js +2 -0
- package/dist/src/mockrtc-peer.js.map +1 -0
- package/dist/src/mockrtc.d.ts +0 -0
- package/dist/src/mockrtc.js +65 -0
- package/dist/src/mockrtc.js.map +1 -0
- package/dist/webrtc/control-channel.d.ts +8 -0
- package/dist/webrtc/control-channel.js +11 -0
- package/dist/webrtc/control-channel.js.map +1 -0
- package/dist/webrtc/datachannel-stream.d.ts +25 -0
- package/dist/webrtc/datachannel-stream.js +86 -0
- package/dist/webrtc/datachannel-stream.js.map +1 -0
- package/dist/webrtc/mediatrack-stream.d.ts +29 -0
- package/dist/webrtc/mediatrack-stream.js +109 -0
- package/dist/webrtc/mediatrack-stream.js.map +1 -0
- package/dist/webrtc/mockrtc-connection.d.ts +14 -0
- package/dist/webrtc/mockrtc-connection.js +147 -0
- package/dist/webrtc/mockrtc-connection.js.map +1 -0
- package/dist/webrtc/peer-connection.d.ts +16 -0
- package/dist/webrtc/peer-connection.js +81 -0
- package/dist/webrtc/peer-connection.js.map +1 -0
- package/dist/webrtc/rtc-connection.d.ts +47 -0
- package/dist/webrtc/rtc-connection.js +370 -0
- package/dist/webrtc/rtc-connection.js.map +1 -0
- package/dist/webrtc-hooks.d.ts +30 -0
- package/dist/webrtc-hooks.js +224 -0
- package/dist/webrtc-hooks.js.map +1 -0
- package/karma.conf.ts +89 -0
- package/ngi-eu-footer.png +0 -0
- package/package.json +86 -0
- package/src/admin-bin.ts +57 -0
- package/src/client/mockrtc-client.ts +79 -0
- package/src/client/mockrtc-remote-peer.ts +286 -0
- package/src/handling/handler-builder.ts +215 -0
- package/src/handling/handler-step-definitions.ts +142 -0
- package/src/handling/handler-steps.ts +254 -0
- package/src/main-browser.ts +44 -0
- package/src/main.ts +109 -0
- package/src/mockrtc-peer.ts +176 -0
- package/src/mockrtc.ts +36 -0
- package/src/server/mockrtc-admin-plugin.ts +196 -0
- package/src/server/mockrtc-admin-server.ts +17 -0
- package/src/server/mockrtc-server-peer.ts +159 -0
- package/src/server/mockrtc-server.ts +53 -0
- package/src/webrtc/control-channel.ts +13 -0
- package/src/webrtc/datachannel-stream.ts +102 -0
- package/src/webrtc/mediatrack-stream.ts +135 -0
- package/src/webrtc/mockrtc-connection.ts +164 -0
- package/src/webrtc/rtc-connection.ts +420 -0
- package/src/webrtc-hooks.ts +245 -0
- package/test/integration/close-steps.spec.ts +39 -0
- package/test/integration/connection-setup.spec.ts +230 -0
- package/test/integration/echo-steps.spec.ts +88 -0
- package/test/integration/proxy.spec.ts +526 -0
- package/test/integration/send-steps.spec.ts +76 -0
- package/test/integration/smoke-test.spec.ts +100 -0
- package/test/integration/wait-steps.spec.ts +225 -0
- package/test/start-test-admin-server.ts +12 -0
- package/test/test-setup.ts +136 -0
- package/test/tsconfig.json +11 -0
- package/tsconfig.json +14 -0
- package/typedoc.json +19 -0
- package/wallaby.js +41 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* SPDX-FileCopyrightText: 2022 Tim Perry <tim@httptoolkit.tech>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.MockRTCClient = void 0;
|
|
17
|
+
const graphql_tag_1 = require("graphql-tag");
|
|
18
|
+
// Long-term, it'd be great to use the 'official' export path of mockttp/pluggable-admin, but
|
|
19
|
+
// if we do so, then TypeScript <4.7 doesn't understand it here or downstream, so we get errors.
|
|
20
|
+
// We don't want to use the main-exported version to avoid bundling all of Mockttp in browsers.
|
|
21
|
+
// For now we have to use the direct import. We can update once TS 4.7 is widely used.
|
|
22
|
+
const BrowserPluggableAdmin = require("mockttp/dist/pluggable-admin-api/pluggable-admin.browser");
|
|
23
|
+
const mockrtc_remote_peer_1 = require("./mockrtc-remote-peer");
|
|
24
|
+
const handler_builder_1 = require("../handling/handler-builder");
|
|
25
|
+
class MockRTCClient {
|
|
26
|
+
constructor(options = {}) {
|
|
27
|
+
this.options = options;
|
|
28
|
+
this.buildPeerFromData = (handlerSteps) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const { adminStream } = this.adminClient;
|
|
30
|
+
const peerData = yield this.adminClient.sendQuery({
|
|
31
|
+
query: (0, graphql_tag_1.default) `
|
|
32
|
+
mutation CreatePeer($peerData: RTCHandlerData!) {
|
|
33
|
+
createPeer(data: $peerData) {
|
|
34
|
+
peerId
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`,
|
|
38
|
+
variables: {
|
|
39
|
+
peerData: {
|
|
40
|
+
steps: handlerSteps.map(step => BrowserPluggableAdmin.Serialization.serialize(step, adminStream))
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
transformResponse: ({ createPeer }) => createPeer
|
|
44
|
+
});
|
|
45
|
+
const { peerId } = peerData;
|
|
46
|
+
return new mockrtc_remote_peer_1.MockRTCRemotePeer(peerId, this.adminClient);
|
|
47
|
+
});
|
|
48
|
+
this.adminClient = new BrowserPluggableAdmin.AdminClient(options);
|
|
49
|
+
}
|
|
50
|
+
buildPeer() {
|
|
51
|
+
return new handler_builder_1.MockRTCHandlerBuilder(this.buildPeerFromData);
|
|
52
|
+
}
|
|
53
|
+
start() {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
yield this.adminClient.start({
|
|
56
|
+
webrtc: this.options
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
stop() {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
yield this.adminClient.stop();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.MockRTCClient = MockRTCClient;
|
|
67
|
+
//# sourceMapp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CAAC,KAAK,CAAC;gBACzB,MAAM,EAAE,IAAI,CAAC,OAAO;aACvB,CAAC,CAAC;QACP,CAAC;KAAA;IAEK,IAAI;;YACN,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAClC,CAAC;KAAA;CACJ;AApDD,sCAoDC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as PluggableAdmin from 'mockttp/dist/pluggable-admin-api/pluggable-admin.browser';
|
|
3
|
+
import { MockRTCPeer, MockRTCOfferParams, MockRTCExternalOfferParams, MockRTCExternalAnswerParams, MockRTCAnswerParams, MockRTCSession, OfferOptions, AnswerOptions } from "../mockrtc-peer";
|
|
4
|
+
export declare class MockRTCRemotePeer implements MockRTCPeer {
|
|
5
|
+
readonly peerId: string;
|
|
6
|
+
private adminClient;
|
|
7
|
+
constructor(peerId: string, adminClient: PluggableAdmin.AdminClient<{}>);
|
|
8
|
+
createOffer(options?: OfferOptions): Promise<MockRTCOfferParams>;
|
|
9
|
+
createExternalOffer(options?: OfferOptions): Promise<MockRTCExternalOfferParams>;
|
|
10
|
+
answerOffer(offer: RTCSessionDescriptionInit, options?: AnswerOptions): Promise<MockRTCAnswerParams>;
|
|
11
|
+
answerExternalOffer(offer: RTCSessionDescriptionInit, options?: AnswerOptions): Promise<MockRTCExternalAnswerParams>;
|
|
12
|
+
getSession(sessionId: string): MockRTCSession;
|
|
13
|
+
getAllMessages(): Promise<(string | Buffer)[]>;
|
|
14
|
+
getMessagesOnChannel(channelName: string): Promise<Array<string | Buffer>>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* SPDX-FileCopyrightText: 2022 Tim Perry <tim@httptoolkit.tech>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.MockRTCRemotePeer = void 0;
|
|
17
|
+
const graphql_tag_1 = require("graphql-tag");
|
|
18
|
+
class MockRTCRemotePeer {
|
|
19
|
+
constructor(peerId, adminClient) {
|
|
20
|
+
this.peerId = peerId;
|
|
21
|
+
this.adminClient = adminClient;
|
|
22
|
+
}
|
|
23
|
+
createOffer(options) {
|
|
24
|
+
return this.adminClient.sendQuery({
|
|
25
|
+
query: (0, graphql_tag_1.gql) `
|
|
26
|
+
mutation GetPeerRTCOffer($peerId: ID!, $options: Raw) {
|
|
27
|
+
createOffer(peerId: $peerId, options: $options) {
|
|
28
|
+
id
|
|
29
|
+
description {
|
|
30
|
+
type
|
|
31
|
+
sdp
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`,
|
|
36
|
+
variables: { peerId: this.peerId, options },
|
|
37
|
+
transformResponse: ({ createOffer }) => {
|
|
38
|
+
const session = this.getSession(createOffer.id);
|
|
39
|
+
return {
|
|
40
|
+
offer: createOffer.description,
|
|
41
|
+
session,
|
|
42
|
+
setAnswer: session.completeOffer.bind(session)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
createExternalOffer(options) {
|
|
48
|
+
return this.adminClient.sendQuery({
|
|
49
|
+
query: (0, graphql_tag_1.gql) `
|
|
50
|
+
mutation GetPeerRTCExternalOffer($peerId: ID!, $options: Raw) {
|
|
51
|
+
createExternalOffer(peerId: $peerId, options: $options) {
|
|
52
|
+
id
|
|
53
|
+
description {
|
|
54
|
+
type
|
|
55
|
+
sdp
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
`,
|
|
60
|
+
variables: { peerId: this.peerId, options },
|
|
61
|
+
transformResponse: ({ createExternalOffer }) => {
|
|
62
|
+
const session = this.getSession(createExternalOffer.id);
|
|
63
|
+
return {
|
|
64
|
+
id: createExternalOffer.id,
|
|
65
|
+
offer: createExternalOffer.description,
|
|
66
|
+
session,
|
|
67
|
+
setAnswer: session.completeOffer.bind(session)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
answerOffer(offer, options) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
return this.adminClient.sendQuery({
|
|
75
|
+
query: (0, graphql_tag_1.gql) `
|
|
76
|
+
mutation GetPeerRTCAnswer(
|
|
77
|
+
$peerId: ID!,
|
|
78
|
+
$offer: SessionDescriptionInput!,
|
|
79
|
+
$options: Raw
|
|
80
|
+
) {
|
|
81
|
+
answerOffer(peerId: $peerId, offer: $offer, options: $options) {
|
|
82
|
+
id
|
|
83
|
+
description {
|
|
84
|
+
type
|
|
85
|
+
sdp
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
`,
|
|
90
|
+
variables: { peerId: this.peerId, offer, options },
|
|
91
|
+
transformResponse: ({ answerOffer }) => ({
|
|
92
|
+
answer: answerOffer.description,
|
|
93
|
+
session: this.getSession(answerOffer.id)
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
answerExternalOffer(offer, options) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return this.adminClient.sendQuery({
|
|
101
|
+
query: (0, graphql_tag_1.gql) `
|
|
102
|
+
mutation GetPeerRTCExternalAnswer(
|
|
103
|
+
$peerId: ID!,
|
|
104
|
+
$offer: SessionDescriptionInput!,
|
|
105
|
+
$options: Raw
|
|
106
|
+
) {
|
|
107
|
+
answerExternalOffer(peerId: $peerId, offer: $offer, options: $options) {
|
|
108
|
+
id
|
|
109
|
+
description {
|
|
110
|
+
type
|
|
111
|
+
sdp
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
`,
|
|
116
|
+
variables: { peerId: this.peerId, offer, options },
|
|
117
|
+
transformResponse: ({ answerExternalOffer }) => {
|
|
118
|
+
const session = this.getSession(answerExternalOffer.id);
|
|
119
|
+
return {
|
|
120
|
+
id: answerExternalOffer.id,
|
|
121
|
+
answer: answerExternalOffer.description,
|
|
122
|
+
session
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
getSession(sessionId) {
|
|
129
|
+
return new RemoteSessionApi(this.adminClient, this.peerId, sessionId);
|
|
130
|
+
}
|
|
131
|
+
getAllMessages() {
|
|
132
|
+
return this.adminClient.sendQuery({
|
|
133
|
+
query: (0, graphql_tag_1.gql) `
|
|
134
|
+
query GetPeerSeenMessages($peerId: ID!) {
|
|
135
|
+
getSeenMessages(peerId: $peerId)
|
|
136
|
+
}
|
|
137
|
+
`,
|
|
138
|
+
variables: { peerId: this.peerId },
|
|
139
|
+
transformResponse: ({ getSeenMessages }) => {
|
|
140
|
+
return getSeenMessages.map((message) => {
|
|
141
|
+
if (typeof message === 'string') {
|
|
142
|
+
return message;
|
|
143
|
+
}
|
|
144
|
+
else if (message.type === 'buffer') {
|
|
145
|
+
return Buffer.from(message.value, 'base64');
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
throw new Error(`Unparseable message data: ${JSON.stringify(message)}`);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
getMessagesOnChannel(channelName) {
|
|
155
|
+
return this.adminClient.sendQuery({
|
|
156
|
+
query: (0, graphql_tag_1.gql) `
|
|
157
|
+
query GetPeerSeenMessages($peerId: ID!, $channelName: String) {
|
|
158
|
+
getSeenMessages(peerId: $peerId, channelName: $channelName)
|
|
159
|
+
}
|
|
160
|
+
`,
|
|
161
|
+
variables: { peerId: this.peerId, channelName },
|
|
162
|
+
transformResponse: ({ getSeenMessages }) => {
|
|
163
|
+
return getSeenMessages.map((message) => {
|
|
164
|
+
if (typeof message === 'string') {
|
|
165
|
+
return message;
|
|
166
|
+
}
|
|
167
|
+
else if (message.type === 'buffer') {
|
|
168
|
+
return Buffer.from(message.value, 'base64');
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
throw new Error(`Unparseable message data: ${JSON.stringify(message)}`);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.MockRTCRemotePeer = MockRTCRemotePeer;
|
|
179
|
+
class RemoteSessionApi {
|
|
180
|
+
constructor(adminClient, peerId, sessionId) {
|
|
181
|
+
this.adminClient = adminClient;
|
|
182
|
+
this.peerId = peerId;
|
|
183
|
+
this.sessionId = sessionId;
|
|
184
|
+
}
|
|
185
|
+
createOffer(options) {
|
|
186
|
+
return this.adminClient.sendQuery({
|
|
187
|
+
query: (0, graphql_tag_1.gql) `
|
|
188
|
+
mutation GetPeerRTCSessionOffer($peerId: ID!, $sessionId: ID!, $options: Raw) {
|
|
189
|
+
createOffer(peerId: $peerId, sessionId: $sessionId, options: $options) {
|
|
190
|
+
description {
|
|
191
|
+
type
|
|
192
|
+
sdp
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
`,
|
|
197
|
+
variables: { peerId: this.peerId, sessionId: this.sessionId, options },
|
|
198
|
+
transformResponse: ({ createOffer }) => createOffer.description
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
completeOffer(answer) {
|
|
202
|
+
return this.adminClient.sendQuery({
|
|
203
|
+
query: (0, graphql_tag_1.gql) `
|
|
204
|
+
mutation CompletePeerRTCOffer(
|
|
205
|
+
$peerId: ID!,
|
|
206
|
+
$sessionId: ID!,
|
|
207
|
+
$answer: SessionDescriptionInput!
|
|
208
|
+
) {
|
|
209
|
+
completeOffer(peerId: $peerId, sessionId: $sessionId, answer: $answer)
|
|
210
|
+
}
|
|
211
|
+
`,
|
|
212
|
+
variables: {
|
|
213
|
+
peerId: this.peerId,
|
|
214
|
+
sessionId: this.sessionId,
|
|
215
|
+
answer: answer
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
answerOffer(offer, options) {
|
|
220
|
+
return this.adminClient.sendQuery({
|
|
221
|
+
query: (0, graphql_tag_1.gql) `
|
|
222
|
+
mutation GetPeerRTCAnswer(
|
|
223
|
+
$peerId: ID!,
|
|
224
|
+
$sessionId: ID!,
|
|
225
|
+
$offer: SessionDescriptionInput!,
|
|
226
|
+
$options: Raw
|
|
227
|
+
) {
|
|
228
|
+
answerOffer(peerId: $peerId, sessionId: $sessionId, offer: $offer, options: $options) {
|
|
229
|
+
description {
|
|
230
|
+
type
|
|
231
|
+
sdp
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
`,
|
|
236
|
+
variables: {
|
|
237
|
+
peerId: this.peerId,
|
|
238
|
+
sessionId: this.sessionId,
|
|
239
|
+
offer,
|
|
240
|
+
options
|
|
241
|
+
},
|
|
242
|
+
transformResponse: ({ answerOffer }) => answerOffer.description
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=mockrtc-remote-peer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockrtc-remote-peer.js","sourceRoot":"","sources":["../../src/client/mockrtc-remote-peer.ts"],"names":[],"mappings":";AAAA;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,CAAC;IACP,CAAC;CAEJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* SPDX-FileCopyrightText: 2022 Tim Perry <tim@httptoolkit.tech>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.MOCKRTC_CONTROL_CHANNEL = void 0;
|
|
8
|
+
// The WebRTC control channel name & protocol used when communicating metadata to about client
|
|
9
|
+
// configuration, e.g. the external connection to bridge to.
|
|
10
|
+
exports.MOCKRTC_CONTROL_CHANNEL = "mockrtc.control-channel";
|
|
11
|
+
//# sourceMappingURL=control-channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-channel.js","sourceRoot":"","sources":["../src/control-channel.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,8FAA8F;AAC9F,4DAA4D;AAC/C,QAAA,uBAAuB,GAAG,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { type HandlerStepDefinition } from "./handler-step-definitions";
|
|
3
|
+
/**
|
|
4
|
+
* The builder logic for composing RTC handling behaviour for both mock peers and rules,
|
|
5
|
+
* by internally queuing defined actions until a `.thenX()` method is called to compile
|
|
6
|
+
* the actions into either a peer or a rule (handled by an constructor callback param).
|
|
7
|
+
*/
|
|
8
|
+
export declare class MockRTCHandlerBuilder<R> {
|
|
9
|
+
private buildCallback;
|
|
10
|
+
private handlerSteps;
|
|
11
|
+
constructor(buildCallback: (handlerSteps: HandlerStepDefinition[]) => Promise<R>);
|
|
12
|
+
/**
|
|
13
|
+
* Wait for a given duration, in milliseconds
|
|
14
|
+
*
|
|
15
|
+
* @category Steps
|
|
16
|
+
*/
|
|
17
|
+
sleep(duration: number): this;
|
|
18
|
+
/**
|
|
19
|
+
* Wait until the remote client has created at least one DataChannel.
|
|
20
|
+
*
|
|
21
|
+
* @category Steps
|
|
22
|
+
*/
|
|
23
|
+
waitForChannel(channelLabel?: string): this;
|
|
24
|
+
/**
|
|
25
|
+
* Wait until the remote client has created at least one media track
|
|
26
|
+
*
|
|
27
|
+
* @category Steps
|
|
28
|
+
*/
|
|
29
|
+
waitForTrack(): this;
|
|
30
|
+
/**
|
|
31
|
+
* Wait until the remote client next sends a message to us on any DataChannel.
|
|
32
|
+
*
|
|
33
|
+
* This looks for new messages, ignoring any messages already consumed by
|
|
34
|
+
* previous steps.
|
|
35
|
+
*
|
|
36
|
+
* @category Steps
|
|
37
|
+
*/
|
|
38
|
+
waitForNextMessage(): this;
|
|
39
|
+
/**
|
|
40
|
+
* Wait until the remote client next sends media data on a media track.
|
|
41
|
+
*
|
|
42
|
+
* This waits for new media, ignoring any media already consumed by previous steps.
|
|
43
|
+
*
|
|
44
|
+
* @category Steps
|
|
45
|
+
*/
|
|
46
|
+
waitForNextMedia(): this;
|
|
47
|
+
/**
|
|
48
|
+
* Wait until the remote client sends a message to us on a specific DataChannel.
|
|
49
|
+
*
|
|
50
|
+
* This looks for new messages, ignoring any messages already consumed by
|
|
51
|
+
* previous steps.
|
|
52
|
+
*
|
|
53
|
+
* @category Steps
|
|
54
|
+
*/
|
|
55
|
+
waitForNextMessageOnChannel(channelLabel: string): this;
|
|
56
|
+
/**
|
|
57
|
+
* Send a message or buffer on the connection's data channels.
|
|
58
|
+
*
|
|
59
|
+
* This can take one or two arguments. If only one is provided, it is used
|
|
60
|
+
* as a message that's sent on all open data channels. If two arguments are
|
|
61
|
+
* provided, the first must be the data channel label, and the message (the
|
|
62
|
+
* second) will be sent only to data channel(s) with that label.
|
|
63
|
+
*
|
|
64
|
+
* If no matching channels are open, this is a no-op. Use `waitForChannel()`
|
|
65
|
+
* to ensure the channels you're expecting are open first if necessary.
|
|
66
|
+
*
|
|
67
|
+
* @category Steps
|
|
68
|
+
*/
|
|
69
|
+
send(message: string | Buffer): this;
|
|
70
|
+
send(channel: string | undefined, message: string | Buffer): this;
|
|
71
|
+
/**
|
|
72
|
+
* Immediately close the connection.
|
|
73
|
+
*
|
|
74
|
+
* This defines a final step, and will then create a mock peer from the full
|
|
75
|
+
* set of steps you've defined, and return it wrapped in a promise. As soon
|
|
76
|
+
* as the promise resolves the peer is ready to use.
|
|
77
|
+
*
|
|
78
|
+
* @category Final Steps
|
|
79
|
+
*/
|
|
80
|
+
thenClose(): Promise<R>;
|
|
81
|
+
/**
|
|
82
|
+
* Send a message or buffer on the connection's data channels, then close the
|
|
83
|
+
* connection. This is equivalent to {@link send `.send()`} then
|
|
84
|
+
* {@link thenClose `.thenClose()`}.
|
|
85
|
+
*
|
|
86
|
+
* This defines a final step, and will then create a mock peer from the full
|
|
87
|
+
* set of steps you've defined, and return it wrapped in a promise. As soon
|
|
88
|
+
* as the promise resolves the peer is ready to use.
|
|
89
|
+
*
|
|
90
|
+
* @category Final Steps
|
|
91
|
+
*/
|
|
92
|
+
thenSend(message: string | Buffer): Promise<R>;
|
|
93
|
+
thenSend(channel: string, message: string | Buffer): Promise<R>;
|
|
94
|
+
/**
|
|
95
|
+
* Echo all incoming data channel messages until the other peer closes the
|
|
96
|
+
* connection.
|
|
97
|
+
*
|
|
98
|
+
* This defines a final step, and will then create a mock peer from the full
|
|
99
|
+
* set of steps you've defined, and return it wrapped in a promise. As soon
|
|
100
|
+
* as the promise resolves the peer is ready to use.
|
|
101
|
+
*
|
|
102
|
+
* @category Final Steps
|
|
103
|
+
*/
|
|
104
|
+
thenEcho(): Promise<R>;
|
|
105
|
+
/**
|
|
106
|
+
* Creates a new external connection to the given remote peer connection,
|
|
107
|
+
* matching the existing mocked connection, and then proxies all traffic
|
|
108
|
+
* through to that peer.
|
|
109
|
+
*
|
|
110
|
+
* This defines a final step, and will then create a mock peer from the full
|
|
111
|
+
* set of steps you've defined, and return it wrapped in a promise. As soon
|
|
112
|
+
* as the promise resolves the peer is ready to use.
|
|
113
|
+
*
|
|
114
|
+
* @category Final Steps
|
|
115
|
+
*/
|
|
116
|
+
thenForwardTo(peer: RTCPeerConnection): Promise<R>;
|
|
117
|
+
/**
|
|
118
|
+
* Proxy this connection dynamically to the 'real' target peer, whoever
|
|
119
|
+
* that may be.
|
|
120
|
+
*
|
|
121
|
+
* This assumes that you have an existing external connection already
|
|
122
|
+
* set up and attached to this mock connection.
|
|
123
|
+
*
|
|
124
|
+
* You can do that either by using {@link hookWebRTCConnection} or
|
|
125
|
+
* {@link hookAllWebRTC} to hook your connection during normal setup to
|
|
126
|
+
* automatically create an external offer to the real remote peer, or you can
|
|
127
|
+
* do so manually using {@link MockRTCPeer.createExternalOffer} or
|
|
128
|
+
* {@link MockRTCPeer.answerExternalOffer} and then passing the connection
|
|
129
|
+
* id as {@link https://github.com/httptoolkit/mockrtc/blob/d0604f3111e0438c52aa514d00cf04ac0718dfeb/src/webrtc-hooks.ts#L83-L93 here}.
|
|
130
|
+
*
|
|
131
|
+
* This defines a final step, and will then create a mock peer from the full
|
|
132
|
+
* set of steps you've defined, and return it wrapped in a promise. As soon
|
|
133
|
+
* as the promise resolves the peer is ready to use.
|
|
134
|
+
*
|
|
135
|
+
* @category Final Steps
|
|
136
|
+
*/
|
|
137
|
+
thenPassThrough(): Promise<R>;
|
|
138
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* SPDX-FileCopyrightText: 2022 Tim Perry <tim@httptoolkit.tech>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.MockRTCHandlerBuilder = void 0;
|
|
8
|
+
const handler_step_definitions_1 = require("./handler-step-definitions");
|
|
9
|
+
/**
|
|
10
|
+
* The builder logic for composing RTC handling behaviour for both mock peers and rules,
|
|
11
|
+
* by internally queuing defined actions until a `.thenX()` method is called to compile
|
|
12
|
+
* the actions into either a peer or a rule (handled by an constructor callback param).
|
|
13
|
+
*/
|
|
14
|
+
class MockRTCHandlerBuilder {
|
|
15
|
+
constructor(buildCallback) {
|
|
16
|
+
this.buildCallback = buildCallback;
|
|
17
|
+
this.handlerSteps = [];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Wait for a given duration, in milliseconds
|
|
21
|
+
*
|
|
22
|
+
* @category Steps
|
|
23
|
+
*/
|
|
24
|
+
sleep(duration) {
|
|
25
|
+
this.handlerSteps.push(new handler_step_definitions_1.WaitForDurationStepDefinition(duration));
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Wait until the remote client has created at least one DataChannel.
|
|
30
|
+
*
|
|
31
|
+
* @category Steps
|
|
32
|
+
*/
|
|
33
|
+
waitForChannel(channelLabel) {
|
|
34
|
+
this.handlerSteps.push(new handler_step_definitions_1.WaitForChannelStepDefinition(channelLabel));
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Wait until the remote client has created at least one media track
|
|
39
|
+
*
|
|
40
|
+
* @category Steps
|
|
41
|
+
*/
|
|
42
|
+
waitForTrack() {
|
|
43
|
+
this.handlerSteps.push(new handler_step_definitions_1.WaitForTrackStepDefinition());
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Wait until the remote client next sends a message to us on any DataChannel.
|
|
48
|
+
*
|
|
49
|
+
* This looks for new messages, ignoring any messages already consumed by
|
|
50
|
+
* previous steps.
|
|
51
|
+
*
|
|
52
|
+
* @category Steps
|
|
53
|
+
*/
|
|
54
|
+
waitForNextMessage() {
|
|
55
|
+
this.handlerSteps.push(new handler_step_definitions_1.WaitForMessageStepDefinition());
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Wait until the remote client next sends media data on a media track.
|
|
60
|
+
*
|
|
61
|
+
* This waits for new media, ignoring any media already consumed by previous steps.
|
|
62
|
+
*
|
|
63
|
+
* @category Steps
|
|
64
|
+
*/
|
|
65
|
+
waitForNextMedia() {
|
|
66
|
+
this.handlerSteps.push(new handler_step_definitions_1.WaitForMediaStepDefinition());
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Wait until the remote client sends a message to us on a specific DataChannel.
|
|
71
|
+
*
|
|
72
|
+
* This looks for new messages, ignoring any messages already consumed by
|
|
73
|
+
* previous steps.
|
|
74
|
+
*
|
|
75
|
+
* @category Steps
|
|
76
|
+
*/
|
|
77
|
+
waitForNextMessageOnChannel(channelLabel) {
|
|
78
|
+
this.handlerSteps.push(new handler_step_definitions_1.WaitForMessageStepDefinition(channelLabel));
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
send(...args) {
|
|
82
|
+
if (args[1] !== undefined) {
|
|
83
|
+
const [channel, message] = args;
|
|
84
|
+
this.handlerSteps.push(new handler_step_definitions_1.SendStepDefinition(channel, message));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const [message] = args;
|
|
88
|
+
this.handlerSteps.push(new handler_step_definitions_1.SendStepDefinition(undefined, message));
|
|
89
|
+
}
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Immediately close the connection.
|
|
94
|
+
*
|
|
95
|
+
* This defines a final step, and will then create a mock peer from the full
|
|
96
|
+
* set of steps you've defined, and return it wrapped in a promise. As soon
|
|
97
|
+
* as the promise resolves the peer is ready to use.
|
|
98
|
+
*
|
|
99
|
+
* @category Final Steps
|
|
100
|
+
*/
|
|
101
|
+
thenClose() {
|
|
102
|
+
this.handlerSteps.push(new handler_step_definitions_1.CloseStepDefinition());
|
|
103
|
+
return this.buildCallback(this.handlerSteps);
|
|
104
|
+
}
|
|
105
|
+
thenSend(...args) {
|
|
106
|
+
return this.send(...args)
|
|
107
|
+
.buildCallback(this.handlerSteps);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Echo all incoming data channel messages until the other peer closes the
|
|
111
|
+
* connection.
|
|
112
|
+
*
|
|
113
|
+
* This defines a final step, and will then create a mock peer from the full
|
|
114
|
+
* set of steps you've defined, and return it wrapped in a promise. As soon
|
|
115
|
+
* as the promise resolves the peer is ready to use.
|
|
116
|
+
*
|
|
117
|
+
* @category Final Steps
|
|
118
|
+
*/
|
|
119
|
+
thenEcho() {
|
|
120
|
+
this.handlerSteps.push(new handler_step_definitions_1.EchoStepDefinition());
|
|
121
|
+
return this.buildCallback(this.handlerSteps);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Creates a new external connection to the given remote peer connection,
|
|
125
|
+
* matching the existing mocked connection, and then proxies all traffic
|
|
126
|
+
* through to that peer.
|
|
127
|
+
*
|
|
128
|
+
* This defines a final step, and will then create a mock peer from the full
|
|
129
|
+
* set of steps you've defined, and return it wrapped in a promise. As soon
|
|
130
|
+
* as the promise resolves the peer is ready to use.
|
|
131
|
+
*
|
|
132
|
+
* @category Final Steps
|
|
133
|
+
*/
|
|
134
|
+
thenForwardTo(peer) {
|
|
135
|
+
this.handlerSteps.push(new handler_step_definitions_1.PeerProxyStepDefinition(peer));
|
|
136
|
+
return this.buildCallback(this.handlerSteps);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Proxy this connection dynamically to the 'real' target peer, whoever
|
|
140
|
+
* that may be.
|
|
141
|
+
*
|
|
142
|
+
* This assumes that you have an existing external connection already
|
|
143
|
+
* set up and attached to this mock connection.
|
|
144
|
+
*
|
|
145
|
+
* You can do that either by using {@link hookWebRTCConnection} or
|
|
146
|
+
* {@link hookAllWebRTC} to hook your connection during normal setup to
|
|
147
|
+
* automatically create an external offer to the real remote peer, or you can
|
|
148
|
+
* do so manually using {@link MockRTCPeer.createExternalOffer} or
|
|
149
|
+
* {@link MockRTCPeer.answerExternalOffer} and then passing the connection
|
|
150
|
+
* id as {@link https://github.com/httptoolkit/mockrtc/blob/d0604f3111e0438c52aa514d00cf04ac0718dfeb/src/webrtc-hooks.ts#L83-L93 here}.
|
|
151
|
+
*
|
|
152
|
+
* This defines a final step, and will then create a mock peer from the full
|
|
153
|
+
* set of steps you've defined, and return it wrapped in a promise. As soon
|
|
154
|
+
* as the promise resolves the peer is ready to use.
|
|
155
|
+
*
|
|
156
|
+
* @category Final Steps
|
|
157
|
+
*/
|
|
158
|
+
thenPassThrough() {
|
|
159
|
+
this.handlerSteps.push(new handler_step_definitions_1.DynamicProxyStepDefinition());
|
|
160
|
+
return this.buildCallback(this.handlerSteps);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.MockRTCHandlerBuilder = MockRTCHandlerBuilder;
|
|
164
|
+
//# sourceMappingURL=handler-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-builder.js","sourceRoot":"","sources":["../../src/handling/handler-builder.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yEAYoC;AAEpC;;;;GAIG;AACH,MAAa,qBAAqB;IAI9B,YACY,aAAoE;QAApE,kBAAa,GAAb,aAAa,CAAuD;QAHxE,iBAAY,GAA4B,EAAE,CAAC;IAIhD,CAAC;IAEJ;;;;OAIG;IACH,KAAK,CAAC,QAAgB;QAClB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,wDAA6B,CAAC,QAAQ,CAAC,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,YAAqB;QAChC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,uDAA4B,CAAC,YAAY,CAAC,CAAC,CAAC;QACvE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,YAAY;QACR,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,qDAA0B,EAAE,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;;;OAOG;IACH,kBAAkB;QACd,IAAI,CAAC,YAAY,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