janus-simple-videoroom-client 1.0.3 → 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 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,7 +35,7 @@ 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: JanusMediaOptions): Promise<void>;
38
+ restart(mediaOptions?: JanusMediaOptions): Promise<void>;
39
39
  unpublish(): Promise<void>;
40
40
  }
41
41
  export interface VideoRoomSubscriber {
@@ -47,7 +47,7 @@ export interface VideoRoomSubscriber {
47
47
  pause(): Promise<void>;
48
48
  resume(): Promise<void>;
49
49
  configure(configureOptions: JanusSubscriberConfigureOptions): Promise<void>;
50
- restart(mediaOptions: JanusMediaOptions): Promise<void>;
50
+ restart(mediaOptions?: JanusMediaOptions): Promise<void>;
51
51
  unsubscribe(): Promise<void>;
52
52
  }
53
53
  export interface StreamingSubscriber {
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
  });
@@ -688,6 +690,7 @@ function createVideoRoomSubscriber(session, roomId, streams, opts) {
688
690
  });
689
691
  },
690
692
  restart: function (mediaOptions) {
693
+ if (mediaOptions === void 0) { mediaOptions = options.mediaOptions; }
691
694
  return __awaiter(this, void 0, void 0, function () {
692
695
  var response;
693
696
  return __generator(this, function (_a) {
@@ -736,13 +739,12 @@ function createVideoRoomSubscriber(session, roomId, streams, opts) {
736
739
  });
737
740
  });
738
741
  }
739
- function createStreamingSubscriber(session, mountPointId, opts) {
742
+ function createStreamingSubscriber(session, mountPointId, options) {
740
743
  return __awaiter(this, void 0, void 0, function () {
741
- var options, cleanup, callbacks, handle_3, response, err_4;
744
+ var cleanup, callbacks, handle_3, response, err_4;
742
745
  return __generator(this, function (_a) {
743
746
  switch (_a.label) {
744
747
  case 0:
745
- options = __assign({}, opts);
746
748
  cleanup = makeCleanup();
747
749
  callbacks = makeCallbacks();
748
750
  _a.label = 1;
@@ -785,14 +787,14 @@ function createStreamingSubscriber(session, mountPointId, opts) {
785
787
  }
786
788
  });
787
789
  return [4 /*yield*/, handle_3.sendAsyncRequest({
788
- 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 }),
789
791
  expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "preparing"; }
790
792
  })];
791
793
  case 3:
792
794
  response = _a.sent();
793
795
  if (!response.jsep)
794
796
  throw new Error("Missing offer Jsep");
795
- 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)
796
798
  // construct and return the StreamingSubscriber object
797
799
  ];
798
800
  case 4:
@@ -870,22 +872,21 @@ function createStreamingSubscriber(session, mountPointId, opts) {
870
872
  });
871
873
  });
872
874
  },
873
- restart: function (newOpts) {
875
+ restart: function (newOptions) {
876
+ if (newOptions === void 0) { newOptions = options; }
874
877
  return __awaiter(this, void 0, void 0, function () {
875
- var newOptions, response;
878
+ var response;
876
879
  return __generator(this, function (_a) {
877
880
  switch (_a.label) {
878
- case 0:
879
- newOptions = __assign({}, newOpts);
880
- return [4 /*yield*/, handle_3.sendAsyncRequest({
881
- message: __assign(__assign({}, newOptions.watchOptions), { request: "watch", id: mountPointId }),
882
- expectResponse: function (r) { var _a; return r.message.streaming == "event" && ((_a = r.message.result) === null || _a === void 0 ? void 0 : _a.status) == "preparing"; }
883
- })];
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
+ })];
884
885
  case 1:
885
886
  response = _a.sent();
886
887
  if (!response.jsep)
887
888
  throw new Error("Missing offer Jsep");
888
- 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)];
889
890
  case 2:
890
891
  _a.sent();
891
892
  options = newOptions;
@@ -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",
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,7 +29,7 @@ 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: JanusMediaOptions): Promise<void>
32
+ restart(mediaOptions?: JanusMediaOptions): Promise<void>
33
33
  unpublish(): Promise<void>
34
34
  }
35
35
 
@@ -42,7 +42,7 @@ export interface VideoRoomSubscriber {
42
42
  pause(): Promise<void>
43
43
  resume(): Promise<void>
44
44
  configure(configureOptions: JanusSubscriberConfigureOptions): Promise<void>
45
- restart(mediaOptions: JanusMediaOptions): Promise<void>
45
+ restart(mediaOptions?: JanusMediaOptions): Promise<void>
46
46
  unsubscribe(): Promise<void>
47
47
  }
48
48
 
@@ -428,7 +428,7 @@ async function createVideoRoomPublisher(
428
428
  expectResponse: r => r.message.videoroom == "event" && r.message.configured == "ok"
429
429
  })
430
430
  },
431
- async restart(mediaOptions) {
431
+ async restart(mediaOptions = options.mediaOptions) {
432
432
  const offerJsep = await new Promise<Jsep>(function(fulfill, reject) {
433
433
  handle.createOffer({
434
434
  ...mediaOptions,
@@ -446,6 +446,7 @@ async function createVideoRoomPublisher(
446
446
  await new Promise(function(fulfill, reject) {
447
447
  handle.handleRemoteJsep({
448
448
  jsep: response.jsep,
449
+ customizeSdp: mediaOptions?.customizeRemoteSdp,
449
450
  success: fulfill,
450
451
  error: reject
451
452
  })
@@ -565,7 +566,7 @@ async function createVideoRoomSubscriber(
565
566
  expectResponse: r => r.message.videoroom == "event" && r.message.configured == "ok"
566
567
  })
567
568
  },
568
- async restart(mediaOptions) {
569
+ async restart(mediaOptions = options.mediaOptions) {
569
570
  const response = await handle.sendAsyncRequest({
570
571
  message: {
571
572
  request: "configure",
@@ -593,13 +594,12 @@ async function createVideoRoomSubscriber(
593
594
  async function createStreamingSubscriber(
594
595
  session: JanusSession,
595
596
  mountPointId: number,
596
- opts?: {
597
+ options?: {
597
598
  watchOptions?: JanusWatchOptions
598
599
  mediaOptions?: JanusMediaOptions
599
600
  }
600
601
  ): Promise<StreamingSubscriber> {
601
602
 
602
- let options = {...opts}
603
603
  const cleanup = makeCleanup()
604
604
  const callbacks = makeCallbacks()
605
605
 
@@ -634,7 +634,7 @@ async function createStreamingSubscriber(
634
634
  // send the watch request
635
635
  const response = await handle.sendAsyncRequest({
636
636
  message: {
637
- ...options.watchOptions,
637
+ ...options?.watchOptions,
638
638
  request: "watch",
639
639
  id: mountPointId
640
640
  },
@@ -642,7 +642,7 @@ async function createStreamingSubscriber(
642
642
  })
643
643
 
644
644
  if (!response.jsep) throw new Error("Missing offer Jsep")
645
- await handleOffer(handle, response.jsep, options.mediaOptions)
645
+ await handleOffer(handle, response.jsep, options?.mediaOptions)
646
646
 
647
647
  // construct and return the StreamingSubscriber object
648
648
  return {
@@ -684,18 +684,17 @@ async function createStreamingSubscriber(
684
684
  })
685
685
  mountPointId = newMountPointId
686
686
  },
687
- async restart(newOpts) {
688
- const newOptions = {...newOpts}
687
+ async restart(newOptions = options) {
689
688
  const response = await handle.sendAsyncRequest({
690
689
  message: {
691
- ...newOptions.watchOptions,
690
+ ...newOptions?.watchOptions,
692
691
  request: "watch",
693
692
  id: mountPointId
694
693
  },
695
694
  expectResponse: r => r.message.streaming == "event" && r.message.result?.status == "preparing"
696
695
  })
697
696
  if (!response.jsep) throw new Error("Missing offer Jsep")
698
- await handleOffer(handle, response.jsep, newOptions.mediaOptions)
697
+ await handleOffer(handle, response.jsep, newOptions?.mediaOptions)
699
698
  options = newOptions
700
699
  },
701
700
  async unsubscribe() {
package/tsconfig.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "target": "es5",
7
7
  "strict": true,
8
8
  "moduleResolution": "node",
9
+ "skipLibCheck": true,
9
10
  "newLine": "LF",
10
11
  "rootDir": "src",
11
12
  "outDir": "dist"