janus-simple-videoroom-client 1.0.2 → 1.0.4
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/README.md +9 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +17 -14
- package/dist/janus.d.ts +95 -0
- package/package.json +2 -2
- package/src/index.ts +15 -12
- package/tsconfig.json +1 -0
package/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# janus-simple-videoroom-client
|
|
2
2
|
Built on top of janus.js, this thin client library provides a simple high-level API that makes it easy to work with the Janus VideoRoom plugin.
|
|
3
3
|
|
|
4
|
+
## Install
|
|
5
|
+
`npm install janus-simple-videoroom-client`
|
|
6
|
+
|
|
4
7
|
## Usage
|
|
5
8
|
```javascript
|
|
9
|
+
import { createVideoRoomClient } from "janus-simple-videoroom-client"
|
|
10
|
+
|
|
6
11
|
async function joinRoom(server, roomId, displayName) {
|
|
7
12
|
const client = await createVideoRoomClient()
|
|
8
13
|
const session = await client.createSession(server)
|
|
@@ -45,7 +50,9 @@ Check out the [example](https://ken107.github.io/janus-videoroom-js/example.html
|
|
|
45
50
|
| -------- | ----------- |
|
|
46
51
|
| isValid() | Return whether the session is connected and valid |
|
|
47
52
|
| joinRoom(_roomId_) | Joins a room, returns a VideoRoom object |
|
|
53
|
+
| watch(_mountpointId_, _options_) | Subscribe to a streaming mountpoint, return a StreamingSubscriber object |
|
|
48
54
|
| attachToPlugin() | Attach to the VideoRoom plugin without joining a room, returns a JanusPluginHandleEx object |
|
|
55
|
+
| destroy() | Destroy the session |
|
|
49
56
|
|
|
50
57
|
### VideoRoom
|
|
51
58
|
|
|
@@ -62,6 +69,7 @@ Check out the [example](https://ken107.github.io/janus-videoroom-js/example.html
|
|
|
62
69
|
|
|
63
70
|
| Property | Description |
|
|
64
71
|
| -------- | ----------- |
|
|
72
|
+
| publisherId | |
|
|
65
73
|
| onTrackAdded(_callback_) | Register a callback for when a local MediaStreamTrack is available to display |
|
|
66
74
|
| onTrackRemoved(_callback_) | Register a callback for when a local MediaStreamTrack terminates |
|
|
67
75
|
| configure(_options_) | Modify publisher properties |
|
|
@@ -72,6 +80,7 @@ Check out the [example](https://ken107.github.io/janus-videoroom-js/example.html
|
|
|
72
80
|
|
|
73
81
|
| Property | Description |
|
|
74
82
|
| -------- | ----------- |
|
|
83
|
+
| pluginHandle | The JanusPluginHandleEx object associated with this subscriber |
|
|
75
84
|
| onTrackAdded(_callback_) | Register a callback for when a remote MediaStreamTrack is available to display |
|
|
76
85
|
| onTrackRemoved(_callback_) | Register a callback for when a remote MediaStreamTrack terminates |
|
|
77
86
|
| addStreams(_streams_) | Add additional streams to this (multi-stream) subscriber |
|
package/dist/index.d.ts
CHANGED
|
@@ -35,10 +35,11 @@ export interface VideoRoomPublisher {
|
|
|
35
35
|
onTrackAdded(callback: (track: MediaStreamTrack) => void): void;
|
|
36
36
|
onTrackRemoved(callback: (track: MediaStreamTrack) => void): void;
|
|
37
37
|
configure(configureOptions: JanusPublishOptions): Promise<void>;
|
|
38
|
-
restart(mediaOptions
|
|
38
|
+
restart(mediaOptions?: JanusMediaOptions): Promise<void>;
|
|
39
39
|
unpublish(): Promise<void>;
|
|
40
40
|
}
|
|
41
41
|
export interface VideoRoomSubscriber {
|
|
42
|
+
pluginHandle: JanusPluginHandleEx;
|
|
42
43
|
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
43
44
|
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
44
45
|
addStreams(streams: JanusStreamSpec[]): Promise<void>;
|
|
@@ -46,10 +47,11 @@ export interface VideoRoomSubscriber {
|
|
|
46
47
|
pause(): Promise<void>;
|
|
47
48
|
resume(): Promise<void>;
|
|
48
49
|
configure(configureOptions: JanusSubscriberConfigureOptions): Promise<void>;
|
|
49
|
-
restart(mediaOptions
|
|
50
|
+
restart(mediaOptions?: JanusMediaOptions): Promise<void>;
|
|
50
51
|
unsubscribe(): Promise<void>;
|
|
51
52
|
}
|
|
52
53
|
export interface StreamingSubscriber {
|
|
54
|
+
pluginHandle: JanusPluginHandleEx;
|
|
53
55
|
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
54
56
|
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
55
57
|
pause(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -468,6 +468,7 @@ function createVideoRoomPublisher(handle, publisherId, opts) {
|
|
|
468
468
|
});
|
|
469
469
|
},
|
|
470
470
|
restart: function (mediaOptions) {
|
|
471
|
+
if (mediaOptions === void 0) { mediaOptions = options.mediaOptions; }
|
|
471
472
|
return __awaiter(this, void 0, void 0, function () {
|
|
472
473
|
var offerJsep, response;
|
|
473
474
|
return __generator(this, function (_a) {
|
|
@@ -489,6 +490,7 @@ function createVideoRoomPublisher(handle, publisherId, opts) {
|
|
|
489
490
|
return [4 /*yield*/, new Promise(function (fulfill, reject) {
|
|
490
491
|
handle.handleRemoteJsep({
|
|
491
492
|
jsep: response.jsep,
|
|
493
|
+
customizeSdp: mediaOptions === null || mediaOptions === void 0 ? void 0 : mediaOptions.customizeRemoteSdp,
|
|
492
494
|
success: fulfill,
|
|
493
495
|
error: reject
|
|
494
496
|
});
|
|
@@ -593,6 +595,7 @@ function createVideoRoomSubscriber(session, roomId, streams, opts) {
|
|
|
593
595
|
_a.sent();
|
|
594
596
|
// construct and return the VideoRoomSubscriber object
|
|
595
597
|
return [2 /*return*/, {
|
|
598
|
+
pluginHandle: handle_2,
|
|
596
599
|
onTrackAdded: function (callback) {
|
|
597
600
|
callbacks.set("onTrackAdded", callback);
|
|
598
601
|
},
|
|
@@ -687,6 +690,7 @@ function createVideoRoomSubscriber(session, roomId, streams, opts) {
|
|
|
687
690
|
});
|
|
688
691
|
},
|
|
689
692
|
restart: function (mediaOptions) {
|
|
693
|
+
if (mediaOptions === void 0) { mediaOptions = options.mediaOptions; }
|
|
690
694
|
return __awaiter(this, void 0, void 0, function () {
|
|
691
695
|
var response;
|
|
692
696
|
return __generator(this, function (_a) {
|
|
@@ -735,13 +739,12 @@ function createVideoRoomSubscriber(session, roomId, streams, opts) {
|
|
|
735
739
|
});
|
|
736
740
|
});
|
|
737
741
|
}
|
|
738
|
-
function createStreamingSubscriber(session, mountPointId,
|
|
742
|
+
function createStreamingSubscriber(session, mountPointId, options) {
|
|
739
743
|
return __awaiter(this, void 0, void 0, function () {
|
|
740
|
-
var
|
|
744
|
+
var cleanup, callbacks, handle_3, response, err_4;
|
|
741
745
|
return __generator(this, function (_a) {
|
|
742
746
|
switch (_a.label) {
|
|
743
747
|
case 0:
|
|
744
|
-
options = __assign({}, opts);
|
|
745
748
|
cleanup = makeCleanup();
|
|
746
749
|
callbacks = makeCallbacks();
|
|
747
750
|
_a.label = 1;
|
|
@@ -784,20 +787,21 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
784
787
|
}
|
|
785
788
|
});
|
|
786
789
|
return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
787
|
-
message: __assign(__assign({}, options.watchOptions), { request: "watch", id: mountPointId }),
|
|
790
|
+
message: __assign(__assign({}, options === null || options === void 0 ? void 0 : options.watchOptions), { request: "watch", id: mountPointId }),
|
|
788
791
|
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "preparing"; }
|
|
789
792
|
})];
|
|
790
793
|
case 3:
|
|
791
794
|
response = _a.sent();
|
|
792
795
|
if (!response.jsep)
|
|
793
796
|
throw new Error("Missing offer Jsep");
|
|
794
|
-
return [4 /*yield*/, handleOffer(handle_3, response.jsep, options.mediaOptions)
|
|
797
|
+
return [4 /*yield*/, handleOffer(handle_3, response.jsep, options === null || options === void 0 ? void 0 : options.mediaOptions)
|
|
795
798
|
// construct and return the StreamingSubscriber object
|
|
796
799
|
];
|
|
797
800
|
case 4:
|
|
798
801
|
_a.sent();
|
|
799
802
|
// construct and return the StreamingSubscriber object
|
|
800
803
|
return [2 /*return*/, {
|
|
804
|
+
pluginHandle: handle_3,
|
|
801
805
|
onTrackAdded: function (callback) {
|
|
802
806
|
callbacks.set("onTrackAdded", callback);
|
|
803
807
|
},
|
|
@@ -868,22 +872,21 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
868
872
|
});
|
|
869
873
|
});
|
|
870
874
|
},
|
|
871
|
-
restart: function (
|
|
875
|
+
restart: function (newOptions) {
|
|
876
|
+
if (newOptions === void 0) { newOptions = options; }
|
|
872
877
|
return __awaiter(this, void 0, void 0, function () {
|
|
873
|
-
var
|
|
878
|
+
var response;
|
|
874
879
|
return __generator(this, function (_a) {
|
|
875
880
|
switch (_a.label) {
|
|
876
|
-
case 0:
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "preparing"; }
|
|
881
|
-
})];
|
|
881
|
+
case 0: return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
882
|
+
message: __assign(__assign({}, newOptions === null || newOptions === void 0 ? void 0 : newOptions.watchOptions), { request: "watch", id: mountPointId }),
|
|
883
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "preparing"; }
|
|
884
|
+
})];
|
|
882
885
|
case 1:
|
|
883
886
|
response = _a.sent();
|
|
884
887
|
if (!response.jsep)
|
|
885
888
|
throw new Error("Missing offer Jsep");
|
|
886
|
-
return [4 /*yield*/, handleOffer(handle_3, response.jsep, newOptions.mediaOptions)];
|
|
889
|
+
return [4 /*yield*/, handleOffer(handle_3, response.jsep, newOptions === null || newOptions === void 0 ? void 0 : newOptions.mediaOptions)];
|
|
887
890
|
case 2:
|
|
888
891
|
_a.sent();
|
|
889
892
|
options = newOptions;
|
package/dist/janus.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
|
|
2
|
+
declare global {
|
|
3
|
+
const Janus: {
|
|
4
|
+
new(options: unknown): JanusSession
|
|
5
|
+
init(options: unknown): void
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface JanusSession {
|
|
10
|
+
isConnected(): boolean
|
|
11
|
+
destroy(options: unknown): void
|
|
12
|
+
attach(options: unknown): void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface JanusPluginHandle {
|
|
16
|
+
createOffer(options: unknown): void
|
|
17
|
+
createAnswer(options: unknown): void
|
|
18
|
+
handleRemoteJsep(options: unknown): void
|
|
19
|
+
send(options: unknown): void
|
|
20
|
+
detach(options: unknown): void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type JanusMessage = {[key: string]: any}
|
|
24
|
+
|
|
25
|
+
interface Jsep {
|
|
26
|
+
sdp: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface JanusStreamSpec {
|
|
30
|
+
feed: unknown
|
|
31
|
+
mid?: JanusMid
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type JanusMid = unknown
|
|
35
|
+
|
|
36
|
+
interface JanusSessionOptions {
|
|
37
|
+
iceServers?: string[]
|
|
38
|
+
ipv6?: boolean
|
|
39
|
+
withCredentials?: boolean
|
|
40
|
+
max_poll_events?: number
|
|
41
|
+
destroyOnUnload?: boolean
|
|
42
|
+
token?: unknown
|
|
43
|
+
apisecret?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface JanusPublishOptions {
|
|
47
|
+
audiocodec?: string
|
|
48
|
+
videocodec?: string
|
|
49
|
+
bitrate?: number
|
|
50
|
+
record?: boolean
|
|
51
|
+
filename?: string
|
|
52
|
+
display?: string
|
|
53
|
+
audio_level_average?: number
|
|
54
|
+
audio_active_packets?: number
|
|
55
|
+
descriptions?: {mid: JanusMid, description: string}[]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface JanusWatchOptions {
|
|
59
|
+
pin?: string
|
|
60
|
+
media?: string[]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface JanusMediaOptions {
|
|
64
|
+
tracks?: JanusTrackSpec[]
|
|
65
|
+
trickle?: boolean
|
|
66
|
+
stream?: MediaStream
|
|
67
|
+
customizeSdp?: (jsep: Jsep) => void
|
|
68
|
+
customizeRemoteSdp?: (jsep: Jsep) => void
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface JanusTrackSpec {
|
|
72
|
+
type: string
|
|
73
|
+
mid?: JanusMid
|
|
74
|
+
capture?: boolean|string|{deviceId: unknown, width?: number, height?: number}
|
|
75
|
+
simulcast?: boolean
|
|
76
|
+
svc?: unknown
|
|
77
|
+
recv?: boolean
|
|
78
|
+
add?: boolean
|
|
79
|
+
replace?: boolean
|
|
80
|
+
remove?: boolean
|
|
81
|
+
dontStop?: boolean
|
|
82
|
+
transforms?: unknown
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface JanusSubscriberConfigureOptions {
|
|
86
|
+
mid?: JanusMid
|
|
87
|
+
send?: boolean
|
|
88
|
+
substream?: number
|
|
89
|
+
temporal?: number
|
|
90
|
+
fallback?: number
|
|
91
|
+
spatial_layer?: number
|
|
92
|
+
temporal_layer?: number
|
|
93
|
+
audio_level_average?: number
|
|
94
|
+
audio_active_packets?: number
|
|
95
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "janus-simple-videoroom-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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
|
"scripts": {
|
|
7
|
-
"build": "tsc"
|
|
7
|
+
"build": "tsc && cp src/janus.d.ts dist"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
package/src/index.ts
CHANGED
|
@@ -29,11 +29,12 @@ export interface VideoRoomPublisher {
|
|
|
29
29
|
onTrackAdded(callback: (track: MediaStreamTrack) => void): void
|
|
30
30
|
onTrackRemoved(callback: (track: MediaStreamTrack) => void): void
|
|
31
31
|
configure(configureOptions: JanusPublishOptions): Promise<void>
|
|
32
|
-
restart(mediaOptions
|
|
32
|
+
restart(mediaOptions?: JanusMediaOptions): Promise<void>
|
|
33
33
|
unpublish(): Promise<void>
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export interface VideoRoomSubscriber {
|
|
37
|
+
pluginHandle: JanusPluginHandleEx
|
|
37
38
|
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
38
39
|
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
39
40
|
addStreams(streams: JanusStreamSpec[]): Promise<void>
|
|
@@ -41,11 +42,12 @@ export interface VideoRoomSubscriber {
|
|
|
41
42
|
pause(): Promise<void>
|
|
42
43
|
resume(): Promise<void>
|
|
43
44
|
configure(configureOptions: JanusSubscriberConfigureOptions): Promise<void>
|
|
44
|
-
restart(mediaOptions
|
|
45
|
+
restart(mediaOptions?: JanusMediaOptions): Promise<void>
|
|
45
46
|
unsubscribe(): Promise<void>
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
export interface StreamingSubscriber {
|
|
50
|
+
pluginHandle: JanusPluginHandleEx
|
|
49
51
|
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
50
52
|
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
51
53
|
pause(): Promise<void>
|
|
@@ -426,7 +428,7 @@ async function createVideoRoomPublisher(
|
|
|
426
428
|
expectResponse: r => r.message.videoroom == "event" && r.message.configured == "ok"
|
|
427
429
|
})
|
|
428
430
|
},
|
|
429
|
-
async restart(mediaOptions) {
|
|
431
|
+
async restart(mediaOptions = options.mediaOptions) {
|
|
430
432
|
const offerJsep = await new Promise<Jsep>(function(fulfill, reject) {
|
|
431
433
|
handle.createOffer({
|
|
432
434
|
...mediaOptions,
|
|
@@ -444,6 +446,7 @@ async function createVideoRoomPublisher(
|
|
|
444
446
|
await new Promise(function(fulfill, reject) {
|
|
445
447
|
handle.handleRemoteJsep({
|
|
446
448
|
jsep: response.jsep,
|
|
449
|
+
customizeSdp: mediaOptions?.customizeRemoteSdp,
|
|
447
450
|
success: fulfill,
|
|
448
451
|
error: reject
|
|
449
452
|
})
|
|
@@ -520,6 +523,7 @@ async function createVideoRoomSubscriber(
|
|
|
520
523
|
|
|
521
524
|
// construct and return the VideoRoomSubscriber object
|
|
522
525
|
return {
|
|
526
|
+
pluginHandle: handle,
|
|
523
527
|
onTrackAdded(callback) {
|
|
524
528
|
callbacks.set("onTrackAdded", callback)
|
|
525
529
|
},
|
|
@@ -562,7 +566,7 @@ async function createVideoRoomSubscriber(
|
|
|
562
566
|
expectResponse: r => r.message.videoroom == "event" && r.message.configured == "ok"
|
|
563
567
|
})
|
|
564
568
|
},
|
|
565
|
-
async restart(mediaOptions) {
|
|
569
|
+
async restart(mediaOptions = options.mediaOptions) {
|
|
566
570
|
const response = await handle.sendAsyncRequest({
|
|
567
571
|
message: {
|
|
568
572
|
request: "configure",
|
|
@@ -590,13 +594,12 @@ async function createVideoRoomSubscriber(
|
|
|
590
594
|
async function createStreamingSubscriber(
|
|
591
595
|
session: JanusSession,
|
|
592
596
|
mountPointId: number,
|
|
593
|
-
|
|
597
|
+
options?: {
|
|
594
598
|
watchOptions?: JanusWatchOptions
|
|
595
599
|
mediaOptions?: JanusMediaOptions
|
|
596
600
|
}
|
|
597
601
|
): Promise<StreamingSubscriber> {
|
|
598
602
|
|
|
599
|
-
let options = {...opts}
|
|
600
603
|
const cleanup = makeCleanup()
|
|
601
604
|
const callbacks = makeCallbacks()
|
|
602
605
|
|
|
@@ -631,7 +634,7 @@ async function createStreamingSubscriber(
|
|
|
631
634
|
// send the watch request
|
|
632
635
|
const response = await handle.sendAsyncRequest({
|
|
633
636
|
message: {
|
|
634
|
-
...options
|
|
637
|
+
...options?.watchOptions,
|
|
635
638
|
request: "watch",
|
|
636
639
|
id: mountPointId
|
|
637
640
|
},
|
|
@@ -639,10 +642,11 @@ async function createStreamingSubscriber(
|
|
|
639
642
|
})
|
|
640
643
|
|
|
641
644
|
if (!response.jsep) throw new Error("Missing offer Jsep")
|
|
642
|
-
await handleOffer(handle, response.jsep, options
|
|
645
|
+
await handleOffer(handle, response.jsep, options?.mediaOptions)
|
|
643
646
|
|
|
644
647
|
// construct and return the StreamingSubscriber object
|
|
645
648
|
return {
|
|
649
|
+
pluginHandle: handle,
|
|
646
650
|
onTrackAdded(callback) {
|
|
647
651
|
callbacks.set("onTrackAdded", callback)
|
|
648
652
|
},
|
|
@@ -680,18 +684,17 @@ async function createStreamingSubscriber(
|
|
|
680
684
|
})
|
|
681
685
|
mountPointId = newMountPointId
|
|
682
686
|
},
|
|
683
|
-
async restart(
|
|
684
|
-
const newOptions = {...newOpts}
|
|
687
|
+
async restart(newOptions = options) {
|
|
685
688
|
const response = await handle.sendAsyncRequest({
|
|
686
689
|
message: {
|
|
687
|
-
...newOptions
|
|
690
|
+
...newOptions?.watchOptions,
|
|
688
691
|
request: "watch",
|
|
689
692
|
id: mountPointId
|
|
690
693
|
},
|
|
691
694
|
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "preparing"
|
|
692
695
|
})
|
|
693
696
|
if (!response.jsep) throw new Error("Missing offer Jsep")
|
|
694
|
-
await handleOffer(handle, response.jsep, newOptions
|
|
697
|
+
await handleOffer(handle, response.jsep, newOptions?.mediaOptions)
|
|
695
698
|
options = newOptions
|
|
696
699
|
},
|
|
697
700
|
async unsubscribe() {
|