janus-simple-videoroom-client 1.0.1 → 1.0.2
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.d.ts +8 -85
- package/dist/index.js +22 -12
- package/package.json +1 -1
- package/src/index.ts +37 -115
- package/src/janus.d.ts +87 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { JanusMediaOptions, JanusMessage, JanusMid, JanusPluginHandle, JanusPublishOptions, JanusSessionOptions, JanusStreamSpec, JanusSubscriberConfigureOptions, JanusWatchOptions, Jsep } from "./janus";
|
|
2
|
+
export interface VideoRoomClient {
|
|
2
3
|
createSession(server: string | string[], options?: JanusSessionOptions): Promise<VideoRoomSession>;
|
|
3
4
|
}
|
|
4
|
-
interface VideoRoomSession {
|
|
5
|
+
export interface VideoRoomSession {
|
|
5
6
|
eventTarget: ReturnType<typeof makeEventTarget>;
|
|
6
7
|
isValid(): boolean;
|
|
7
8
|
joinRoom(roomId: string | number): Promise<VideoRoom>;
|
|
@@ -15,7 +16,7 @@ interface VideoRoomSession {
|
|
|
15
16
|
attachToPlugin(plugin: string): Promise<JanusPluginHandleEx>;
|
|
16
17
|
destroy(): Promise<void>;
|
|
17
18
|
}
|
|
18
|
-
interface VideoRoom {
|
|
19
|
+
export interface VideoRoom {
|
|
19
20
|
roomId: string | number;
|
|
20
21
|
pluginHandle: JanusPluginHandleEx;
|
|
21
22
|
onPublisherAdded(callback: (publishers: unknown[]) => void): void;
|
|
@@ -29,7 +30,7 @@ interface VideoRoom {
|
|
|
29
30
|
}): Promise<VideoRoomSubscriber>;
|
|
30
31
|
leave(): Promise<void>;
|
|
31
32
|
}
|
|
32
|
-
interface VideoRoomPublisher {
|
|
33
|
+
export interface VideoRoomPublisher {
|
|
33
34
|
publisherId: string | number;
|
|
34
35
|
onTrackAdded(callback: (track: MediaStreamTrack) => void): void;
|
|
35
36
|
onTrackRemoved(callback: (track: MediaStreamTrack) => void): void;
|
|
@@ -37,7 +38,7 @@ interface VideoRoomPublisher {
|
|
|
37
38
|
restart(mediaOptions: JanusMediaOptions): Promise<void>;
|
|
38
39
|
unpublish(): Promise<void>;
|
|
39
40
|
}
|
|
40
|
-
interface VideoRoomSubscriber {
|
|
41
|
+
export interface VideoRoomSubscriber {
|
|
41
42
|
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
42
43
|
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
43
44
|
addStreams(streams: JanusStreamSpec[]): Promise<void>;
|
|
@@ -48,7 +49,7 @@ interface VideoRoomSubscriber {
|
|
|
48
49
|
restart(mediaOptions: JanusMediaOptions): Promise<void>;
|
|
49
50
|
unsubscribe(): Promise<void>;
|
|
50
51
|
}
|
|
51
|
-
interface StreamingSubscriber {
|
|
52
|
+
export interface StreamingSubscriber {
|
|
52
53
|
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
53
54
|
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
54
55
|
pause(): Promise<void>;
|
|
@@ -61,12 +62,7 @@ interface StreamingSubscriber {
|
|
|
61
62
|
}): Promise<void>;
|
|
62
63
|
unsubscribe(): Promise<void>;
|
|
63
64
|
}
|
|
64
|
-
interface JanusPluginHandleEx {
|
|
65
|
-
createOffer(options: unknown): void;
|
|
66
|
-
createAnswer(options: unknown): void;
|
|
67
|
-
handleRemoteJsep(options: unknown): void;
|
|
68
|
-
send(options: unknown): void;
|
|
69
|
-
detach(options: unknown): void;
|
|
65
|
+
export interface JanusPluginHandleEx extends JanusPluginHandle {
|
|
70
66
|
eventTarget: ReturnType<typeof makeEventTarget>;
|
|
71
67
|
sendRequest(message: JanusMessage): Promise<JanusMessage>;
|
|
72
68
|
sendAsyncRequest(options: {
|
|
@@ -79,79 +75,6 @@ interface AsyncResponse {
|
|
|
79
75
|
message: JanusMessage;
|
|
80
76
|
jsep?: Jsep;
|
|
81
77
|
}
|
|
82
|
-
type JanusMessage = {
|
|
83
|
-
[key: string]: any;
|
|
84
|
-
};
|
|
85
|
-
interface Jsep {
|
|
86
|
-
sdp: string;
|
|
87
|
-
}
|
|
88
|
-
interface JanusStreamSpec {
|
|
89
|
-
feed: unknown;
|
|
90
|
-
mid?: JanusMid;
|
|
91
|
-
}
|
|
92
|
-
type JanusMid = unknown;
|
|
93
|
-
interface JanusSessionOptions {
|
|
94
|
-
iceServers?: string[];
|
|
95
|
-
ipv6?: boolean;
|
|
96
|
-
withCredentials?: boolean;
|
|
97
|
-
max_poll_events?: number;
|
|
98
|
-
destroyOnUnload?: boolean;
|
|
99
|
-
token?: unknown;
|
|
100
|
-
apisecret?: string;
|
|
101
|
-
}
|
|
102
|
-
interface JanusPublishOptions {
|
|
103
|
-
audiocodec?: string;
|
|
104
|
-
videocodec?: string;
|
|
105
|
-
bitrate?: number;
|
|
106
|
-
record?: boolean;
|
|
107
|
-
filename?: string;
|
|
108
|
-
display?: string;
|
|
109
|
-
audio_level_average?: number;
|
|
110
|
-
audio_active_packets?: number;
|
|
111
|
-
descriptions?: {
|
|
112
|
-
mid: JanusMid;
|
|
113
|
-
description: string;
|
|
114
|
-
}[];
|
|
115
|
-
}
|
|
116
|
-
interface JanusWatchOptions {
|
|
117
|
-
pin?: string;
|
|
118
|
-
media?: string[];
|
|
119
|
-
}
|
|
120
|
-
interface JanusMediaOptions {
|
|
121
|
-
tracks?: JanusTrackSpec[];
|
|
122
|
-
trickle?: boolean;
|
|
123
|
-
stream?: MediaStream;
|
|
124
|
-
customizeSdp?: (jsep: Jsep) => void;
|
|
125
|
-
customizeRemoteSdp?: (jsep: Jsep) => void;
|
|
126
|
-
}
|
|
127
|
-
interface JanusTrackSpec {
|
|
128
|
-
type: string;
|
|
129
|
-
mid?: JanusMid;
|
|
130
|
-
capture?: boolean | string | {
|
|
131
|
-
deviceId: unknown;
|
|
132
|
-
width?: number;
|
|
133
|
-
height?: number;
|
|
134
|
-
};
|
|
135
|
-
simulcast?: boolean;
|
|
136
|
-
svc?: unknown;
|
|
137
|
-
recv?: boolean;
|
|
138
|
-
add?: boolean;
|
|
139
|
-
replace?: boolean;
|
|
140
|
-
remove?: boolean;
|
|
141
|
-
dontStop?: boolean;
|
|
142
|
-
transforms?: unknown;
|
|
143
|
-
}
|
|
144
|
-
interface JanusSubscriberConfigureOptions {
|
|
145
|
-
mid?: JanusMid;
|
|
146
|
-
send?: boolean;
|
|
147
|
-
substream?: number;
|
|
148
|
-
temporal?: number;
|
|
149
|
-
fallback?: number;
|
|
150
|
-
spatial_layer?: number;
|
|
151
|
-
temporal_layer?: number;
|
|
152
|
-
audio_level_average?: number;
|
|
153
|
-
audio_active_packets?: number;
|
|
154
|
-
}
|
|
155
78
|
export declare function createVideoRoomClient(options?: {
|
|
156
79
|
debug?: boolean | string[];
|
|
157
80
|
dependencies?: unknown;
|
package/dist/index.js
CHANGED
|
@@ -52,9 +52,12 @@ function createVideoRoomClient(options) {
|
|
|
52
52
|
return __awaiter(this, void 0, void 0, function () {
|
|
53
53
|
return __generator(this, function (_a) {
|
|
54
54
|
switch (_a.label) {
|
|
55
|
-
case 0: return [4 /*yield*/, new Promise(function (f) { return Janus.init(__assign(__assign({}, options), { callback: f })); })
|
|
55
|
+
case 0: return [4 /*yield*/, new Promise(function (f) { return Janus.init(__assign(__assign({}, options), { callback: f })); })
|
|
56
|
+
// construct and return the VideoRoomClient object
|
|
57
|
+
];
|
|
56
58
|
case 1:
|
|
57
59
|
_a.sent();
|
|
60
|
+
// construct and return the VideoRoomClient object
|
|
58
61
|
return [2 /*return*/, {
|
|
59
62
|
createSession: createVideoRoomSession
|
|
60
63
|
}];
|
|
@@ -92,9 +95,12 @@ function createVideoRoomSession(server, options) {
|
|
|
92
95
|
console.error(err);
|
|
93
96
|
}
|
|
94
97
|
} }));
|
|
95
|
-
})
|
|
98
|
+
})
|
|
99
|
+
// construct and return the VideoRoomSession object
|
|
100
|
+
];
|
|
96
101
|
case 1:
|
|
97
102
|
_a.sent();
|
|
103
|
+
// construct and return the VideoRoomSession object
|
|
98
104
|
return [2 /*return*/, {
|
|
99
105
|
eventTarget: eventTarget,
|
|
100
106
|
isValid: function () {
|
|
@@ -424,11 +430,12 @@ function createVideoRoomPublisher(handle, publisherId, opts) {
|
|
|
424
430
|
});
|
|
425
431
|
// handle the answer JSEP
|
|
426
432
|
return [4 /*yield*/, new Promise(function (fulfill, reject) {
|
|
433
|
+
var _a;
|
|
427
434
|
handle.handleRemoteJsep({
|
|
428
435
|
jsep: response_2.jsep,
|
|
429
436
|
success: fulfill,
|
|
430
437
|
error: reject,
|
|
431
|
-
customizeSdp: options.mediaOptions
|
|
438
|
+
customizeSdp: (_a = options.mediaOptions) === null || _a === void 0 ? void 0 : _a.customizeRemoteSdp
|
|
432
439
|
});
|
|
433
440
|
})
|
|
434
441
|
// construct and return the VideoRoomPublisher object
|
|
@@ -778,7 +785,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
778
785
|
});
|
|
779
786
|
return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
780
787
|
message: __assign(__assign({}, options.watchOptions), { request: "watch", id: mountPointId }),
|
|
781
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
788
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "preparing"; }
|
|
782
789
|
})];
|
|
783
790
|
case 3:
|
|
784
791
|
response = _a.sent();
|
|
@@ -803,7 +810,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
803
810
|
switch (_a.label) {
|
|
804
811
|
case 0: return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
805
812
|
message: { request: "pause" },
|
|
806
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
813
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "pausing"; }
|
|
807
814
|
})];
|
|
808
815
|
case 1:
|
|
809
816
|
_a.sent();
|
|
@@ -818,7 +825,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
818
825
|
switch (_a.label) {
|
|
819
826
|
case 0: return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
820
827
|
message: { request: "start" },
|
|
821
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
828
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "starting"; }
|
|
822
829
|
})];
|
|
823
830
|
case 1:
|
|
824
831
|
_a.sent();
|
|
@@ -833,7 +840,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
833
840
|
switch (_a.label) {
|
|
834
841
|
case 0: return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
835
842
|
message: __assign(__assign({}, configureOptions), { request: "configure" }),
|
|
836
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
843
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.event) == "configured"; }
|
|
837
844
|
})];
|
|
838
845
|
case 1:
|
|
839
846
|
_a.sent();
|
|
@@ -851,7 +858,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
851
858
|
request: "switch",
|
|
852
859
|
id: newMountPointId
|
|
853
860
|
},
|
|
854
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
861
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.switched) == "ok"; }
|
|
855
862
|
})];
|
|
856
863
|
case 1:
|
|
857
864
|
_a.sent();
|
|
@@ -870,7 +877,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
870
877
|
newOptions = __assign({}, newOpts);
|
|
871
878
|
return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
872
879
|
message: __assign(__assign({}, newOptions.watchOptions), { request: "watch", id: mountPointId }),
|
|
873
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
880
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "preparing"; }
|
|
874
881
|
})];
|
|
875
882
|
case 1:
|
|
876
883
|
response = _a.sent();
|
|
@@ -916,7 +923,7 @@ function handleOffer(handle, offerJsep, mediaOptions) {
|
|
|
916
923
|
switch (_a.label) {
|
|
917
924
|
case 0:
|
|
918
925
|
// allow customizing the remote (offer) sdp
|
|
919
|
-
if (mediaOptions
|
|
926
|
+
if (mediaOptions === null || mediaOptions === void 0 ? void 0 : mediaOptions.customizeRemoteSdp) {
|
|
920
927
|
mediaOptions.customizeRemoteSdp(offerJsep);
|
|
921
928
|
}
|
|
922
929
|
return [4 /*yield*/, new Promise(function (fulfill, reject) {
|
|
@@ -928,8 +935,11 @@ function handleOffer(handle, offerJsep, mediaOptions) {
|
|
|
928
935
|
return [4 /*yield*/, handle.sendAsyncRequest({
|
|
929
936
|
message: { request: "start" },
|
|
930
937
|
jsep: answerJsep,
|
|
931
|
-
expectResponse: function (r) {
|
|
932
|
-
|
|
938
|
+
expectResponse: function (r) {
|
|
939
|
+
var _a;
|
|
940
|
+
return r.message.videoroom == "event" && r.message.started == "ok" ||
|
|
941
|
+
r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "starting";
|
|
942
|
+
}
|
|
933
943
|
})];
|
|
934
944
|
case 2:
|
|
935
945
|
_a.sent();
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { JanusSession } from "./janus"
|
|
1
|
+
import { JanusMediaOptions, JanusMessage, JanusMid, JanusPluginHandle, JanusPublishOptions, JanusSession, JanusSessionOptions, JanusStreamSpec, JanusSubscriberConfigureOptions, JanusWatchOptions, Jsep } from "./janus"
|
|
2
2
|
|
|
3
|
-
interface VideoRoomClient {
|
|
3
|
+
export interface VideoRoomClient {
|
|
4
4
|
createSession(server: string|string[], options?: JanusSessionOptions): Promise<VideoRoomSession>
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
interface VideoRoomSession {
|
|
7
|
+
export interface VideoRoomSession {
|
|
8
8
|
eventTarget: ReturnType<typeof makeEventTarget>
|
|
9
9
|
isValid(): boolean
|
|
10
10
|
joinRoom(roomId: string|number): Promise<VideoRoom>
|
|
@@ -14,7 +14,7 @@ interface VideoRoomSession {
|
|
|
14
14
|
destroy(): Promise<void>
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
interface VideoRoom {
|
|
17
|
+
export interface VideoRoom {
|
|
18
18
|
roomId: string|number
|
|
19
19
|
pluginHandle: JanusPluginHandleEx
|
|
20
20
|
onPublisherAdded(callback: (publishers: unknown[]) => void): void
|
|
@@ -24,7 +24,7 @@ interface VideoRoom {
|
|
|
24
24
|
leave(): Promise<void>
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
interface VideoRoomPublisher {
|
|
27
|
+
export interface VideoRoomPublisher {
|
|
28
28
|
publisherId: string|number
|
|
29
29
|
onTrackAdded(callback: (track: MediaStreamTrack) => void): void
|
|
30
30
|
onTrackRemoved(callback: (track: MediaStreamTrack) => void): void
|
|
@@ -33,7 +33,7 @@ interface VideoRoomPublisher {
|
|
|
33
33
|
unpublish(): Promise<void>
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
interface VideoRoomSubscriber {
|
|
36
|
+
export interface VideoRoomSubscriber {
|
|
37
37
|
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
38
38
|
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
39
39
|
addStreams(streams: JanusStreamSpec[]): Promise<void>
|
|
@@ -45,7 +45,7 @@ interface VideoRoomSubscriber {
|
|
|
45
45
|
unsubscribe(): Promise<void>
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
interface StreamingSubscriber {
|
|
48
|
+
export interface StreamingSubscriber {
|
|
49
49
|
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
50
50
|
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void
|
|
51
51
|
pause(): Promise<void>
|
|
@@ -56,13 +56,7 @@ interface StreamingSubscriber {
|
|
|
56
56
|
unsubscribe(): Promise<void>
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
interface JanusPluginHandleEx {
|
|
60
|
-
createOffer(options: unknown): void
|
|
61
|
-
createAnswer(options: unknown): void
|
|
62
|
-
handleRemoteJsep(options: unknown): void
|
|
63
|
-
send(options: unknown): void
|
|
64
|
-
detach(options: unknown): void
|
|
65
|
-
|
|
59
|
+
export interface JanusPluginHandleEx extends JanusPluginHandle {
|
|
66
60
|
eventTarget: ReturnType<typeof makeEventTarget>
|
|
67
61
|
sendRequest(message: JanusMessage): Promise<JanusMessage>
|
|
68
62
|
sendAsyncRequest(options: {message: JanusMessage, jsep?: Jsep, expectResponse: (response: AsyncResponse) => boolean}): Promise<AsyncResponse>
|
|
@@ -73,80 +67,6 @@ interface AsyncResponse {
|
|
|
73
67
|
jsep?: Jsep
|
|
74
68
|
}
|
|
75
69
|
|
|
76
|
-
type JanusMessage = {[key: string]: any}
|
|
77
|
-
|
|
78
|
-
interface Jsep {
|
|
79
|
-
sdp: string
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
interface JanusStreamSpec {
|
|
83
|
-
feed: unknown
|
|
84
|
-
mid?: JanusMid
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
type JanusMid = unknown
|
|
88
|
-
|
|
89
|
-
interface JanusSessionOptions {
|
|
90
|
-
iceServers?: string[]
|
|
91
|
-
ipv6?: boolean
|
|
92
|
-
withCredentials?: boolean
|
|
93
|
-
max_poll_events?: number
|
|
94
|
-
destroyOnUnload?: boolean
|
|
95
|
-
token?: unknown
|
|
96
|
-
apisecret?: string
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
interface JanusPublishOptions {
|
|
100
|
-
audiocodec?: string
|
|
101
|
-
videocodec?: string
|
|
102
|
-
bitrate?: number
|
|
103
|
-
record?: boolean
|
|
104
|
-
filename?: string
|
|
105
|
-
display?: string
|
|
106
|
-
audio_level_average?: number
|
|
107
|
-
audio_active_packets?: number
|
|
108
|
-
descriptions?: {mid: JanusMid, description: string}[]
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
interface JanusWatchOptions {
|
|
112
|
-
pin?: string
|
|
113
|
-
media?: string[]
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
interface JanusMediaOptions {
|
|
117
|
-
tracks?: JanusTrackSpec[]
|
|
118
|
-
trickle?: boolean
|
|
119
|
-
stream?: MediaStream
|
|
120
|
-
customizeSdp?: (jsep: Jsep) => void
|
|
121
|
-
customizeRemoteSdp?: (jsep: Jsep) => void
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
interface JanusTrackSpec {
|
|
125
|
-
type: string
|
|
126
|
-
mid?: JanusMid
|
|
127
|
-
capture?: boolean|string|{deviceId: unknown, width?: number, height?: number}
|
|
128
|
-
simulcast?: boolean
|
|
129
|
-
svc?: unknown
|
|
130
|
-
recv?: boolean
|
|
131
|
-
add?: boolean
|
|
132
|
-
replace?: boolean
|
|
133
|
-
remove?: boolean
|
|
134
|
-
dontStop?: boolean
|
|
135
|
-
transforms?: unknown
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
interface JanusSubscriberConfigureOptions {
|
|
139
|
-
mid?: JanusMid
|
|
140
|
-
send?: boolean
|
|
141
|
-
substream?: number
|
|
142
|
-
temporal?: number
|
|
143
|
-
fallback?: number
|
|
144
|
-
spatial_layer?: number
|
|
145
|
-
temporal_layer?: number
|
|
146
|
-
audio_level_average?: number
|
|
147
|
-
audio_active_packets?: number
|
|
148
|
-
}
|
|
149
|
-
|
|
150
70
|
|
|
151
71
|
|
|
152
72
|
export async function createVideoRoomClient(
|
|
@@ -157,6 +77,7 @@ export async function createVideoRoomClient(
|
|
|
157
77
|
): Promise<VideoRoomClient> {
|
|
158
78
|
await new Promise(f => Janus.init({...options, callback: f}))
|
|
159
79
|
|
|
80
|
+
// construct and return the VideoRoomClient object
|
|
160
81
|
return {
|
|
161
82
|
createSession: createVideoRoomSession
|
|
162
83
|
}
|
|
@@ -197,6 +118,7 @@ async function createVideoRoomSession(server: string|string[], options?: JanusSe
|
|
|
197
118
|
})
|
|
198
119
|
})
|
|
199
120
|
|
|
121
|
+
// construct and return the VideoRoomSession object
|
|
200
122
|
return {
|
|
201
123
|
eventTarget,
|
|
202
124
|
isValid() {
|
|
@@ -233,41 +155,41 @@ async function attachToPlugin(session: JanusSession, plugin: string): Promise<Ja
|
|
|
233
155
|
|
|
234
156
|
const handle: JanusPluginHandleEx = await new Promise(function(fulfill, reject) {
|
|
235
157
|
session.attach({
|
|
236
|
-
plugin
|
|
158
|
+
plugin,
|
|
237
159
|
success: fulfill,
|
|
238
160
|
error: reject,
|
|
239
161
|
consentDialog(state: unknown) {
|
|
240
|
-
eventTarget.dispatchEvent(new CustomEvent("consentDialog", {detail: {state
|
|
162
|
+
eventTarget.dispatchEvent(new CustomEvent("consentDialog", {detail: {state}}))
|
|
241
163
|
},
|
|
242
164
|
webrtcState(state: unknown, reason: unknown) {
|
|
243
|
-
eventTarget.dispatchEvent(new CustomEvent("webrtcState", {detail: {state
|
|
165
|
+
eventTarget.dispatchEvent(new CustomEvent("webrtcState", {detail: {state, reason}}))
|
|
244
166
|
},
|
|
245
167
|
iceState(state: unknown) {
|
|
246
|
-
eventTarget.dispatchEvent(new CustomEvent("iceState", {detail: {state
|
|
168
|
+
eventTarget.dispatchEvent(new CustomEvent("iceState", {detail: {state}}))
|
|
247
169
|
},
|
|
248
170
|
mediaState(state: unknown) {
|
|
249
|
-
eventTarget.dispatchEvent(new CustomEvent("mediaState", {detail: {state
|
|
171
|
+
eventTarget.dispatchEvent(new CustomEvent("mediaState", {detail: {state}}))
|
|
250
172
|
},
|
|
251
173
|
slowLink(state: unknown) {
|
|
252
|
-
eventTarget.dispatchEvent(new CustomEvent("slowLink", {detail: {state
|
|
174
|
+
eventTarget.dispatchEvent(new CustomEvent("slowLink", {detail: {state}}))
|
|
253
175
|
},
|
|
254
176
|
onmessage(message: JanusMessage, jsep: Jsep) {
|
|
255
|
-
const response = {message
|
|
177
|
+
const response = {message, jsep}
|
|
256
178
|
const index = pendingRequests.findIndex(x => x.acceptResponse(response))
|
|
257
179
|
if (index != -1) pendingRequests.splice(index, 1)
|
|
258
|
-
else eventTarget.dispatchEvent(new CustomEvent("message", {detail: {message
|
|
180
|
+
else eventTarget.dispatchEvent(new CustomEvent("message", {detail: {message, jsep}}))
|
|
259
181
|
},
|
|
260
182
|
onlocaltrack(track: MediaStreamTrack, added: boolean) {
|
|
261
|
-
eventTarget.dispatchEvent(new CustomEvent("localtrack", {detail: {track
|
|
183
|
+
eventTarget.dispatchEvent(new CustomEvent("localtrack", {detail: {track, added}}))
|
|
262
184
|
},
|
|
263
185
|
onremotetrack(track: MediaStreamTrack, mid: JanusMid, added: boolean) {
|
|
264
|
-
eventTarget.dispatchEvent(new CustomEvent("remotetrack", {detail: {track
|
|
186
|
+
eventTarget.dispatchEvent(new CustomEvent("remotetrack", {detail: {track, mid, added}}))
|
|
265
187
|
},
|
|
266
188
|
ondataopen(label: unknown, protocol: unknown) {
|
|
267
|
-
eventTarget.dispatchEvent(new CustomEvent("dataopen", {detail: {label
|
|
189
|
+
eventTarget.dispatchEvent(new CustomEvent("dataopen", {detail: {label, protocol}}))
|
|
268
190
|
},
|
|
269
191
|
ondata(data: unknown, label: unknown) {
|
|
270
|
-
eventTarget.dispatchEvent(new CustomEvent("data", {detail: {data
|
|
192
|
+
eventTarget.dispatchEvent(new CustomEvent("data", {detail: {data, label}}))
|
|
271
193
|
},
|
|
272
194
|
oncleanup() {
|
|
273
195
|
eventTarget.dispatchEvent(new CustomEvent("cleanup"))
|
|
@@ -285,7 +207,7 @@ async function attachToPlugin(session: JanusSession, plugin: string): Promise<Ja
|
|
|
285
207
|
handle.sendRequest = function(message) {
|
|
286
208
|
return new Promise(function(fulfill, reject) {
|
|
287
209
|
handle.send({
|
|
288
|
-
message
|
|
210
|
+
message,
|
|
289
211
|
success: fulfill,
|
|
290
212
|
error: reject
|
|
291
213
|
})
|
|
@@ -388,7 +310,7 @@ async function joinVideoRoom(session: JanusSession, roomId: string|number): Prom
|
|
|
388
310
|
|
|
389
311
|
// construct and return the VideoRoom object
|
|
390
312
|
return {
|
|
391
|
-
roomId
|
|
313
|
+
roomId,
|
|
392
314
|
pluginHandle: handle,
|
|
393
315
|
onPublisherAdded(callback) {
|
|
394
316
|
callbacks.set("onPublisherAdded", callback)
|
|
@@ -482,13 +404,13 @@ async function createVideoRoomPublisher(
|
|
|
482
404
|
jsep: response.jsep,
|
|
483
405
|
success: fulfill,
|
|
484
406
|
error: reject,
|
|
485
|
-
customizeSdp: options.mediaOptions
|
|
407
|
+
customizeSdp: options.mediaOptions?.customizeRemoteSdp
|
|
486
408
|
})
|
|
487
409
|
})
|
|
488
410
|
|
|
489
411
|
// construct and return the VideoRoomPublisher object
|
|
490
412
|
return {
|
|
491
|
-
publisherId
|
|
413
|
+
publisherId,
|
|
492
414
|
onTrackAdded(callback) {
|
|
493
415
|
callbacks.set("onTrackAdded", callback)
|
|
494
416
|
},
|
|
@@ -588,7 +510,7 @@ async function createVideoRoomSubscriber(
|
|
|
588
510
|
request: "join",
|
|
589
511
|
ptype: "subscriber",
|
|
590
512
|
room: roomId,
|
|
591
|
-
streams
|
|
513
|
+
streams
|
|
592
514
|
},
|
|
593
515
|
expectResponse: r => r.message.videoroom == "attached" && r.message.room == roomId
|
|
594
516
|
})
|
|
@@ -606,14 +528,14 @@ async function createVideoRoomSubscriber(
|
|
|
606
528
|
},
|
|
607
529
|
async addStreams(streams) {
|
|
608
530
|
const response = await handle.sendAsyncRequest({
|
|
609
|
-
message: {request: "subscribe", streams
|
|
531
|
+
message: {request: "subscribe", streams},
|
|
610
532
|
expectResponse: r => r.message.videoroom == "updated" && r.message.room == roomId
|
|
611
533
|
})
|
|
612
534
|
if (response.jsep) await handleOffer(handle, response.jsep, options.mediaOptions)
|
|
613
535
|
},
|
|
614
536
|
async removeStreams(streams) {
|
|
615
537
|
const response = await handle.sendAsyncRequest({
|
|
616
|
-
message: {request: "unsubscribe", streams
|
|
538
|
+
message: {request: "unsubscribe", streams},
|
|
617
539
|
expectResponse: r => r.message.videoroom == "updated" && r.message.room == roomId
|
|
618
540
|
})
|
|
619
541
|
if (response.jsep) await handleOffer(handle, response.jsep, options.mediaOptions)
|
|
@@ -713,7 +635,7 @@ async function createStreamingSubscriber(
|
|
|
713
635
|
request: "watch",
|
|
714
636
|
id: mountPointId
|
|
715
637
|
},
|
|
716
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
638
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "preparing"
|
|
717
639
|
})
|
|
718
640
|
|
|
719
641
|
if (!response.jsep) throw new Error("Missing offer Jsep")
|
|
@@ -730,13 +652,13 @@ async function createStreamingSubscriber(
|
|
|
730
652
|
async pause() {
|
|
731
653
|
await handle.sendAsyncRequest({
|
|
732
654
|
message: {request: "pause"},
|
|
733
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
655
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "pausing"
|
|
734
656
|
})
|
|
735
657
|
},
|
|
736
658
|
async resume() {
|
|
737
659
|
await handle.sendAsyncRequest({
|
|
738
660
|
message: {request: "start"},
|
|
739
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
661
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "starting"
|
|
740
662
|
})
|
|
741
663
|
},
|
|
742
664
|
async configure(configureOptions) {
|
|
@@ -745,7 +667,7 @@ async function createStreamingSubscriber(
|
|
|
745
667
|
...configureOptions,
|
|
746
668
|
request: "configure"
|
|
747
669
|
},
|
|
748
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
670
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.event == "configured"
|
|
749
671
|
})
|
|
750
672
|
},
|
|
751
673
|
async switch(newMountPointId) {
|
|
@@ -754,7 +676,7 @@ async function createStreamingSubscriber(
|
|
|
754
676
|
request: "switch",
|
|
755
677
|
id: newMountPointId
|
|
756
678
|
},
|
|
757
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
679
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.switched == "ok"
|
|
758
680
|
})
|
|
759
681
|
mountPointId = newMountPointId
|
|
760
682
|
},
|
|
@@ -766,7 +688,7 @@ async function createStreamingSubscriber(
|
|
|
766
688
|
request: "watch",
|
|
767
689
|
id: mountPointId
|
|
768
690
|
},
|
|
769
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
691
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "preparing"
|
|
770
692
|
})
|
|
771
693
|
if (!response.jsep) throw new Error("Missing offer Jsep")
|
|
772
694
|
await handleOffer(handle, response.jsep, newOptions.mediaOptions)
|
|
@@ -787,7 +709,7 @@ async function createStreamingSubscriber(
|
|
|
787
709
|
|
|
788
710
|
async function handleOffer(handle: JanusPluginHandleEx, offerJsep: Jsep, mediaOptions?: JanusMediaOptions): Promise<void> {
|
|
789
711
|
// allow customizing the remote (offer) sdp
|
|
790
|
-
if (mediaOptions
|
|
712
|
+
if (mediaOptions?.customizeRemoteSdp) {
|
|
791
713
|
mediaOptions.customizeRemoteSdp(offerJsep)
|
|
792
714
|
}
|
|
793
715
|
|
|
@@ -806,7 +728,7 @@ async function handleOffer(handle: JanusPluginHandleEx, offerJsep: Jsep, mediaOp
|
|
|
806
728
|
message: {request: "start"},
|
|
807
729
|
jsep: answerJsep,
|
|
808
730
|
expectResponse: r => r.message.videoroom == "event" && r.message.started == "ok" ||
|
|
809
|
-
r.message.streaming == "event" && r.message.result
|
|
731
|
+
r.message.streaming == "event" && r.message.result?.status == "starting"
|
|
810
732
|
})
|
|
811
733
|
}
|
|
812
734
|
|
package/src/janus.d.ts
CHANGED
|
@@ -1,12 +1,95 @@
|
|
|
1
1
|
|
|
2
|
+
declare global {
|
|
3
|
+
const Janus: {
|
|
4
|
+
new(options: unknown): JanusSession
|
|
5
|
+
init(options: unknown): void
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
2
9
|
export interface JanusSession {
|
|
3
|
-
new(options: unknown): JanusSession
|
|
4
|
-
init(options: unknown): void
|
|
5
10
|
isConnected(): boolean
|
|
6
11
|
destroy(options: unknown): void
|
|
7
12
|
attach(options: unknown): void
|
|
8
13
|
}
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
12
95
|
}
|