@whereby.com/media 11.0.0 → 11.1.0

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.cjs CHANGED
@@ -3924,7 +3924,7 @@ class VegaConnection extends EventEmitter.EventEmitter {
3924
3924
  this.socket.onclose = this._onClose.bind(this);
3925
3925
  this.socket.onerror = this._onError.bind(this);
3926
3926
  }
3927
- _tearDown() {
3927
+ _tearDown(event) {
3928
3928
  if (this.socket === null)
3929
3929
  return;
3930
3930
  this.socket.onopen = null;
@@ -3933,7 +3933,7 @@ class VegaConnection extends EventEmitter.EventEmitter {
3933
3933
  this.socket.onerror = null;
3934
3934
  this.socket = null;
3935
3935
  this.sents.forEach((sent) => sent.close());
3936
- this.emit("close");
3936
+ this.emit("close", event);
3937
3937
  }
3938
3938
  close() {
3939
3939
  var _a;
@@ -3953,9 +3953,9 @@ class VegaConnection extends EventEmitter.EventEmitter {
3953
3953
  this.emit("message", socketMessage);
3954
3954
  }
3955
3955
  }
3956
- _onClose() {
3956
+ _onClose(event) {
3957
3957
  logger$3.info("Disconnected");
3958
- this._tearDown();
3958
+ this._tearDown(event);
3959
3959
  }
3960
3960
  _onError(error) {
3961
3961
  logger$3.info("Error", error);
@@ -6621,10 +6621,12 @@ function startPerformanceMonitor({ onMetricsUpdated, onTerminated, isHidden, })
6621
6621
  }
6622
6622
 
6623
6623
  const logger$1 = new Logger();
6624
+ const SFU_BASE_URL = "wss://any.sfu.svc.whereby.com";
6624
6625
  class BandwidthTester extends EventEmitter {
6625
- constructor({ features } = {}) {
6626
+ constructor({ token, features }) {
6626
6627
  super();
6627
6628
  this.closed = false;
6629
+ this._token = token;
6628
6630
  this._features = features || {};
6629
6631
  this._vegaConnection = null;
6630
6632
  this._mediasoupDeviceInitializedAsync = getMediasoupDeviceAsync(this._features);
@@ -6654,22 +6656,33 @@ class BandwidthTester extends EventEmitter {
6654
6656
  timeout: true,
6655
6657
  },
6656
6658
  });
6657
- return this.close();
6659
+ this.close();
6660
+ return;
6658
6661
  }
6659
6662
  this._runTime = runTime;
6660
6663
  this._startTime = Date.now();
6661
- const host = this._features.sfuServerOverrideHost || "any.sfu.svc.whereby.com";
6662
- const wsUrl = `wss://${host}`;
6663
- this._vegaConnection = new VegaConnection(wsUrl, { protocol: "whereby-sfu#bw-test-v1" });
6664
+ const host = this._features.sfuServerOverrideHost && !this._features.sfuServerOverrideHost.startsWith("wss://")
6665
+ ? `wss://${this._features.sfuServerOverrideHost}`
6666
+ : this._features.sfuServerOverrideHost || SFU_BASE_URL;
6667
+ const wsUrl = `${host}?bandwidthTestClaim=${this._token}`;
6668
+ this._vegaConnection = new VegaConnection(wsUrl, {
6669
+ protocol: "whereby-sfu#bw-test-v1",
6670
+ });
6664
6671
  this._vegaConnection.on("open", () => this._start());
6665
- this._vegaConnection.on("close", () => this.close(true));
6672
+ this._vegaConnection.on("close", (event) => this.close(true, event));
6666
6673
  this._vegaConnection.on("message", (message) => this._onMessage(message));
6667
6674
  this._startTimeout();
6668
6675
  }
6669
- close(vegaConnectionClosed) {
6676
+ close(vegaConnectionClosed, event) {
6670
6677
  logger$1.info("close()");
6671
6678
  this.closed = true;
6672
- if (!!this._timeout || Date.now() - this._startTime < 750) {
6679
+ if ((event === null || event === void 0 ? void 0 : event.code) === 1008) {
6680
+ this.emit("result", {
6681
+ error: true,
6682
+ details: Object.assign(Object.assign({}, ((event === null || event === void 0 ? void 0 : event.reason) === "invalidClaim" && { invalidClaim: true })), ((event === null || event === void 0 ? void 0 : event.reason) === "connectionTimeout" && { timeout: true })),
6683
+ });
6684
+ }
6685
+ else if (!!this._timeout || Date.now() - this._startTime < 750) {
6673
6686
  this.emit("result", {
6674
6687
  error: true,
6675
6688
  });
package/dist/index.d.cts CHANGED
@@ -1325,6 +1325,7 @@ declare function trackAnnotations(o: MediaStreamTrack): TrackAnnotation;
1325
1325
 
1326
1326
  declare class BandwidthTester extends EventEmitter {
1327
1327
  closed: boolean;
1328
+ _token: string;
1328
1329
  _features: any;
1329
1330
  _vegaConnection: any;
1330
1331
  _mediasoupDeviceInitializedAsync: Promise<Device | null>;
@@ -1342,11 +1343,12 @@ declare class BandwidthTester extends EventEmitter {
1342
1343
  _canvas: any;
1343
1344
  _drawInterval: any;
1344
1345
  _resultTimeout: ClearableTimeout | null;
1345
- constructor({ features }?: {
1346
+ constructor({ token, features }: {
1347
+ token: string;
1346
1348
  features?: any;
1347
1349
  });
1348
1350
  start(runTime?: number): void;
1349
- close(vegaConnectionClosed?: boolean): void;
1351
+ close(vegaConnectionClosed?: boolean, event?: any): void;
1350
1352
  _start(): Promise<void>;
1351
1353
  _createTransport(send: any): Promise<void>;
1352
1354
  _getTestTrack(): any;
@@ -1848,11 +1850,11 @@ declare class VegaConnection extends EventEmitter$1 {
1848
1850
  incrementAnalyticMetric?: VegaIncrementAnalyticMetric;
1849
1851
  constructor(wsUrl: string, { protocol, incrementAnalyticMetric }: VegaConnectionOptions);
1850
1852
  _setupSocket(): void;
1851
- _tearDown(): void;
1853
+ _tearDown(event?: CloseEvent): void;
1852
1854
  close(): void;
1853
1855
  _onOpen(): void;
1854
1856
  _onMessage(event: MessageEvent): void;
1855
- _onClose(): void;
1857
+ _onClose(event?: CloseEvent): void;
1856
1858
  _onError(error: any): void;
1857
1859
  _handleResponse(socketMessage: any): void;
1858
1860
  send(message: any): void;
package/dist/index.d.mts CHANGED
@@ -1325,6 +1325,7 @@ declare function trackAnnotations(o: MediaStreamTrack): TrackAnnotation;
1325
1325
 
1326
1326
  declare class BandwidthTester extends EventEmitter {
1327
1327
  closed: boolean;
1328
+ _token: string;
1328
1329
  _features: any;
1329
1330
  _vegaConnection: any;
1330
1331
  _mediasoupDeviceInitializedAsync: Promise<Device | null>;
@@ -1342,11 +1343,12 @@ declare class BandwidthTester extends EventEmitter {
1342
1343
  _canvas: any;
1343
1344
  _drawInterval: any;
1344
1345
  _resultTimeout: ClearableTimeout | null;
1345
- constructor({ features }?: {
1346
+ constructor({ token, features }: {
1347
+ token: string;
1346
1348
  features?: any;
1347
1349
  });
1348
1350
  start(runTime?: number): void;
1349
- close(vegaConnectionClosed?: boolean): void;
1351
+ close(vegaConnectionClosed?: boolean, event?: any): void;
1350
1352
  _start(): Promise<void>;
1351
1353
  _createTransport(send: any): Promise<void>;
1352
1354
  _getTestTrack(): any;
@@ -1848,11 +1850,11 @@ declare class VegaConnection extends EventEmitter$1 {
1848
1850
  incrementAnalyticMetric?: VegaIncrementAnalyticMetric;
1849
1851
  constructor(wsUrl: string, { protocol, incrementAnalyticMetric }: VegaConnectionOptions);
1850
1852
  _setupSocket(): void;
1851
- _tearDown(): void;
1853
+ _tearDown(event?: CloseEvent): void;
1852
1854
  close(): void;
1853
1855
  _onOpen(): void;
1854
1856
  _onMessage(event: MessageEvent): void;
1855
- _onClose(): void;
1857
+ _onClose(event?: CloseEvent): void;
1856
1858
  _onError(error: any): void;
1857
1859
  _handleResponse(socketMessage: any): void;
1858
1860
  send(message: any): void;
package/dist/index.d.ts CHANGED
@@ -1325,6 +1325,7 @@ declare function trackAnnotations(o: MediaStreamTrack): TrackAnnotation;
1325
1325
 
1326
1326
  declare class BandwidthTester extends EventEmitter {
1327
1327
  closed: boolean;
1328
+ _token: string;
1328
1329
  _features: any;
1329
1330
  _vegaConnection: any;
1330
1331
  _mediasoupDeviceInitializedAsync: Promise<Device | null>;
@@ -1342,11 +1343,12 @@ declare class BandwidthTester extends EventEmitter {
1342
1343
  _canvas: any;
1343
1344
  _drawInterval: any;
1344
1345
  _resultTimeout: ClearableTimeout | null;
1345
- constructor({ features }?: {
1346
+ constructor({ token, features }: {
1347
+ token: string;
1346
1348
  features?: any;
1347
1349
  });
1348
1350
  start(runTime?: number): void;
1349
- close(vegaConnectionClosed?: boolean): void;
1351
+ close(vegaConnectionClosed?: boolean, event?: any): void;
1350
1352
  _start(): Promise<void>;
1351
1353
  _createTransport(send: any): Promise<void>;
1352
1354
  _getTestTrack(): any;
@@ -1848,11 +1850,11 @@ declare class VegaConnection extends EventEmitter$1 {
1848
1850
  incrementAnalyticMetric?: VegaIncrementAnalyticMetric;
1849
1851
  constructor(wsUrl: string, { protocol, incrementAnalyticMetric }: VegaConnectionOptions);
1850
1852
  _setupSocket(): void;
1851
- _tearDown(): void;
1853
+ _tearDown(event?: CloseEvent): void;
1852
1854
  close(): void;
1853
1855
  _onOpen(): void;
1854
1856
  _onMessage(event: MessageEvent): void;
1855
- _onClose(): void;
1857
+ _onClose(event?: CloseEvent): void;
1856
1858
  _onError(error: any): void;
1857
1859
  _handleResponse(socketMessage: any): void;
1858
1860
  send(message: any): void;
package/dist/index.mjs CHANGED
@@ -3904,7 +3904,7 @@ class VegaConnection extends EventEmitter$1 {
3904
3904
  this.socket.onclose = this._onClose.bind(this);
3905
3905
  this.socket.onerror = this._onError.bind(this);
3906
3906
  }
3907
- _tearDown() {
3907
+ _tearDown(event) {
3908
3908
  if (this.socket === null)
3909
3909
  return;
3910
3910
  this.socket.onopen = null;
@@ -3913,7 +3913,7 @@ class VegaConnection extends EventEmitter$1 {
3913
3913
  this.socket.onerror = null;
3914
3914
  this.socket = null;
3915
3915
  this.sents.forEach((sent) => sent.close());
3916
- this.emit("close");
3916
+ this.emit("close", event);
3917
3917
  }
3918
3918
  close() {
3919
3919
  var _a;
@@ -3933,9 +3933,9 @@ class VegaConnection extends EventEmitter$1 {
3933
3933
  this.emit("message", socketMessage);
3934
3934
  }
3935
3935
  }
3936
- _onClose() {
3936
+ _onClose(event) {
3937
3937
  logger$3.info("Disconnected");
3938
- this._tearDown();
3938
+ this._tearDown(event);
3939
3939
  }
3940
3940
  _onError(error) {
3941
3941
  logger$3.info("Error", error);
@@ -6601,10 +6601,12 @@ function startPerformanceMonitor({ onMetricsUpdated, onTerminated, isHidden, })
6601
6601
  }
6602
6602
 
6603
6603
  const logger$1 = new Logger();
6604
+ const SFU_BASE_URL = "wss://any.sfu.svc.whereby.com";
6604
6605
  class BandwidthTester extends EventEmitter {
6605
- constructor({ features } = {}) {
6606
+ constructor({ token, features }) {
6606
6607
  super();
6607
6608
  this.closed = false;
6609
+ this._token = token;
6608
6610
  this._features = features || {};
6609
6611
  this._vegaConnection = null;
6610
6612
  this._mediasoupDeviceInitializedAsync = getMediasoupDeviceAsync(this._features);
@@ -6634,22 +6636,33 @@ class BandwidthTester extends EventEmitter {
6634
6636
  timeout: true,
6635
6637
  },
6636
6638
  });
6637
- return this.close();
6639
+ this.close();
6640
+ return;
6638
6641
  }
6639
6642
  this._runTime = runTime;
6640
6643
  this._startTime = Date.now();
6641
- const host = this._features.sfuServerOverrideHost || "any.sfu.svc.whereby.com";
6642
- const wsUrl = `wss://${host}`;
6643
- this._vegaConnection = new VegaConnection(wsUrl, { protocol: "whereby-sfu#bw-test-v1" });
6644
+ const host = this._features.sfuServerOverrideHost && !this._features.sfuServerOverrideHost.startsWith("wss://")
6645
+ ? `wss://${this._features.sfuServerOverrideHost}`
6646
+ : this._features.sfuServerOverrideHost || SFU_BASE_URL;
6647
+ const wsUrl = `${host}?bandwidthTestClaim=${this._token}`;
6648
+ this._vegaConnection = new VegaConnection(wsUrl, {
6649
+ protocol: "whereby-sfu#bw-test-v1",
6650
+ });
6644
6651
  this._vegaConnection.on("open", () => this._start());
6645
- this._vegaConnection.on("close", () => this.close(true));
6652
+ this._vegaConnection.on("close", (event) => this.close(true, event));
6646
6653
  this._vegaConnection.on("message", (message) => this._onMessage(message));
6647
6654
  this._startTimeout();
6648
6655
  }
6649
- close(vegaConnectionClosed) {
6656
+ close(vegaConnectionClosed, event) {
6650
6657
  logger$1.info("close()");
6651
6658
  this.closed = true;
6652
- if (!!this._timeout || Date.now() - this._startTime < 750) {
6659
+ if ((event === null || event === void 0 ? void 0 : event.code) === 1008) {
6660
+ this.emit("result", {
6661
+ error: true,
6662
+ details: Object.assign(Object.assign({}, ((event === null || event === void 0 ? void 0 : event.reason) === "invalidClaim" && { invalidClaim: true })), ((event === null || event === void 0 ? void 0 : event.reason) === "connectionTimeout" && { timeout: true })),
6663
+ });
6664
+ }
6665
+ else if (!!this._timeout || Date.now() - this._startTime < 750) {
6653
6666
  this.emit("result", {
6654
6667
  error: true,
6655
6668
  });
@@ -3904,7 +3904,7 @@ class VegaConnection extends EventEmitter$1 {
3904
3904
  this.socket.onclose = this._onClose.bind(this);
3905
3905
  this.socket.onerror = this._onError.bind(this);
3906
3906
  }
3907
- _tearDown() {
3907
+ _tearDown(event) {
3908
3908
  if (this.socket === null)
3909
3909
  return;
3910
3910
  this.socket.onopen = null;
@@ -3913,7 +3913,7 @@ class VegaConnection extends EventEmitter$1 {
3913
3913
  this.socket.onerror = null;
3914
3914
  this.socket = null;
3915
3915
  this.sents.forEach((sent) => sent.close());
3916
- this.emit("close");
3916
+ this.emit("close", event);
3917
3917
  }
3918
3918
  close() {
3919
3919
  var _a;
@@ -3933,9 +3933,9 @@ class VegaConnection extends EventEmitter$1 {
3933
3933
  this.emit("message", socketMessage);
3934
3934
  }
3935
3935
  }
3936
- _onClose() {
3936
+ _onClose(event) {
3937
3937
  logger$3.info("Disconnected");
3938
- this._tearDown();
3938
+ this._tearDown(event);
3939
3939
  }
3940
3940
  _onError(error) {
3941
3941
  logger$3.info("Error", error);
@@ -6601,10 +6601,12 @@ function startPerformanceMonitor({ onMetricsUpdated, onTerminated, isHidden, })
6601
6601
  }
6602
6602
 
6603
6603
  const logger$1 = new Logger();
6604
+ const SFU_BASE_URL = "wss://any.sfu.svc.whereby.com";
6604
6605
  class BandwidthTester extends EventEmitter {
6605
- constructor({ features } = {}) {
6606
+ constructor({ token, features }) {
6606
6607
  super();
6607
6608
  this.closed = false;
6609
+ this._token = token;
6608
6610
  this._features = features || {};
6609
6611
  this._vegaConnection = null;
6610
6612
  this._mediasoupDeviceInitializedAsync = getMediasoupDeviceAsync(this._features);
@@ -6634,22 +6636,33 @@ class BandwidthTester extends EventEmitter {
6634
6636
  timeout: true,
6635
6637
  },
6636
6638
  });
6637
- return this.close();
6639
+ this.close();
6640
+ return;
6638
6641
  }
6639
6642
  this._runTime = runTime;
6640
6643
  this._startTime = Date.now();
6641
- const host = this._features.sfuServerOverrideHost || "any.sfu.svc.whereby.com";
6642
- const wsUrl = `wss://${host}`;
6643
- this._vegaConnection = new VegaConnection(wsUrl, { protocol: "whereby-sfu#bw-test-v1" });
6644
+ const host = this._features.sfuServerOverrideHost && !this._features.sfuServerOverrideHost.startsWith("wss://")
6645
+ ? `wss://${this._features.sfuServerOverrideHost}`
6646
+ : this._features.sfuServerOverrideHost || SFU_BASE_URL;
6647
+ const wsUrl = `${host}?bandwidthTestClaim=${this._token}`;
6648
+ this._vegaConnection = new VegaConnection(wsUrl, {
6649
+ protocol: "whereby-sfu#bw-test-v1",
6650
+ });
6644
6651
  this._vegaConnection.on("open", () => this._start());
6645
- this._vegaConnection.on("close", () => this.close(true));
6652
+ this._vegaConnection.on("close", (event) => this.close(true, event));
6646
6653
  this._vegaConnection.on("message", (message) => this._onMessage(message));
6647
6654
  this._startTimeout();
6648
6655
  }
6649
- close(vegaConnectionClosed) {
6656
+ close(vegaConnectionClosed, event) {
6650
6657
  logger$1.info("close()");
6651
6658
  this.closed = true;
6652
- if (!!this._timeout || Date.now() - this._startTime < 750) {
6659
+ if ((event === null || event === void 0 ? void 0 : event.code) === 1008) {
6660
+ this.emit("result", {
6661
+ error: true,
6662
+ details: Object.assign(Object.assign({}, ((event === null || event === void 0 ? void 0 : event.reason) === "invalidClaim" && { invalidClaim: true })), ((event === null || event === void 0 ? void 0 : event.reason) === "connectionTimeout" && { timeout: true })),
6663
+ });
6664
+ }
6665
+ else if (!!this._timeout || Date.now() - this._startTime < 750) {
6653
6666
  this.emit("result", {
6654
6667
  error: true,
6655
6668
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@whereby.com/media",
3
3
  "description": "Media library for Whereby",
4
- "version": "11.0.0",
4
+ "version": "11.1.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {