janus-simple-videoroom-client 2.1.0 → 2.2.1
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/dist/index.js +10 -9
- package/dist/index.js.map +1 -0
- package/package.json +8 -7
- package/src/index.ts +862 -0
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.Janus = void 0;
|
|
13
|
+
exports.createVideoRoomClient = createVideoRoomClient;
|
|
13
14
|
/**
|
|
14
15
|
* Remove this once janus.js properly imports webrtc-adapter.
|
|
15
16
|
* Currently janus npm package depends on webrtc-adapter but does not import it, and so it gets dropped during tree shaking.
|
|
@@ -28,7 +29,6 @@ function createVideoRoomClient(options) {
|
|
|
28
29
|
};
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
exports.createVideoRoomClient = createVideoRoomClient;
|
|
32
32
|
function createVideoRoomSession(server, options) {
|
|
33
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
34
|
const eventTarget = makeEventTarget();
|
|
@@ -344,8 +344,8 @@ function createVideoRoomPublisher(handle, publisherId, opts) {
|
|
|
344
344
|
});
|
|
345
345
|
});
|
|
346
346
|
},
|
|
347
|
-
restart(
|
|
348
|
-
return __awaiter(this,
|
|
347
|
+
restart() {
|
|
348
|
+
return __awaiter(this, arguments, void 0, function* (mediaOptions = options.mediaOptions, publishOptions) {
|
|
349
349
|
const offerJsep = yield new Promise(function (fulfill, reject) {
|
|
350
350
|
handle.createOffer(Object.assign(Object.assign({}, mediaOptions), { success: fulfill, error: reject }));
|
|
351
351
|
});
|
|
@@ -476,8 +476,8 @@ function createVideoRoomSubscriber(session, roomId, streams, opts) {
|
|
|
476
476
|
});
|
|
477
477
|
});
|
|
478
478
|
},
|
|
479
|
-
restart(
|
|
480
|
-
return __awaiter(this,
|
|
479
|
+
restart() {
|
|
480
|
+
return __awaiter(this, arguments, void 0, function* (mediaOptions = options.mediaOptions) {
|
|
481
481
|
const response = yield handle.sendAsyncRequest({
|
|
482
482
|
message: {
|
|
483
483
|
request: "configure",
|
|
@@ -588,8 +588,8 @@ function createStreamingSubscriber(session, mountPointId, options) {
|
|
|
588
588
|
mountPointId = newMountPointId;
|
|
589
589
|
});
|
|
590
590
|
},
|
|
591
|
-
restart(
|
|
592
|
-
return __awaiter(this,
|
|
591
|
+
restart() {
|
|
592
|
+
return __awaiter(this, arguments, void 0, function* (newOptions = options) {
|
|
593
593
|
const response = yield handle.sendAsyncRequest({
|
|
594
594
|
message: Object.assign(Object.assign({}, newOptions === null || newOptions === void 0 ? void 0 : newOptions.watchOptions), { request: "watch", id: mountPointId }),
|
|
595
595
|
expectResponse: r => { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "preparing"; }
|
|
@@ -630,7 +630,7 @@ function handleOffer(handle, offerJsep, mediaOptions) {
|
|
|
630
630
|
expectResponse: r => {
|
|
631
631
|
var _a;
|
|
632
632
|
return r.message.videoroom == "event" && r.message.started == "ok" ||
|
|
633
|
-
r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "
|
|
633
|
+
r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "started";
|
|
634
634
|
}
|
|
635
635
|
});
|
|
636
636
|
});
|
|
@@ -692,3 +692,4 @@ function makeEventTarget() {
|
|
|
692
692
|
}
|
|
693
693
|
};
|
|
694
694
|
}
|
|
695
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AA+IA,sDAOC;AAtJD;;;GAGG;AACH,mDAAoC;AACpC,IAAI,CA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CAAC,CAAA;YACnC,CAAC;QACL,CAAC;KACJ,CAAA;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "janus-simple-videoroom-client",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Provides a simple high-level API that makes it easy to work with the Janus VideoRoom plugin",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist/*"
|
|
8
|
+
"dist/*",
|
|
9
|
+
"src/*"
|
|
9
10
|
],
|
|
10
11
|
"scripts": {
|
|
11
12
|
"build": "tsc",
|
|
@@ -22,12 +23,12 @@
|
|
|
22
23
|
},
|
|
23
24
|
"homepage": "https://github.com/ken107/janus-videoroom-js#readme",
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"ts-loader": "^9.5.
|
|
26
|
-
"typescript": "^
|
|
27
|
-
"webpack": "^5.
|
|
28
|
-
"webpack-cli": "^
|
|
26
|
+
"ts-loader": "^9.5.4",
|
|
27
|
+
"typescript": "^5.9.3",
|
|
28
|
+
"webpack": "^5.104.1",
|
|
29
|
+
"webpack-cli": "^6.0.1"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"janus-gateway": "^1.
|
|
32
|
+
"janus-gateway": "^1.3.3"
|
|
32
33
|
}
|
|
33
34
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,862 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove this once janus.js properly imports webrtc-adapter.
|
|
3
|
+
* Currently janus npm package depends on webrtc-adapter but does not import it, and so it gets dropped during tree shaking.
|
|
4
|
+
*/
|
|
5
|
+
import adapter from "webrtc-adapter"
|
|
6
|
+
if (!(window as any).adapter) (window as any).adapter = adapter
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import Janus, { JanusJS } from "janus-gateway"
|
|
10
|
+
export { Janus }
|
|
11
|
+
|
|
12
|
+
type JanusMid = unknown
|
|
13
|
+
|
|
14
|
+
interface JanusMessage {
|
|
15
|
+
[key: string]: any
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface JanusMediaOptions {
|
|
19
|
+
tracks?: JanusJS.TrackOption[]
|
|
20
|
+
trickle?: boolean
|
|
21
|
+
stream?: MediaStream
|
|
22
|
+
customizeSdp?: (jsep: JanusJS.JSEP) => void
|
|
23
|
+
customizeRemoteSdp?: (jsep: JanusJS.JSEP) => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface JanusStreamSpec {
|
|
27
|
+
feed: unknown
|
|
28
|
+
mid?: JanusMid
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface JanusWatchOptions {
|
|
32
|
+
pin?: string
|
|
33
|
+
media?: string[]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface JanusPublishOptions {
|
|
37
|
+
audiocodec?: string
|
|
38
|
+
videocodec?: string
|
|
39
|
+
bitrate?: number
|
|
40
|
+
record?: boolean
|
|
41
|
+
filename?: string
|
|
42
|
+
display?: string
|
|
43
|
+
audio_level_average?: number
|
|
44
|
+
audio_active_packets?: number
|
|
45
|
+
descriptions?: {mid: JanusMid, description: string}[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface JanusPublisherConfigureOptions extends JanusPublishOptions {
|
|
49
|
+
keyframe?: boolean
|
|
50
|
+
streams?: Array<{
|
|
51
|
+
mid: JanusMid
|
|
52
|
+
keyframe?: boolean
|
|
53
|
+
send?: boolean
|
|
54
|
+
min_delay?: number
|
|
55
|
+
max_delay?: number
|
|
56
|
+
}>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface JanusSubscriberConfigureOptions {
|
|
60
|
+
mid?: JanusMid
|
|
61
|
+
send?: boolean
|
|
62
|
+
substream?: number
|
|
63
|
+
temporal?: number
|
|
64
|
+
fallback?: number
|
|
65
|
+
spatial_layer?: number
|
|
66
|
+
temporal_layer?: number
|
|
67
|
+
audio_level_average?: number
|
|
68
|
+
audio_active_packets?: number
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
export interface VideoRoomClient {
|
|
73
|
+
createSession(server: string|string[], options?: Partial<JanusJS.ConstructorOptions>): Promise<VideoRoomSession>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface VideoRoomSession {
|
|
77
|
+
eventTarget: ReturnType<typeof makeEventTarget>
|
|
78
|
+
isValid(): boolean
|
|
79
|
+
joinRoom(roomId: string|number): Promise<VideoRoom>
|
|
80
|
+
subscribe(roomId: string|number, streams: JanusStreamSpec[], options?: {mediaOptions?: JanusMediaOptions}): Promise<VideoRoomSubscriber>
|
|
81
|
+
watch(mountPointId: number, options?: {watchOptions?: JanusWatchOptions, mediaOptions?: JanusMediaOptions}): Promise<StreamingSubscriber>
|
|
82
|
+
attachToPlugin(plugin: string): Promise<JanusPluginHandleEx>
|
|
83
|
+
destroy(): Promise<void>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface VideoRoom {
|
|
87
|
+
roomId: string|number
|
|
88
|
+
pluginHandle: JanusPluginHandleEx
|
|
89
|
+
onPublisherAdded(callback: (publishers: unknown[]) => void): void
|
|
90
|
+
onPublisherRemoved(callback: (publisherId: unknown) => void): void
|
|
91
|
+
publish(options?: {publishOptions?: JanusPublishOptions, mediaOptions?: JanusMediaOptions}): Promise<VideoRoomPublisher>
|
|
92
|
+
subscribe(streams: JanusStreamSpec[], options?: {mediaOptions?: JanusMediaOptions}): Promise<VideoRoomSubscriber>
|
|
93
|
+
leave(): Promise<void>
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface VideoRoomPublisher {
|
|
97
|
+
publisherId: string|number
|
|
98
|
+
onTrackAdded(callback: (track: MediaStreamTrack) => void): void
|
|
99
|
+
onTrackRemoved(callback: (track: MediaStreamTrack) => void): void
|
|
100
|
+
configure(configureOptions: JanusPublisherConfigureOptions): Promise<void>
|
|
101
|
+
restart(mediaOptions?: JanusMediaOptions, publishOptions?: JanusPublishOptions): Promise<void>
|
|
102
|
+
unpublish(): Promise<void>
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface VideoRoomSubscriber {
|
|
106
|
+
pluginHandle: JanusPluginHandleEx
|
|
107
|
+
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
108
|
+
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
109
|
+
addStreams(streams: JanusStreamSpec[]): Promise<void>
|
|
110
|
+
removeStreams(streams: JanusStreamSpec[]): Promise<void>
|
|
111
|
+
pause(): Promise<void>
|
|
112
|
+
resume(): Promise<void>
|
|
113
|
+
configure(configureOptions: JanusSubscriberConfigureOptions): Promise<void>
|
|
114
|
+
restart(mediaOptions?: JanusMediaOptions): Promise<void>
|
|
115
|
+
unsubscribe(): Promise<void>
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface StreamingSubscriber {
|
|
119
|
+
pluginHandle: JanusPluginHandleEx
|
|
120
|
+
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
121
|
+
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
122
|
+
pause(): Promise<void>
|
|
123
|
+
resume(): Promise<void>
|
|
124
|
+
configure(configureOptions: JanusSubscriberConfigureOptions): Promise<void>
|
|
125
|
+
switch(mountPointId: number): Promise<void>
|
|
126
|
+
restart(options?: {watchOptions?: JanusWatchOptions, mediaOptions?: JanusMediaOptions}): Promise<void>
|
|
127
|
+
unsubscribe(): Promise<void>
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface JanusPluginHandleEx extends JanusJS.PluginHandle {
|
|
131
|
+
eventTarget: ReturnType<typeof makeEventTarget>
|
|
132
|
+
sendRequest(message: JanusMessage & {request: string}): Promise<JanusMessage>
|
|
133
|
+
sendAsyncRequest(options: {message: JanusMessage & {request: string}, jsep?: JanusJS.JSEP, expectResponse: (response: AsyncResponse) => boolean}): Promise<AsyncResponse>
|
|
134
|
+
handleRemoteJsep(params: JanusJS.PluginHandleRemoteJsepParam & {customizeSdp?: (jsep: JanusJS.JSEP) => void}): void
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface AsyncResponse {
|
|
138
|
+
message: JanusMessage
|
|
139
|
+
jsep?: JanusJS.JSEP
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
export async function createVideoRoomClient(options?: JanusJS.InitOptions): Promise<VideoRoomClient> {
|
|
145
|
+
await new Promise(f => Janus.init({...options, callback: f}))
|
|
146
|
+
|
|
147
|
+
// construct and return the VideoRoomClient object
|
|
148
|
+
return {
|
|
149
|
+
createSession: createVideoRoomSession
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
async function createVideoRoomSession(server: string|string[], options?: JanusJS.ConstructorOptions): Promise<VideoRoomSession> {
|
|
156
|
+
const eventTarget = makeEventTarget()
|
|
157
|
+
let session: JanusJS.Janus
|
|
158
|
+
|
|
159
|
+
await new Promise<void>(function(fulfill, reject) {
|
|
160
|
+
let resolved = false
|
|
161
|
+
session = new Janus({
|
|
162
|
+
...options,
|
|
163
|
+
server,
|
|
164
|
+
success() {
|
|
165
|
+
if (!resolved) {
|
|
166
|
+
fulfill()
|
|
167
|
+
resolved = true
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
//reconnected
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
error(err: unknown) {
|
|
174
|
+
if (!resolved) {
|
|
175
|
+
reject(err)
|
|
176
|
+
resolved = true
|
|
177
|
+
}
|
|
178
|
+
else if (typeof err == "string" && err.startsWith("Lost connection")) {
|
|
179
|
+
eventTarget.dispatchEvent(new CustomEvent("connectionLost"))
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
console.error(err)
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
// construct and return the VideoRoomSession object
|
|
189
|
+
return {
|
|
190
|
+
eventTarget,
|
|
191
|
+
isValid() {
|
|
192
|
+
return session.isConnected()
|
|
193
|
+
},
|
|
194
|
+
joinRoom(roomId) {
|
|
195
|
+
return joinVideoRoom(session, roomId)
|
|
196
|
+
},
|
|
197
|
+
subscribe(roomId, streams, options) {
|
|
198
|
+
return createVideoRoomSubscriber(session, roomId, streams, options)
|
|
199
|
+
},
|
|
200
|
+
watch(mountPointId, options) {
|
|
201
|
+
return createStreamingSubscriber(session, mountPointId, options)
|
|
202
|
+
},
|
|
203
|
+
attachToPlugin(plugin) {
|
|
204
|
+
return attachToPlugin(session, plugin)
|
|
205
|
+
},
|
|
206
|
+
async destroy() {
|
|
207
|
+
await new Promise<void>(function(fulfill, reject) {
|
|
208
|
+
session.destroy({
|
|
209
|
+
success: fulfill,
|
|
210
|
+
error: reject
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
async function attachToPlugin(session: JanusJS.Janus, plugin: string): Promise<JanusPluginHandleEx> {
|
|
220
|
+
const pendingRequests: {acceptResponse(response: AsyncResponse): boolean}[] = []
|
|
221
|
+
const eventTarget = makeEventTarget()
|
|
222
|
+
|
|
223
|
+
const handle: JanusPluginHandleEx = await new Promise(function(fulfill, reject) {
|
|
224
|
+
session.attach({
|
|
225
|
+
plugin,
|
|
226
|
+
success(handle) {
|
|
227
|
+
fulfill(handle as JanusPluginHandleEx)
|
|
228
|
+
},
|
|
229
|
+
error: reject,
|
|
230
|
+
consentDialog(state: unknown) {
|
|
231
|
+
eventTarget.dispatchEvent(new CustomEvent("consentDialog", {detail: {state}}))
|
|
232
|
+
},
|
|
233
|
+
webrtcState(state: unknown) {
|
|
234
|
+
eventTarget.dispatchEvent(new CustomEvent("webrtcState", {detail: {state}}))
|
|
235
|
+
},
|
|
236
|
+
iceState(state: unknown) {
|
|
237
|
+
eventTarget.dispatchEvent(new CustomEvent("iceState", {detail: {state}}))
|
|
238
|
+
},
|
|
239
|
+
mediaState(state: unknown) {
|
|
240
|
+
eventTarget.dispatchEvent(new CustomEvent("mediaState", {detail: {state}}))
|
|
241
|
+
},
|
|
242
|
+
slowLink(state: unknown) {
|
|
243
|
+
eventTarget.dispatchEvent(new CustomEvent("slowLink", {detail: {state}}))
|
|
244
|
+
},
|
|
245
|
+
onmessage(message: JanusMessage, jsep?: JanusJS.JSEP) {
|
|
246
|
+
const response = {message, jsep}
|
|
247
|
+
const index = pendingRequests.findIndex(x => x.acceptResponse(response))
|
|
248
|
+
if (index != -1) pendingRequests.splice(index, 1)
|
|
249
|
+
else eventTarget.dispatchEvent(new CustomEvent("message", {detail: {message, jsep}}))
|
|
250
|
+
},
|
|
251
|
+
onlocaltrack(track: MediaStreamTrack, added: boolean) {
|
|
252
|
+
eventTarget.dispatchEvent(new CustomEvent("localtrack", {detail: {track, added}}))
|
|
253
|
+
},
|
|
254
|
+
onremotetrack(track: MediaStreamTrack, mid: JanusMid, added: boolean) {
|
|
255
|
+
eventTarget.dispatchEvent(new CustomEvent("remotetrack", {detail: {track, mid, added}}))
|
|
256
|
+
},
|
|
257
|
+
ondataopen(label: unknown, protocol: unknown) {
|
|
258
|
+
eventTarget.dispatchEvent(new CustomEvent("dataopen", {detail: {label, protocol}}))
|
|
259
|
+
},
|
|
260
|
+
ondata(data: unknown, label: unknown) {
|
|
261
|
+
eventTarget.dispatchEvent(new CustomEvent("data", {detail: {data, label}}))
|
|
262
|
+
},
|
|
263
|
+
oncleanup() {
|
|
264
|
+
eventTarget.dispatchEvent(new CustomEvent("cleanup"))
|
|
265
|
+
},
|
|
266
|
+
ondetached() {
|
|
267
|
+
eventTarget.dispatchEvent(new CustomEvent("detached"))
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
// extend the handle to add convenience methods
|
|
273
|
+
handle.eventTarget = eventTarget
|
|
274
|
+
|
|
275
|
+
// method to send a synchrnous request to the plugin
|
|
276
|
+
handle.sendRequest = function(message) {
|
|
277
|
+
return new Promise(function(fulfill, reject) {
|
|
278
|
+
handle.send({
|
|
279
|
+
message,
|
|
280
|
+
success: fulfill,
|
|
281
|
+
error: reject
|
|
282
|
+
})
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// method to send an asynchronous request to the plugin
|
|
287
|
+
let pending: Promise<unknown> = Promise.resolve()
|
|
288
|
+
handle.sendAsyncRequest = function(request) {
|
|
289
|
+
const promise = pending.catch(function() {})
|
|
290
|
+
.then(async function() {
|
|
291
|
+
await new Promise(function(fulfill, reject) {
|
|
292
|
+
handle.send({
|
|
293
|
+
message: request.message,
|
|
294
|
+
jsep: request.jsep,
|
|
295
|
+
success: fulfill,
|
|
296
|
+
error: reject
|
|
297
|
+
})
|
|
298
|
+
})
|
|
299
|
+
return new Promise<AsyncResponse>(function(fulfill, reject) {
|
|
300
|
+
pendingRequests.push({
|
|
301
|
+
acceptResponse(response) {
|
|
302
|
+
if ((response.message.videoroom == "event" || response.message.streaming == "event") && response.message.error_code) {
|
|
303
|
+
const err: Error & {code?: unknown} = new Error(response.message.error || response.message.error_code)
|
|
304
|
+
err.code = response.message.error_code
|
|
305
|
+
reject(err)
|
|
306
|
+
return true
|
|
307
|
+
}
|
|
308
|
+
else if (request.expectResponse(response)) {
|
|
309
|
+
fulfill(response)
|
|
310
|
+
return true
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
return false
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
})
|
|
317
|
+
})
|
|
318
|
+
})
|
|
319
|
+
pending = promise
|
|
320
|
+
return promise
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return handle
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
async function joinVideoRoom(session: JanusJS.Janus, roomId: string|number): Promise<VideoRoom> {
|
|
329
|
+
const cleanup = makeCleanup()
|
|
330
|
+
const callbacks = makeCallbacks()
|
|
331
|
+
|
|
332
|
+
try {
|
|
333
|
+
// attach to plugin and get a new handle for this room
|
|
334
|
+
const handle = await attachToPlugin(session, "janus.plugin.videoroom")
|
|
335
|
+
|
|
336
|
+
// remember to detach
|
|
337
|
+
cleanup.add(async function() {
|
|
338
|
+
await new Promise<void>(function(fulfill, reject) {
|
|
339
|
+
handle.detach({
|
|
340
|
+
success: fulfill,
|
|
341
|
+
error: reject
|
|
342
|
+
})
|
|
343
|
+
})
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
// listen to events and invoke callbacks
|
|
347
|
+
handle.eventTarget.addEventListener("message", function(event) {
|
|
348
|
+
const message = event.detail.message
|
|
349
|
+
if (message.videoroom == "event" && message.room == roomId) {
|
|
350
|
+
if (message.publishers) {
|
|
351
|
+
callbacks.get("onPublisherAdded")
|
|
352
|
+
.then(callback => callback(message.publishers))
|
|
353
|
+
.catch(console.error)
|
|
354
|
+
}
|
|
355
|
+
if (message.unpublished) {
|
|
356
|
+
callbacks.get("onPublisherRemoved")
|
|
357
|
+
.then(callback => callback(message.unpublished))
|
|
358
|
+
.catch(console.error)
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
// send the join request
|
|
364
|
+
const response = await handle.sendAsyncRequest({
|
|
365
|
+
message: {
|
|
366
|
+
request: "join",
|
|
367
|
+
ptype: "publisher",
|
|
368
|
+
room: roomId,
|
|
369
|
+
},
|
|
370
|
+
expectResponse: r => r.message.videoroom == "joined" && r.message.room == roomId
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
// invoke callback with the initial list of publishers
|
|
374
|
+
if (response.message.publishers.length) {
|
|
375
|
+
callbacks.get("onPublisherAdded")
|
|
376
|
+
.then(callback => callback(response.message.publishers))
|
|
377
|
+
.catch(console.error)
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// construct and return the VideoRoom object
|
|
381
|
+
return {
|
|
382
|
+
roomId,
|
|
383
|
+
pluginHandle: handle,
|
|
384
|
+
onPublisherAdded(callback) {
|
|
385
|
+
callbacks.set("onPublisherAdded", callback)
|
|
386
|
+
},
|
|
387
|
+
onPublisherRemoved(callback) {
|
|
388
|
+
callbacks.set("onPublisherRemoved", callback)
|
|
389
|
+
},
|
|
390
|
+
publish(options) {
|
|
391
|
+
return createVideoRoomPublisher(handle, response.message.id, options)
|
|
392
|
+
},
|
|
393
|
+
subscribe(streams, options) {
|
|
394
|
+
return createVideoRoomSubscriber(session, roomId, streams, options)
|
|
395
|
+
},
|
|
396
|
+
async leave() {
|
|
397
|
+
await cleanup.run()
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
catch (err) {
|
|
402
|
+
await cleanup.run().catch(console.error)
|
|
403
|
+
throw err
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
async function createVideoRoomPublisher(
|
|
410
|
+
handle: JanusPluginHandleEx,
|
|
411
|
+
publisherId: string|number,
|
|
412
|
+
opts?: {
|
|
413
|
+
publishOptions?: JanusPublishOptions,
|
|
414
|
+
mediaOptions?: JanusMediaOptions
|
|
415
|
+
}
|
|
416
|
+
): Promise<VideoRoomPublisher> {
|
|
417
|
+
|
|
418
|
+
const options = {...opts}
|
|
419
|
+
const cleanup = makeCleanup()
|
|
420
|
+
const callbacks = makeCallbacks()
|
|
421
|
+
|
|
422
|
+
// listen to events and invoke callbacks
|
|
423
|
+
const onLocalTrack = function(event: CustomEvent) {
|
|
424
|
+
if (event.detail.added) {
|
|
425
|
+
callbacks.get("onTrackAdded")
|
|
426
|
+
.then(callback => callback(event.detail.track))
|
|
427
|
+
.catch(console.error)
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
callbacks.get("onTrackRemoved")
|
|
431
|
+
.then(callback => callback(event.detail.track))
|
|
432
|
+
.catch(console.error)
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
handle.eventTarget.addEventListener("localtrack", onLocalTrack)
|
|
436
|
+
|
|
437
|
+
// remember to remove the event listener
|
|
438
|
+
cleanup.add(function() {
|
|
439
|
+
handle.eventTarget.removeEventListener("localtrack", onLocalTrack)
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
try {
|
|
443
|
+
// send the publish request
|
|
444
|
+
const offerJsep = await new Promise<JanusJS.JSEP>(function(fulfill, reject) {
|
|
445
|
+
// the offer (local) sdp can be customized via mediaOptions.customizeSdp
|
|
446
|
+
handle.createOffer({
|
|
447
|
+
...options.mediaOptions,
|
|
448
|
+
success: fulfill,
|
|
449
|
+
error: reject
|
|
450
|
+
})
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
const response = await handle.sendAsyncRequest({
|
|
454
|
+
message: {
|
|
455
|
+
...options.publishOptions,
|
|
456
|
+
request: "publish"
|
|
457
|
+
},
|
|
458
|
+
jsep: offerJsep,
|
|
459
|
+
expectResponse: r => r.message.videoroom == "event" && r.message.configured == "ok"
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
// remember to unpublish
|
|
463
|
+
cleanup.add(async function() {
|
|
464
|
+
await handle.sendAsyncRequest({
|
|
465
|
+
message: {request: "unpublish"},
|
|
466
|
+
expectResponse: r => r.message.videoroom == "event" && r.message.unpublished == "ok"
|
|
467
|
+
})
|
|
468
|
+
})
|
|
469
|
+
|
|
470
|
+
// handle the answer JSEP
|
|
471
|
+
await new Promise(function(fulfill, reject) {
|
|
472
|
+
handle.handleRemoteJsep({
|
|
473
|
+
jsep: response.jsep!,
|
|
474
|
+
success: fulfill,
|
|
475
|
+
error: reject,
|
|
476
|
+
customizeSdp: options.mediaOptions?.customizeRemoteSdp
|
|
477
|
+
})
|
|
478
|
+
})
|
|
479
|
+
|
|
480
|
+
// construct and return the VideoRoomPublisher object
|
|
481
|
+
return {
|
|
482
|
+
publisherId,
|
|
483
|
+
onTrackAdded(callback) {
|
|
484
|
+
callbacks.set("onTrackAdded", callback)
|
|
485
|
+
},
|
|
486
|
+
onTrackRemoved(callback) {
|
|
487
|
+
callbacks.set("onTrackRemoved", callback)
|
|
488
|
+
},
|
|
489
|
+
async configure(configureOptions) {
|
|
490
|
+
await handle.sendAsyncRequest({
|
|
491
|
+
message: {
|
|
492
|
+
...configureOptions,
|
|
493
|
+
request: "configure"
|
|
494
|
+
},
|
|
495
|
+
expectResponse: r => r.message.videoroom == "event" && r.message.configured == "ok"
|
|
496
|
+
})
|
|
497
|
+
},
|
|
498
|
+
async restart(mediaOptions = options.mediaOptions, publishOptions) {
|
|
499
|
+
const offerJsep = await new Promise<JanusJS.JSEP>(function(fulfill, reject) {
|
|
500
|
+
handle.createOffer({
|
|
501
|
+
...mediaOptions,
|
|
502
|
+
success: fulfill,
|
|
503
|
+
error: reject
|
|
504
|
+
})
|
|
505
|
+
})
|
|
506
|
+
const response = await handle.sendAsyncRequest({
|
|
507
|
+
message: {
|
|
508
|
+
...publishOptions,
|
|
509
|
+
request: "configure",
|
|
510
|
+
},
|
|
511
|
+
jsep: offerJsep,
|
|
512
|
+
expectResponse: r => r.message.videoroom == "event" && r.message.configured == "ok"
|
|
513
|
+
})
|
|
514
|
+
await new Promise(function(fulfill, reject) {
|
|
515
|
+
handle.handleRemoteJsep({
|
|
516
|
+
jsep: response.jsep!,
|
|
517
|
+
customizeSdp: mediaOptions?.customizeRemoteSdp,
|
|
518
|
+
success: fulfill,
|
|
519
|
+
error: reject
|
|
520
|
+
})
|
|
521
|
+
})
|
|
522
|
+
options.mediaOptions = mediaOptions
|
|
523
|
+
},
|
|
524
|
+
async unpublish() {
|
|
525
|
+
await cleanup.run()
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
catch (err) {
|
|
530
|
+
await cleanup.run().catch(console.error)
|
|
531
|
+
throw err
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
async function createVideoRoomSubscriber(
|
|
538
|
+
session: JanusJS.Janus,
|
|
539
|
+
roomId: string|number,
|
|
540
|
+
streams: JanusStreamSpec[],
|
|
541
|
+
opts?: {
|
|
542
|
+
mediaOptions?: JanusMediaOptions
|
|
543
|
+
}
|
|
544
|
+
): Promise<VideoRoomSubscriber> {
|
|
545
|
+
|
|
546
|
+
const options = {...opts}
|
|
547
|
+
const cleanup = makeCleanup()
|
|
548
|
+
const callbacks = makeCallbacks()
|
|
549
|
+
|
|
550
|
+
try {
|
|
551
|
+
// attach to plugin and get a separate handle for this subscriber
|
|
552
|
+
const handle = await attachToPlugin(session, "janus.plugin.videoroom")
|
|
553
|
+
|
|
554
|
+
// remember to detach
|
|
555
|
+
cleanup.add(async function() {
|
|
556
|
+
await new Promise<void>(function(fulfill, reject) {
|
|
557
|
+
handle.detach({
|
|
558
|
+
success: fulfill,
|
|
559
|
+
error: reject
|
|
560
|
+
})
|
|
561
|
+
})
|
|
562
|
+
})
|
|
563
|
+
|
|
564
|
+
// listen to events and invoke callbacks
|
|
565
|
+
handle.eventTarget.addEventListener("remotetrack", function(event) {
|
|
566
|
+
if (event.detail.added) {
|
|
567
|
+
callbacks.get("onTrackAdded")
|
|
568
|
+
.then(callback => callback(event.detail.track, event.detail.mid))
|
|
569
|
+
.catch(console.error)
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
callbacks.get("onTrackRemoved")
|
|
573
|
+
.then(callback => callback(event.detail.track, event.detail.mid))
|
|
574
|
+
.catch(console.error)
|
|
575
|
+
}
|
|
576
|
+
})
|
|
577
|
+
|
|
578
|
+
// join the room as a subscriber
|
|
579
|
+
const response = await handle.sendAsyncRequest({
|
|
580
|
+
message: {
|
|
581
|
+
request: "join",
|
|
582
|
+
ptype: "subscriber",
|
|
583
|
+
room: roomId,
|
|
584
|
+
streams
|
|
585
|
+
},
|
|
586
|
+
expectResponse: r => r.message.videoroom == "attached" && r.message.room == roomId
|
|
587
|
+
})
|
|
588
|
+
|
|
589
|
+
if (!response.jsep) throw new Error("Missing offer Jsep")
|
|
590
|
+
await handleOffer(handle, response.jsep, options.mediaOptions)
|
|
591
|
+
|
|
592
|
+
// construct and return the VideoRoomSubscriber object
|
|
593
|
+
return {
|
|
594
|
+
pluginHandle: handle,
|
|
595
|
+
onTrackAdded(callback) {
|
|
596
|
+
callbacks.set("onTrackAdded", callback)
|
|
597
|
+
},
|
|
598
|
+
onTrackRemoved(callback) {
|
|
599
|
+
callbacks.set("onTrackRemoved", callback)
|
|
600
|
+
},
|
|
601
|
+
async addStreams(streams) {
|
|
602
|
+
const response = await handle.sendAsyncRequest({
|
|
603
|
+
message: {request: "subscribe", streams},
|
|
604
|
+
expectResponse: r => r.message.videoroom == "updated" && r.message.room == roomId
|
|
605
|
+
})
|
|
606
|
+
if (response.jsep) await handleOffer(handle, response.jsep, options.mediaOptions)
|
|
607
|
+
},
|
|
608
|
+
async removeStreams(streams) {
|
|
609
|
+
const response = await handle.sendAsyncRequest({
|
|
610
|
+
message: {request: "unsubscribe", streams},
|
|
611
|
+
expectResponse: r => r.message.videoroom == "updated" && r.message.room == roomId
|
|
612
|
+
})
|
|
613
|
+
if (response.jsep) await handleOffer(handle, response.jsep, options.mediaOptions)
|
|
614
|
+
},
|
|
615
|
+
async pause() {
|
|
616
|
+
await handle.sendAsyncRequest({
|
|
617
|
+
message: {request: "pause"},
|
|
618
|
+
expectResponse: r => r.message.videoroom == "event" && r.message.paused == "ok"
|
|
619
|
+
})
|
|
620
|
+
},
|
|
621
|
+
async resume() {
|
|
622
|
+
await handle.sendAsyncRequest({
|
|
623
|
+
message: {request: "start"},
|
|
624
|
+
expectResponse: r => r.message.videoroom == "event" && r.message.started == "ok"
|
|
625
|
+
})
|
|
626
|
+
},
|
|
627
|
+
async configure(configureOptions) {
|
|
628
|
+
await handle.sendAsyncRequest({
|
|
629
|
+
message: {
|
|
630
|
+
...configureOptions,
|
|
631
|
+
request: "configure",
|
|
632
|
+
restart: false
|
|
633
|
+
},
|
|
634
|
+
expectResponse: r => r.message.videoroom == "event" && r.message.configured == "ok"
|
|
635
|
+
})
|
|
636
|
+
},
|
|
637
|
+
async restart(mediaOptions = options.mediaOptions) {
|
|
638
|
+
const response = await handle.sendAsyncRequest({
|
|
639
|
+
message: {
|
|
640
|
+
request: "configure",
|
|
641
|
+
restart: true
|
|
642
|
+
},
|
|
643
|
+
expectResponse: r => r.message.videoroom == "event" && r.message.configured == "ok"
|
|
644
|
+
})
|
|
645
|
+
if (!response.jsep) throw new Error("Missing offer Jsep")
|
|
646
|
+
await handleOffer(handle, response.jsep, mediaOptions)
|
|
647
|
+
options.mediaOptions = mediaOptions
|
|
648
|
+
},
|
|
649
|
+
async unsubscribe() {
|
|
650
|
+
await cleanup.run()
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
catch (err) {
|
|
655
|
+
await cleanup.run().catch(console.error)
|
|
656
|
+
throw err
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
async function createStreamingSubscriber(
|
|
663
|
+
session: JanusJS.Janus,
|
|
664
|
+
mountPointId: number,
|
|
665
|
+
options?: {
|
|
666
|
+
watchOptions?: JanusWatchOptions
|
|
667
|
+
mediaOptions?: JanusMediaOptions
|
|
668
|
+
}
|
|
669
|
+
): Promise<StreamingSubscriber> {
|
|
670
|
+
|
|
671
|
+
const cleanup = makeCleanup()
|
|
672
|
+
const callbacks = makeCallbacks()
|
|
673
|
+
|
|
674
|
+
try {
|
|
675
|
+
// attach to the streaming plugin
|
|
676
|
+
const handle = await attachToPlugin(session, "janus.plugin.streaming")
|
|
677
|
+
|
|
678
|
+
// remember to detach
|
|
679
|
+
cleanup.add(async function() {
|
|
680
|
+
await new Promise<void>(function(fulfill, reject) {
|
|
681
|
+
handle.detach({
|
|
682
|
+
success: fulfill,
|
|
683
|
+
error: reject
|
|
684
|
+
})
|
|
685
|
+
})
|
|
686
|
+
})
|
|
687
|
+
|
|
688
|
+
// listen to events and invoke callbacks
|
|
689
|
+
handle.eventTarget.addEventListener("remotetrack", function(event) {
|
|
690
|
+
if (event.detail.added) {
|
|
691
|
+
callbacks.get("onTrackAdded")
|
|
692
|
+
.then(callback => callback(event.detail.track, event.detail.mid))
|
|
693
|
+
.catch(console.error)
|
|
694
|
+
}
|
|
695
|
+
else {
|
|
696
|
+
callbacks.get("onTrackRemoved")
|
|
697
|
+
.then(callback => callback(event.detail.track, event.detail.mid))
|
|
698
|
+
.catch(console.error)
|
|
699
|
+
}
|
|
700
|
+
})
|
|
701
|
+
|
|
702
|
+
// send the watch request
|
|
703
|
+
const response = await handle.sendAsyncRequest({
|
|
704
|
+
message: {
|
|
705
|
+
...options?.watchOptions,
|
|
706
|
+
request: "watch",
|
|
707
|
+
id: mountPointId
|
|
708
|
+
},
|
|
709
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "preparing"
|
|
710
|
+
})
|
|
711
|
+
|
|
712
|
+
if (!response.jsep) throw new Error("Missing offer Jsep")
|
|
713
|
+
await handleOffer(handle, response.jsep, options?.mediaOptions)
|
|
714
|
+
|
|
715
|
+
// construct and return the StreamingSubscriber object
|
|
716
|
+
return {
|
|
717
|
+
pluginHandle: handle,
|
|
718
|
+
onTrackAdded(callback) {
|
|
719
|
+
callbacks.set("onTrackAdded", callback)
|
|
720
|
+
},
|
|
721
|
+
onTrackRemoved(callback) {
|
|
722
|
+
callbacks.set("onTrackRemoved", callback)
|
|
723
|
+
},
|
|
724
|
+
async pause() {
|
|
725
|
+
await handle.sendAsyncRequest({
|
|
726
|
+
message: {request: "pause"},
|
|
727
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "pausing"
|
|
728
|
+
})
|
|
729
|
+
},
|
|
730
|
+
async resume() {
|
|
731
|
+
await handle.sendAsyncRequest({
|
|
732
|
+
message: {request: "start"},
|
|
733
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "starting"
|
|
734
|
+
})
|
|
735
|
+
},
|
|
736
|
+
async configure(configureOptions) {
|
|
737
|
+
await handle.sendAsyncRequest({
|
|
738
|
+
message: {
|
|
739
|
+
...configureOptions,
|
|
740
|
+
request: "configure"
|
|
741
|
+
},
|
|
742
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.event == "configured"
|
|
743
|
+
})
|
|
744
|
+
},
|
|
745
|
+
async switch(newMountPointId) {
|
|
746
|
+
await handle.sendAsyncRequest({
|
|
747
|
+
message: {
|
|
748
|
+
request: "switch",
|
|
749
|
+
id: newMountPointId
|
|
750
|
+
},
|
|
751
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.switched == "ok"
|
|
752
|
+
})
|
|
753
|
+
mountPointId = newMountPointId
|
|
754
|
+
},
|
|
755
|
+
async restart(newOptions = options) {
|
|
756
|
+
const response = await handle.sendAsyncRequest({
|
|
757
|
+
message: {
|
|
758
|
+
...newOptions?.watchOptions,
|
|
759
|
+
request: "watch",
|
|
760
|
+
id: mountPointId
|
|
761
|
+
},
|
|
762
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "preparing"
|
|
763
|
+
})
|
|
764
|
+
if (!response.jsep) throw new Error("Missing offer Jsep")
|
|
765
|
+
await handleOffer(handle, response.jsep, newOptions?.mediaOptions)
|
|
766
|
+
options = newOptions
|
|
767
|
+
},
|
|
768
|
+
async unsubscribe() {
|
|
769
|
+
await cleanup.run()
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
catch (err) {
|
|
774
|
+
await cleanup.run().catch(console.error)
|
|
775
|
+
throw err
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
async function handleOffer(handle: JanusPluginHandleEx, offerJsep: JanusJS.JSEP, mediaOptions?: JanusMediaOptions): Promise<void> {
|
|
782
|
+
// allow customizing the remote (offer) sdp
|
|
783
|
+
if (mediaOptions?.customizeRemoteSdp) {
|
|
784
|
+
mediaOptions.customizeRemoteSdp(offerJsep)
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// create and send the answer
|
|
788
|
+
const answerJsep = await new Promise<JanusJS.JSEP>(function(fulfill, reject) {
|
|
789
|
+
// the answer (local) sdp can be customized via mediaOptions.customizeSdp
|
|
790
|
+
handle.createAnswer({
|
|
791
|
+
...mediaOptions,
|
|
792
|
+
jsep: offerJsep,
|
|
793
|
+
success: fulfill,
|
|
794
|
+
error: reject
|
|
795
|
+
})
|
|
796
|
+
})
|
|
797
|
+
|
|
798
|
+
await handle.sendAsyncRequest({
|
|
799
|
+
message: {request: "start"},
|
|
800
|
+
jsep: answerJsep,
|
|
801
|
+
expectResponse: r => r.message.videoroom == "event" && r.message.started == "ok" ||
|
|
802
|
+
r.message.streaming == "event" && r.message.result?.status == "started"
|
|
803
|
+
})
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
function makeCleanup() {
|
|
809
|
+
type Task = () => void|Promise<void>
|
|
810
|
+
const tasks: Task[] = []
|
|
811
|
+
return {
|
|
812
|
+
add(task: Task) {
|
|
813
|
+
tasks.push(task)
|
|
814
|
+
},
|
|
815
|
+
run() {
|
|
816
|
+
let promise = Promise.resolve()
|
|
817
|
+
for (let i=tasks.length-1; i>=0; i--) promise = promise.then(tasks[i])
|
|
818
|
+
return promise
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
function makeCallbacks() {
|
|
824
|
+
const pending: {[name: string]: {promise: Promise<Function>, fulfill: (callback: Function) => void}} = {}
|
|
825
|
+
const getPending = (name: string) => {
|
|
826
|
+
if (!pending[name]) {
|
|
827
|
+
let fulfill = function(_: Function) {}
|
|
828
|
+
const promise = new Promise<Function>(f => fulfill = f)
|
|
829
|
+
pending[name] = {promise, fulfill}
|
|
830
|
+
}
|
|
831
|
+
return pending[name]
|
|
832
|
+
}
|
|
833
|
+
return {
|
|
834
|
+
get(name: string) {
|
|
835
|
+
return getPending(name).promise
|
|
836
|
+
},
|
|
837
|
+
set(name: string, value: Function) {
|
|
838
|
+
getPending(name).fulfill(value)
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
function makeEventTarget() {
|
|
844
|
+
const listeners: {[name: string]: Function[]} = {}
|
|
845
|
+
return {
|
|
846
|
+
addEventListener(name: string, callback: (event: CustomEvent) => void) {
|
|
847
|
+
if (!listeners[name]) listeners[name] = []
|
|
848
|
+
listeners[name].push(callback)
|
|
849
|
+
},
|
|
850
|
+
removeEventListener(name: string, callback: (event: CustomEvent) => void) {
|
|
851
|
+
if (!listeners[name]) return
|
|
852
|
+
const index = listeners[name].indexOf(callback)
|
|
853
|
+
if (index >= 0) listeners[name].splice(index, 1)
|
|
854
|
+
},
|
|
855
|
+
dispatchEvent(event: Event) {
|
|
856
|
+
if (!listeners[event.type]) return
|
|
857
|
+
for (let i=0; i<listeners[event.type].length; i++) {
|
|
858
|
+
listeners[event.type][i](event)
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|