@antmedia/web_player 2.12.0 → 2.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -522,6 +522,24 @@ class WebPlayer {
522
522
  * It can be streamID or backupStreamId
523
523
  */
524
524
  _defineProperty(this, "activeStreamId", void 0);
525
+ // we define insertSecurityParameters in this way because we want to get the this context such as this.subscriberId
526
+ _defineProperty(this, "insertSecurityParameters", options => {
527
+ var queryParams = [];
528
+ if (!options.uri.includes("subscriberId") && this.subscriberId != null) {
529
+ queryParams.push("subscriberId=".concat(this.subscriberId));
530
+ }
531
+ if (!options.uri.includes("subscriberCode") && this.subscriberCode != null) {
532
+ queryParams.push("subscriberCode=".concat(this.subscriberCode));
533
+ }
534
+ if (!options.uri.includes("token") && this.token != null) {
535
+ queryParams.push("token=".concat(this.token));
536
+ }
537
+ if (queryParams.length > 0) {
538
+ var queryString = queryParams.join("&");
539
+ options.uri += options.uri.includes("?") ? "&".concat(queryString) : "?".concat(queryString);
540
+ }
541
+ Logger_1.debug("hls request: " + options.uri);
542
+ });
525
543
  WebPlayer.DEFAULT_PLAY_ORDER = ["webrtc", "hls"];
526
544
  WebPlayer.DEFAULT_PLAY_TYPE = ["mp4", "webm"];
527
545
  WebPlayer.HLS_EXTENSION = "m3u8";
@@ -724,12 +742,12 @@ class WebPlayer {
724
742
  }
725
743
  loadWebRTCComponents() {
726
744
  if (this.playOrder.includes("webrtc")) {
727
- return Promise.resolve().then(function () { return require('./videojs-webrtc-plugin-5dd8808d.js'); }).then(css => {
745
+ return Promise.resolve().then(function () { return require('./videojs-webrtc-plugin-c8051dbf.js'); }).then(css => {
728
746
  Logger_1.info("videojs-webrtc-plugin.css is loaded");
729
747
  var styleElement = this.dom.createElement('style');
730
748
  styleElement.textContent = css.default.toString(); // Assuming css module exports a string
731
749
  this.dom.head.appendChild(styleElement);
732
- return Promise.resolve().then(function () { return require('./videojs-webrtc-plugin.es-8f3aed93.js'); }).then(videojsWebrtcPluginLocal => {
750
+ return Promise.resolve().then(function () { return require('./videojs-webrtc-plugin.es-cf567f2d.js'); }).then(videojsWebrtcPluginLocal => {
733
751
  Logger_1.info("videojs-webrtc-plugin is loaded");
734
752
  });
735
753
  });
@@ -750,12 +768,12 @@ class WebPlayer {
750
768
  styleElement.textContent = css.default.toString(); // Assuming css module exports a string
751
769
  this.dom.head.appendChild(styleElement);
752
770
  }).then(() => {
753
- return Promise.resolve().then(function () { return require('./video.es-df9af03d.js'); });
771
+ return Promise.resolve().then(function () { return require('./video.es-474303e7.js'); }).then(function (n) { return n.video_es; });
754
772
  }).then(videojs => {
755
773
  window.videojs = videojs.default;
756
774
  this.videojsLoaded = true;
757
775
  }).then(() => {
758
- return Promise.resolve().then(function () { return require('./plugin-bec9dc4a.js'); });
776
+ return Promise.resolve().then(function () { return require('./plugin-1270024e.js'); });
759
777
  }).then(() => {
760
778
  return this.loadWebRTCComponents();
761
779
  });
@@ -821,10 +839,9 @@ class WebPlayer {
821
839
  }, 2000);
822
840
  } else if (infos["info"] == "streaming_started") {
823
841
  Logger_1.info("Requested stream has started");
824
- this.playIfExists(this.currentPlayType, this.activeStreamId);
842
+ this.playIfExists(this.currentPlayType, infos["obj"].streamId);
825
843
  }
826
844
  }
827
-
828
845
  /**
829
846
  * Play the stream via videojs
830
847
  * @param {*} streamUrl
@@ -892,7 +909,14 @@ class WebPlayer {
892
909
  && errors["message"]["information"] == "stream_not_exist_or_not_streaming") {
893
910
  // server puts the this client to the waiting list automatically and it will notify with
894
911
  //streaming_started event
895
- Logger_1.info("Stream does not exists or not started yet. Waiting for the stream to start. It will be notified with streaming_started event by the server");
912
+
913
+ //check if backup stream id is set
914
+ if (this.backupStreamId != null) {
915
+ this.tryNextTech();
916
+ } else {
917
+ //if backup stream id is not set, let the server notify
918
+ Logger_1.info("Stream " + errors["message"]["streamId"] + " does not exists or not started yet. Waiting for the stream to start. It will be notified with streaming_started event by the server");
919
+ }
896
920
  } else if (errors["error"] == "no_stream_exist" || errors["error"] == "WebSocketNotConnected" || errors["error"] == "not_initialized_yet" || errors["error"] == "data_store_not_available" || errors["error"] == "highResourceUsage" || errors["error"] == "unauthorized_access" || errors["error"] == "user_blocked") {
897
921
  //handle high resource usage and not authroized errors && websocket disconnected
898
922
  //Even if webrtc adaptor has auto reconnect scenario, we dispose the videojs immediately in tryNextTech
@@ -920,23 +944,12 @@ class WebPlayer {
920
944
 
921
945
  //hls specific calls
922
946
  if (extension == "m3u8") {
923
- videojs.Vhs.xhr.onRequest = options => {
924
- var queryParams = [];
925
- if (!options.uri.includes("subscriberId") && this.subscriberId != null) {
926
- queryParams.push("subscriberId=".concat(this.subscriberId));
927
- }
928
- if (!options.uri.includes("subscriberCode") && this.subscriberCode != null) {
929
- queryParams.push("subscriberCode=".concat(this.subscriberCode));
930
- }
931
- if (!options.uri.includes("token") && this.token != null) {
932
- queryParams.push("token=".concat(this.token));
933
- }
934
- if (queryParams.length > 0) {
935
- var queryString = queryParams.join("&");
936
- options.uri += options.uri.includes("?") ? "&".concat(queryString) : "?".concat(queryString);
937
- }
938
- Logger_1.debug("hls request: " + options.uri);
939
- };
947
+ this.videojsPlayer.on('xhr-hooks-ready', () => {
948
+ this.videojsPlayer.ready(() => {
949
+ // tech is ready after ready event
950
+ this.videojsPlayer.tech().vhs.xhr.onRequest(this.insertSecurityParameters);
951
+ });
952
+ });
940
953
  this.videojsPlayer.ready(() => {
941
954
  // If it's already added to player, no need to add again
942
955
  if (typeof this.videojsPlayer.qualitySelectorHls === "function") {
@@ -1447,13 +1460,17 @@ class WebPlayer {
1447
1460
  getSecurityQueryParams() {
1448
1461
  var queryString = "";
1449
1462
  if (this.token != null) {
1450
- queryString += "&token=" + this.token;
1463
+ queryString += "token=" + this.token + "&";
1451
1464
  }
1452
1465
  if (this.subscriberId != null) {
1453
- queryString += "&subscriberId=" + this.subscriberId;
1466
+ queryString += "subscriberId=" + this.subscriberId + "&";
1454
1467
  }
1455
1468
  if (this.subscriberCode != null) {
1456
- queryString += "&subscriberCode=" + this.subscriberCode;
1469
+ queryString += "subscriberCode=" + this.subscriberCode + "&";
1470
+ }
1471
+ //remove the last character if it's "&"
1472
+ if (queryString.endsWith("&")) {
1473
+ queryString = queryString.substring(0, queryString.length - 1);
1457
1474
  }
1458
1475
  return queryString;
1459
1476
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antmedia/web_player",
3
- "version": "2.12.0",
3
+ "version": "2.12.1",
4
4
  "description": "Ant Media Server Player that can play WebRTC, HLS, DASH",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/es/index.js",
package/src/web_player.js CHANGED
@@ -605,7 +605,7 @@ export class WebPlayer {
605
605
  else if (infos["info"] == "streaming_started")
606
606
  {
607
607
  Logger.info("Requested stream has started");
608
- this.playIfExists(this.currentPlayType, this.activeStreamId);
608
+ this.playIfExists(this.currentPlayType, infos["obj"].streamId);
609
609
  }
610
610
  }
611
611
 
@@ -711,7 +711,15 @@ export class WebPlayer {
711
711
  {
712
712
  // server puts the this client to the waiting list automatically and it will notify with
713
713
  //streaming_started event
714
- Logger.info("Stream does not exists or not started yet. Waiting for the stream to start. It will be notified with streaming_started event by the server");
714
+
715
+ //check if backup stream id is set
716
+ if (this.backupStreamId != null) {
717
+ this.tryNextTech();
718
+ }
719
+ else {
720
+ //if backup stream id is not set, let the server notify
721
+ Logger.info("Stream "+errors["message"]["streamId"] +" does not exists or not started yet. Waiting for the stream to start. It will be notified with streaming_started event by the server");
722
+ }
715
723
  }
716
724
  else if (errors["error"] == "no_stream_exist" || errors["error"] == "WebSocketNotConnected"
717
725
  || errors["error"] == "not_initialized_yet" || errors["error"] == "data_store_not_available"
@@ -795,11 +795,14 @@ describe("WebPlayer", function() {
795
795
 
796
796
  it("handleWebRTCInfoMessages", async function() {
797
797
 
798
+ this.timeout(10000);
798
799
  var videoContainer = document.createElement("video_container");
799
-
800
800
  var placeHolder = document.createElement("place_holder");
801
+ document.body.appendChild(videoContainer);
802
+ document.body.appendChild(placeHolder);
801
803
 
802
- var locationComponent = { href: 'http://example.com?id=stream123.mp4', search: "?id=stream123.mp4", pathname: "/", protocol: "http:" };
804
+ var locationComponent = { href: 'http://example.com?id=stream123',
805
+ search: "?id=stream123&playOrder=webrtc,hls,dash", pathname: "/", protocol: "http:" };
803
806
  var windowComponent = {
804
807
  location: locationComponent,
805
808
  document: document,
@@ -807,7 +810,14 @@ describe("WebPlayer", function() {
807
810
  };
808
811
 
809
812
  var player = new WebPlayer(windowComponent, videoContainer, placeHolder);
813
+ await player.initialize().then(()=> {
814
+
815
+ }).catch((err) => {
816
+ expect.fail("it should not fail because we skip videojs and dash is already loaded");
817
+ });
818
+
810
819
  var tryNextTech = sinon.replace(player, "tryNextTech", sinon.fake.returns(Promise.resolve("")));
820
+
811
821
  var infos = {
812
822
  info: "ice_connection_state_changed",
813
823
  obj: {
@@ -836,7 +846,7 @@ describe("WebPlayer", function() {
836
846
 
837
847
  expect(tryNextTech.calledTwice).to.be.true;
838
848
 
839
- await player.playIfExists("webrtc");
849
+ await player.playIfExists("webrtc", "streamId");
840
850
 
841
851
  expect(player.videojsPlayer).to.not.be.null;
842
852
 
@@ -862,17 +872,27 @@ describe("WebPlayer", function() {
862
872
 
863
873
  infos = {
864
874
  info: "streaming_started",
875
+ obj: {
876
+ streamId: "streamId"
877
+ }
865
878
 
866
879
  }
867
880
  player.handleWebRTCInfoMessages(infos);
868
881
 
869
882
  expect(playIfExistsMethod.calledOnce).to.be.true;
883
+
884
+
885
+
870
886
  });
871
887
 
872
888
  it("testAutoPlay",async function(){
873
889
  var videoContainer = document.createElement("video_container");
874
-
890
+
891
+ document.body.appendChild(videoContainer);
875
892
  var placeHolder = document.createElement("place_holder");
893
+ document.body.appendChild(placeHolder);
894
+
895
+
876
896
 
877
897
  var locationComponent = { href: 'http://example.com?id=stream123.mp4', search: "?id=stream123.mp4", pathname: "/", protocol: "http:" };
878
898
  var windowComponent = { location : locationComponent,