janus-simple-videoroom-client 1.0.1 → 1.0.3
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 +10 -85
- package/dist/index.js +24 -12
- package/package.json +1 -1
- package/src/index.ts +41 -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,8 @@ interface VideoRoomPublisher {
|
|
|
37
38
|
restart(mediaOptions: JanusMediaOptions): Promise<void>;
|
|
38
39
|
unpublish(): Promise<void>;
|
|
39
40
|
}
|
|
40
|
-
interface VideoRoomSubscriber {
|
|
41
|
+
export interface VideoRoomSubscriber {
|
|
42
|
+
pluginHandle: JanusPluginHandleEx;
|
|
41
43
|
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
42
44
|
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
43
45
|
addStreams(streams: JanusStreamSpec[]): Promise<void>;
|
|
@@ -48,7 +50,8 @@ interface VideoRoomSubscriber {
|
|
|
48
50
|
restart(mediaOptions: JanusMediaOptions): Promise<void>;
|
|
49
51
|
unsubscribe(): Promise<void>;
|
|
50
52
|
}
|
|
51
|
-
interface StreamingSubscriber {
|
|
53
|
+
export interface StreamingSubscriber {
|
|
54
|
+
pluginHandle: JanusPluginHandleEx;
|
|
52
55
|
onTrackAdded(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
53
56
|
onTrackRemoved(callback: (track: MediaStreamTrack, mid: JanusMid) => void): void;
|
|
54
57
|
pause(): Promise<void>;
|
|
@@ -61,12 +64,7 @@ interface StreamingSubscriber {
|
|
|
61
64
|
}): Promise<void>;
|
|
62
65
|
unsubscribe(): Promise<void>;
|
|
63
66
|
}
|
|
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;
|
|
67
|
+
export interface JanusPluginHandleEx extends JanusPluginHandle {
|
|
70
68
|
eventTarget: ReturnType<typeof makeEventTarget>;
|
|
71
69
|
sendRequest(message: JanusMessage): Promise<JanusMessage>;
|
|
72
70
|
sendAsyncRequest(options: {
|
|
@@ -79,79 +77,6 @@ interface AsyncResponse {
|
|
|
79
77
|
message: JanusMessage;
|
|
80
78
|
jsep?: Jsep;
|
|
81
79
|
}
|
|
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
80
|
export declare function createVideoRoomClient(options?: {
|
|
156
81
|
debug?: boolean | string[];
|
|
157
82
|
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
|
|
@@ -586,6 +593,7 @@ function createVideoRoomSubscriber(session, roomId, streams, opts) {
|
|
|
586
593
|
_a.sent();
|
|
587
594
|
// construct and return the VideoRoomSubscriber object
|
|
588
595
|
return [2 /*return*/, {
|
|
596
|
+
pluginHandle: handle_2,
|
|
589
597
|
onTrackAdded: function (callback) {
|
|
590
598
|
callbacks.set("onTrackAdded", callback);
|
|
591
599
|
},
|
|
@@ -778,7 +786,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
778
786
|
});
|
|
779
787
|
return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
780
788
|
message: __assign(__assign({}, options.watchOptions), { request: "watch", id: mountPointId }),
|
|
781
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
789
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "preparing"; }
|
|
782
790
|
})];
|
|
783
791
|
case 3:
|
|
784
792
|
response = _a.sent();
|
|
@@ -791,6 +799,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
791
799
|
_a.sent();
|
|
792
800
|
// construct and return the StreamingSubscriber object
|
|
793
801
|
return [2 /*return*/, {
|
|
802
|
+
pluginHandle: handle_3,
|
|
794
803
|
onTrackAdded: function (callback) {
|
|
795
804
|
callbacks.set("onTrackAdded", callback);
|
|
796
805
|
},
|
|
@@ -803,7 +812,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
803
812
|
switch (_a.label) {
|
|
804
813
|
case 0: return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
805
814
|
message: { request: "pause" },
|
|
806
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
815
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "pausing"; }
|
|
807
816
|
})];
|
|
808
817
|
case 1:
|
|
809
818
|
_a.sent();
|
|
@@ -818,7 +827,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
818
827
|
switch (_a.label) {
|
|
819
828
|
case 0: return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
820
829
|
message: { request: "start" },
|
|
821
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
830
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "starting"; }
|
|
822
831
|
})];
|
|
823
832
|
case 1:
|
|
824
833
|
_a.sent();
|
|
@@ -833,7 +842,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
833
842
|
switch (_a.label) {
|
|
834
843
|
case 0: return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
835
844
|
message: __assign(__assign({}, configureOptions), { request: "configure" }),
|
|
836
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
845
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.event) == "configured"; }
|
|
837
846
|
})];
|
|
838
847
|
case 1:
|
|
839
848
|
_a.sent();
|
|
@@ -851,7 +860,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
851
860
|
request: "switch",
|
|
852
861
|
id: newMountPointId
|
|
853
862
|
},
|
|
854
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
863
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.switched) == "ok"; }
|
|
855
864
|
})];
|
|
856
865
|
case 1:
|
|
857
866
|
_a.sent();
|
|
@@ -870,7 +879,7 @@ function createStreamingSubscriber(session, mountPointId, opts) {
|
|
|
870
879
|
newOptions = __assign({}, newOpts);
|
|
871
880
|
return [4 /*yield*/, handle_3.sendAsyncRequest({
|
|
872
881
|
message: __assign(__assign({}, newOptions.watchOptions), { request: "watch", id: mountPointId }),
|
|
873
|
-
expectResponse: function (r) { return r.message.streaming == "event" && r.message.result
|
|
882
|
+
expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "preparing"; }
|
|
874
883
|
})];
|
|
875
884
|
case 1:
|
|
876
885
|
response = _a.sent();
|
|
@@ -916,7 +925,7 @@ function handleOffer(handle, offerJsep, mediaOptions) {
|
|
|
916
925
|
switch (_a.label) {
|
|
917
926
|
case 0:
|
|
918
927
|
// allow customizing the remote (offer) sdp
|
|
919
|
-
if (mediaOptions
|
|
928
|
+
if (mediaOptions === null || mediaOptions === void 0 ? void 0 : mediaOptions.customizeRemoteSdp) {
|
|
920
929
|
mediaOptions.customizeRemoteSdp(offerJsep);
|
|
921
930
|
}
|
|
922
931
|
return [4 /*yield*/, new Promise(function (fulfill, reject) {
|
|
@@ -928,8 +937,11 @@ function handleOffer(handle, offerJsep, mediaOptions) {
|
|
|
928
937
|
return [4 /*yield*/, handle.sendAsyncRequest({
|
|
929
938
|
message: { request: "start" },
|
|
930
939
|
jsep: answerJsep,
|
|
931
|
-
expectResponse: function (r) {
|
|
932
|
-
|
|
940
|
+
expectResponse: function (r) {
|
|
941
|
+
var _a;
|
|
942
|
+
return r.message.videoroom == "event" && r.message.started == "ok" ||
|
|
943
|
+
r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "starting";
|
|
944
|
+
}
|
|
933
945
|
})];
|
|
934
946
|
case 2:
|
|
935
947
|
_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,8 @@ interface VideoRoomPublisher {
|
|
|
33
33
|
unpublish(): Promise<void>
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
interface VideoRoomSubscriber {
|
|
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>
|
|
@@ -45,7 +46,8 @@ interface VideoRoomSubscriber {
|
|
|
45
46
|
unsubscribe(): Promise<void>
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
interface StreamingSubscriber {
|
|
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>
|
|
@@ -56,13 +58,7 @@ interface StreamingSubscriber {
|
|
|
56
58
|
unsubscribe(): Promise<void>
|
|
57
59
|
}
|
|
58
60
|
|
|
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
|
-
|
|
61
|
+
export interface JanusPluginHandleEx extends JanusPluginHandle {
|
|
66
62
|
eventTarget: ReturnType<typeof makeEventTarget>
|
|
67
63
|
sendRequest(message: JanusMessage): Promise<JanusMessage>
|
|
68
64
|
sendAsyncRequest(options: {message: JanusMessage, jsep?: Jsep, expectResponse: (response: AsyncResponse) => boolean}): Promise<AsyncResponse>
|
|
@@ -73,80 +69,6 @@ interface AsyncResponse {
|
|
|
73
69
|
jsep?: Jsep
|
|
74
70
|
}
|
|
75
71
|
|
|
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
72
|
|
|
151
73
|
|
|
152
74
|
export async function createVideoRoomClient(
|
|
@@ -157,6 +79,7 @@ export async function createVideoRoomClient(
|
|
|
157
79
|
): Promise<VideoRoomClient> {
|
|
158
80
|
await new Promise(f => Janus.init({...options, callback: f}))
|
|
159
81
|
|
|
82
|
+
// construct and return the VideoRoomClient object
|
|
160
83
|
return {
|
|
161
84
|
createSession: createVideoRoomSession
|
|
162
85
|
}
|
|
@@ -197,6 +120,7 @@ async function createVideoRoomSession(server: string|string[], options?: JanusSe
|
|
|
197
120
|
})
|
|
198
121
|
})
|
|
199
122
|
|
|
123
|
+
// construct and return the VideoRoomSession object
|
|
200
124
|
return {
|
|
201
125
|
eventTarget,
|
|
202
126
|
isValid() {
|
|
@@ -233,41 +157,41 @@ async function attachToPlugin(session: JanusSession, plugin: string): Promise<Ja
|
|
|
233
157
|
|
|
234
158
|
const handle: JanusPluginHandleEx = await new Promise(function(fulfill, reject) {
|
|
235
159
|
session.attach({
|
|
236
|
-
plugin
|
|
160
|
+
plugin,
|
|
237
161
|
success: fulfill,
|
|
238
162
|
error: reject,
|
|
239
163
|
consentDialog(state: unknown) {
|
|
240
|
-
eventTarget.dispatchEvent(new CustomEvent("consentDialog", {detail: {state
|
|
164
|
+
eventTarget.dispatchEvent(new CustomEvent("consentDialog", {detail: {state}}))
|
|
241
165
|
},
|
|
242
166
|
webrtcState(state: unknown, reason: unknown) {
|
|
243
|
-
eventTarget.dispatchEvent(new CustomEvent("webrtcState", {detail: {state
|
|
167
|
+
eventTarget.dispatchEvent(new CustomEvent("webrtcState", {detail: {state, reason}}))
|
|
244
168
|
},
|
|
245
169
|
iceState(state: unknown) {
|
|
246
|
-
eventTarget.dispatchEvent(new CustomEvent("iceState", {detail: {state
|
|
170
|
+
eventTarget.dispatchEvent(new CustomEvent("iceState", {detail: {state}}))
|
|
247
171
|
},
|
|
248
172
|
mediaState(state: unknown) {
|
|
249
|
-
eventTarget.dispatchEvent(new CustomEvent("mediaState", {detail: {state
|
|
173
|
+
eventTarget.dispatchEvent(new CustomEvent("mediaState", {detail: {state}}))
|
|
250
174
|
},
|
|
251
175
|
slowLink(state: unknown) {
|
|
252
|
-
eventTarget.dispatchEvent(new CustomEvent("slowLink", {detail: {state
|
|
176
|
+
eventTarget.dispatchEvent(new CustomEvent("slowLink", {detail: {state}}))
|
|
253
177
|
},
|
|
254
178
|
onmessage(message: JanusMessage, jsep: Jsep) {
|
|
255
|
-
const response = {message
|
|
179
|
+
const response = {message, jsep}
|
|
256
180
|
const index = pendingRequests.findIndex(x => x.acceptResponse(response))
|
|
257
181
|
if (index != -1) pendingRequests.splice(index, 1)
|
|
258
|
-
else eventTarget.dispatchEvent(new CustomEvent("message", {detail: {message
|
|
182
|
+
else eventTarget.dispatchEvent(new CustomEvent("message", {detail: {message, jsep}}))
|
|
259
183
|
},
|
|
260
184
|
onlocaltrack(track: MediaStreamTrack, added: boolean) {
|
|
261
|
-
eventTarget.dispatchEvent(new CustomEvent("localtrack", {detail: {track
|
|
185
|
+
eventTarget.dispatchEvent(new CustomEvent("localtrack", {detail: {track, added}}))
|
|
262
186
|
},
|
|
263
187
|
onremotetrack(track: MediaStreamTrack, mid: JanusMid, added: boolean) {
|
|
264
|
-
eventTarget.dispatchEvent(new CustomEvent("remotetrack", {detail: {track
|
|
188
|
+
eventTarget.dispatchEvent(new CustomEvent("remotetrack", {detail: {track, mid, added}}))
|
|
265
189
|
},
|
|
266
190
|
ondataopen(label: unknown, protocol: unknown) {
|
|
267
|
-
eventTarget.dispatchEvent(new CustomEvent("dataopen", {detail: {label
|
|
191
|
+
eventTarget.dispatchEvent(new CustomEvent("dataopen", {detail: {label, protocol}}))
|
|
268
192
|
},
|
|
269
193
|
ondata(data: unknown, label: unknown) {
|
|
270
|
-
eventTarget.dispatchEvent(new CustomEvent("data", {detail: {data
|
|
194
|
+
eventTarget.dispatchEvent(new CustomEvent("data", {detail: {data, label}}))
|
|
271
195
|
},
|
|
272
196
|
oncleanup() {
|
|
273
197
|
eventTarget.dispatchEvent(new CustomEvent("cleanup"))
|
|
@@ -285,7 +209,7 @@ async function attachToPlugin(session: JanusSession, plugin: string): Promise<Ja
|
|
|
285
209
|
handle.sendRequest = function(message) {
|
|
286
210
|
return new Promise(function(fulfill, reject) {
|
|
287
211
|
handle.send({
|
|
288
|
-
message
|
|
212
|
+
message,
|
|
289
213
|
success: fulfill,
|
|
290
214
|
error: reject
|
|
291
215
|
})
|
|
@@ -388,7 +312,7 @@ async function joinVideoRoom(session: JanusSession, roomId: string|number): Prom
|
|
|
388
312
|
|
|
389
313
|
// construct and return the VideoRoom object
|
|
390
314
|
return {
|
|
391
|
-
roomId
|
|
315
|
+
roomId,
|
|
392
316
|
pluginHandle: handle,
|
|
393
317
|
onPublisherAdded(callback) {
|
|
394
318
|
callbacks.set("onPublisherAdded", callback)
|
|
@@ -482,13 +406,13 @@ async function createVideoRoomPublisher(
|
|
|
482
406
|
jsep: response.jsep,
|
|
483
407
|
success: fulfill,
|
|
484
408
|
error: reject,
|
|
485
|
-
customizeSdp: options.mediaOptions
|
|
409
|
+
customizeSdp: options.mediaOptions?.customizeRemoteSdp
|
|
486
410
|
})
|
|
487
411
|
})
|
|
488
412
|
|
|
489
413
|
// construct and return the VideoRoomPublisher object
|
|
490
414
|
return {
|
|
491
|
-
publisherId
|
|
415
|
+
publisherId,
|
|
492
416
|
onTrackAdded(callback) {
|
|
493
417
|
callbacks.set("onTrackAdded", callback)
|
|
494
418
|
},
|
|
@@ -588,7 +512,7 @@ async function createVideoRoomSubscriber(
|
|
|
588
512
|
request: "join",
|
|
589
513
|
ptype: "subscriber",
|
|
590
514
|
room: roomId,
|
|
591
|
-
streams
|
|
515
|
+
streams
|
|
592
516
|
},
|
|
593
517
|
expectResponse: r => r.message.videoroom == "attached" && r.message.room == roomId
|
|
594
518
|
})
|
|
@@ -598,6 +522,7 @@ async function createVideoRoomSubscriber(
|
|
|
598
522
|
|
|
599
523
|
// construct and return the VideoRoomSubscriber object
|
|
600
524
|
return {
|
|
525
|
+
pluginHandle: handle,
|
|
601
526
|
onTrackAdded(callback) {
|
|
602
527
|
callbacks.set("onTrackAdded", callback)
|
|
603
528
|
},
|
|
@@ -606,14 +531,14 @@ async function createVideoRoomSubscriber(
|
|
|
606
531
|
},
|
|
607
532
|
async addStreams(streams) {
|
|
608
533
|
const response = await handle.sendAsyncRequest({
|
|
609
|
-
message: {request: "subscribe", streams
|
|
534
|
+
message: {request: "subscribe", streams},
|
|
610
535
|
expectResponse: r => r.message.videoroom == "updated" && r.message.room == roomId
|
|
611
536
|
})
|
|
612
537
|
if (response.jsep) await handleOffer(handle, response.jsep, options.mediaOptions)
|
|
613
538
|
},
|
|
614
539
|
async removeStreams(streams) {
|
|
615
540
|
const response = await handle.sendAsyncRequest({
|
|
616
|
-
message: {request: "unsubscribe", streams
|
|
541
|
+
message: {request: "unsubscribe", streams},
|
|
617
542
|
expectResponse: r => r.message.videoroom == "updated" && r.message.room == roomId
|
|
618
543
|
})
|
|
619
544
|
if (response.jsep) await handleOffer(handle, response.jsep, options.mediaOptions)
|
|
@@ -713,7 +638,7 @@ async function createStreamingSubscriber(
|
|
|
713
638
|
request: "watch",
|
|
714
639
|
id: mountPointId
|
|
715
640
|
},
|
|
716
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
641
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "preparing"
|
|
717
642
|
})
|
|
718
643
|
|
|
719
644
|
if (!response.jsep) throw new Error("Missing offer Jsep")
|
|
@@ -721,6 +646,7 @@ async function createStreamingSubscriber(
|
|
|
721
646
|
|
|
722
647
|
// construct and return the StreamingSubscriber object
|
|
723
648
|
return {
|
|
649
|
+
pluginHandle: handle,
|
|
724
650
|
onTrackAdded(callback) {
|
|
725
651
|
callbacks.set("onTrackAdded", callback)
|
|
726
652
|
},
|
|
@@ -730,13 +656,13 @@ async function createStreamingSubscriber(
|
|
|
730
656
|
async pause() {
|
|
731
657
|
await handle.sendAsyncRequest({
|
|
732
658
|
message: {request: "pause"},
|
|
733
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
659
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "pausing"
|
|
734
660
|
})
|
|
735
661
|
},
|
|
736
662
|
async resume() {
|
|
737
663
|
await handle.sendAsyncRequest({
|
|
738
664
|
message: {request: "start"},
|
|
739
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
665
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "starting"
|
|
740
666
|
})
|
|
741
667
|
},
|
|
742
668
|
async configure(configureOptions) {
|
|
@@ -745,7 +671,7 @@ async function createStreamingSubscriber(
|
|
|
745
671
|
...configureOptions,
|
|
746
672
|
request: "configure"
|
|
747
673
|
},
|
|
748
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
674
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.event == "configured"
|
|
749
675
|
})
|
|
750
676
|
},
|
|
751
677
|
async switch(newMountPointId) {
|
|
@@ -754,7 +680,7 @@ async function createStreamingSubscriber(
|
|
|
754
680
|
request: "switch",
|
|
755
681
|
id: newMountPointId
|
|
756
682
|
},
|
|
757
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
683
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.switched == "ok"
|
|
758
684
|
})
|
|
759
685
|
mountPointId = newMountPointId
|
|
760
686
|
},
|
|
@@ -766,7 +692,7 @@ async function createStreamingSubscriber(
|
|
|
766
692
|
request: "watch",
|
|
767
693
|
id: mountPointId
|
|
768
694
|
},
|
|
769
|
-
expectResponse: r => r.message.streaming == "event" && r.message.result
|
|
695
|
+
expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "preparing"
|
|
770
696
|
})
|
|
771
697
|
if (!response.jsep) throw new Error("Missing offer Jsep")
|
|
772
698
|
await handleOffer(handle, response.jsep, newOptions.mediaOptions)
|
|
@@ -787,7 +713,7 @@ async function createStreamingSubscriber(
|
|
|
787
713
|
|
|
788
714
|
async function handleOffer(handle: JanusPluginHandleEx, offerJsep: Jsep, mediaOptions?: JanusMediaOptions): Promise<void> {
|
|
789
715
|
// allow customizing the remote (offer) sdp
|
|
790
|
-
if (mediaOptions
|
|
716
|
+
if (mediaOptions?.customizeRemoteSdp) {
|
|
791
717
|
mediaOptions.customizeRemoteSdp(offerJsep)
|
|
792
718
|
}
|
|
793
719
|
|
|
@@ -806,7 +732,7 @@ async function handleOffer(handle: JanusPluginHandleEx, offerJsep: Jsep, mediaOp
|
|
|
806
732
|
message: {request: "start"},
|
|
807
733
|
jsep: answerJsep,
|
|
808
734
|
expectResponse: r => r.message.videoroom == "event" && r.message.started == "ok" ||
|
|
809
|
-
r.message.streaming == "event" && r.message.result
|
|
735
|
+
r.message.streaming == "event" && r.message.result?.status == "starting"
|
|
810
736
|
})
|
|
811
737
|
}
|
|
812
738
|
|
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
|
}
|