@vkontakte/calls-sdk 2.8.12-beta.1 → 2.8.12-beta.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/calls-sdk.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @vkontakte/calls-sdk v2.8.12-beta.1
3
- * Fri, 24 Jul 2026 10:37:01 GMT
2
+ * @vkontakte/calls-sdk v2.8.12-beta.3
3
+ * Tue, 28 Jul 2026 09:15:22 GMT
4
4
  * https://calls-sdk.cdn-vk.ru/doc/latest/index.html
5
5
  */
6
6
 
@@ -2159,7 +2159,7 @@ var mn = pn.getInstance(), M = class e {
2159
2159
  return 1.1;
2160
2160
  }
2161
2161
  static get sdkVersion() {
2162
- return "2.8.12-beta.1";
2162
+ return "2.8.12-beta.3";
2163
2163
  }
2164
2164
  static get debug() {
2165
2165
  return e._params.debug;
@@ -6621,8 +6621,32 @@ var fa = da, pa = {
6621
6621
  }
6622
6622
  }
6623
6623
  }, Ca = class {
6624
+ static isBrowserSupported() {
6625
+ return !(!("WebTransport" in window && typeof WebTransport == "function") || T.browserName() === "Safari");
6626
+ }
6624
6627
  constructor(e, t = {}, n = R) {
6625
- h(this, "webTransport", void 0), h(this, "stream", null), h(this, "writer", null), h(this, "reader", null), h(this, "url", void 0), h(this, "options", void 0), h(this, "compression", void 0), h(this, "closeRequested", null), h(this, "closeEventEmitted", !1), h(this, "encoder", void 0), h(this, "decoder", void 0), h(this, "_debug", void 0), h(this, "onopen", null), h(this, "onmessage", null), h(this, "onerror", null), h(this, "onclose", null), h(this, "readyState", WebSocket.CONNECTING), this._debug = n, this.url = e, this.options = t, this.readyState = WebSocket.CONNECTING, this.compression = this.getCompressionTypeFromUrl(e), this.encoder = new xa(this.compression), this.decoder = new Sa(this.compression), this.connect();
6628
+ h(this, "onopen", null), h(this, "onmessage", null), h(this, "onerror", null), h(this, "onclose", null), h(this, "readyState", WebSocket.CONNECTING), h(this, "webTransport", null), h(this, "writer", null), h(this, "url", void 0), h(this, "options", void 0), h(this, "compression", void 0), h(this, "encoder", void 0), h(this, "decoder", void 0), h(this, "_debug", void 0), this._debug = n, this.url = e, this.options = t, this.compression = this.getCompressionTypeFromUrl(e), this.encoder = new xa(this.compression), this.decoder = new Sa(this.compression), this.connect();
6629
+ }
6630
+ async send(e) {
6631
+ if (this.readyState !== WebSocket.OPEN) {
6632
+ this._debug.warn("[WebTransport] Attempt to send data before webtransport is open");
6633
+ return;
6634
+ }
6635
+ let t = this.writer;
6636
+ if (!t) {
6637
+ this._debug.warn("[WebTransport] Attempt to send data before stream is ready");
6638
+ return;
6639
+ }
6640
+ try {
6641
+ await t.ready;
6642
+ let n = this.encoder.encode(e);
6643
+ await t.write(n);
6644
+ } catch (e) {
6645
+ this.handleStreamError("send", e);
6646
+ }
6647
+ }
6648
+ close(e = 1e3, t = "") {
6649
+ this.readyState === WebSocket.CLOSING || this.readyState === WebSocket.CLOSED || (this.readyState = WebSocket.CLOSING, this.requestNativeClose(e, t));
6626
6650
  }
6627
6651
  getCompressionTypeFromUrl(e) {
6628
6652
  try {
@@ -6639,60 +6663,81 @@ var fa = da, pa = {
6639
6663
  }
6640
6664
  async connect() {
6641
6665
  try {
6642
- if (this.webTransport = new WebTransport(this.url, { ...this.options }), this.webTransport.closed.catch((e) => {
6643
- this._debug.warn("[WebTransport] Native transport closed with error", e);
6644
- }), await this.webTransport.ready, this.closeRequested) {
6645
- this.closeConnectedTransport(this.closeRequested.code, this.closeRequested.reason);
6646
- return;
6647
- }
6648
- this._debug.debug("[WebTransport] WebTransport connected to " + this.url), this.stream = await this.webTransport.createBidirectionalStream(), this.writer = this.stream.writable.getWriter(), this.reader = this.stream.readable.getReader(), this.readyState = WebSocket.OPEN, this.onopen?.(new Event("open")), await this.readLoop();
6666
+ let e = new WebTransport(this.url, { ...this.options });
6667
+ if (this.webTransport = e, this.observeClosed(e), await e.ready, this.readyState !== WebSocket.CONNECTING) return;
6668
+ this._debug.debug("[WebTransport] WebTransport connected to " + this.url);
6669
+ let t = await e.createBidirectionalStream();
6670
+ if (this.readyState !== WebSocket.CONNECTING) return;
6671
+ this.writer = t.writable.getWriter(), this.readyState = WebSocket.OPEN, this.emitEvent("open", this.onopen, new Event("open")), this.readyState === WebSocket.OPEN && this.readLoop(t.readable);
6649
6672
  } catch (e) {
6650
- if (this.closeRequested) {
6651
- this.readyState = WebSocket.CLOSED, this.emitClose(this.closeRequested.code, this.closeRequested.reason);
6673
+ if (!this.webTransport) {
6674
+ queueMicrotask(() => this.fail("connect", e));
6652
6675
  return;
6653
6676
  }
6654
- this._debug.error("[WebTransport] WebTransport connection failed. This will cause fallback to WebSocket", e), this.readyState = WebSocket.CLOSED, this.onerror?.(this.createErrorEvent(e, "connect")), this.onclose?.(new CloseEvent("close", {
6655
- code: 1006,
6656
- reason: "Connection Failed"
6657
- }));
6677
+ this.fail("connect", e);
6658
6678
  }
6659
6679
  }
6660
- async *readChunks() {
6661
- if (this.reader) try {
6680
+ observeClosed(e) {
6681
+ e.closed.then(({ closeCode: e, reason: t }) => {
6682
+ this.finishClose(e, t);
6683
+ }, (e) => {
6684
+ let t = this.readyState === WebSocket.CONNECTING ? "connect" : "session";
6685
+ this.fail(t, e), this.finishClose(1006, "");
6686
+ }).catch((e) => {
6687
+ this._debug.error("[WebTransport] Failed to process native close", e);
6688
+ });
6689
+ }
6690
+ async readLoop(e) {
6691
+ let t = e.getReader();
6692
+ try {
6662
6693
  for (;;) {
6663
- let { done: e, value: t } = await this.reader.read();
6664
- if (e) break;
6665
- t && (yield t);
6694
+ let { done: e, value: n } = await t.read();
6695
+ if (e) {
6696
+ this.close(1e3, "Stream Closed");
6697
+ return;
6698
+ }
6699
+ if (n) for (let e of this.decoder.decode(n)) this.emitEvent("message", this.onmessage, new MessageEvent("message", { data: e }));
6666
6700
  }
6701
+ } catch (e) {
6702
+ this.handleStreamError("read", e);
6667
6703
  } finally {
6668
- this.reader.releaseLock();
6704
+ t.releaseLock();
6669
6705
  }
6670
6706
  }
6671
- async readLoop() {
6672
- if (this.reader) try {
6673
- for await (let e of this.readChunks()) this.decoder.decode(e).forEach((e) => {
6674
- this.onmessage?.(new MessageEvent("message", { data: e }));
6675
- });
6676
- this.close(1e3, "Stream Closed");
6677
- } catch (e) {
6678
- this._debug.error("[WebTransport] Stream read failed", e), this.readyState = WebSocket.CLOSED, this.onerror?.(this.createErrorEvent(e, "read"));
6679
- }
6707
+ fail(e, t) {
6708
+ this.readyState === WebSocket.CLOSING || this.readyState === WebSocket.CLOSED || (this.readyState = WebSocket.CLOSING, this._debug.error(`[WebTransport] ${e} failed`, t), this.emitEvent("error", this.onerror, this.createErrorEvent(t, e)), this.requestNativeClose(1006, `${e} failed`));
6680
6709
  }
6681
- async send(e) {
6682
- if (this.readyState !== WebSocket.OPEN) {
6683
- this._debug.warn("[WebTransport] Attempt to send data before webtransport is open");
6684
- return;
6685
- }
6686
- if (!this.writer) {
6687
- this._debug.warn("[WebTransport] Attempt to send data before stream is ready");
6710
+ handleStreamError(e, t) {
6711
+ let n = typeof t == "object" && t && "source" in t ? t.source : void 0;
6712
+ if (n === "session") return;
6713
+ let r = n === void 0 && t instanceof Error && t.name === "WebTransportError" && t.message.startsWith("Session closed");
6714
+ this.fail(r ? "session" : e, t);
6715
+ }
6716
+ requestNativeClose(e, t) {
6717
+ if (!this.webTransport) {
6718
+ this.finishClose(1006, "Connection Failed");
6688
6719
  return;
6689
6720
  }
6690
6721
  try {
6691
- await this.writer.ready;
6692
- let t = this.encoder.encode(e);
6693
- await this.writer.write(t);
6722
+ this.webTransport.close({
6723
+ closeCode: e,
6724
+ reason: t
6725
+ });
6694
6726
  } catch (e) {
6695
- this._debug.error("[WebTransport] Failed to send data", e), this.onerror?.(this.createErrorEvent(e, "send")), this.close(1006, "Failed to send data");
6727
+ this._debug.warn("[WebTransport] Native close failed synchronously", e), this.finishClose(1006, "Close Failed");
6728
+ }
6729
+ }
6730
+ finishClose(e, t) {
6731
+ this.readyState !== WebSocket.CLOSED && (this.writer = null, this.readyState = WebSocket.CLOSED, this.emitEvent("close", this.onclose, new CloseEvent("close", {
6732
+ code: e,
6733
+ reason: t
6734
+ })));
6735
+ }
6736
+ emitEvent(e, t, n) {
6737
+ try {
6738
+ t?.call(this, n);
6739
+ } catch (t) {
6740
+ this._debug.error(`[WebTransport] ${e} handler failed`, t);
6696
6741
  }
6697
6742
  }
6698
6743
  createErrorEvent(e, t) {
@@ -6706,40 +6751,6 @@ var fa = da, pa = {
6706
6751
  compression: this.compression
6707
6752
  }, n;
6708
6753
  }
6709
- close(e = 1e3, t) {
6710
- if (!(this.readyState === WebSocket.CLOSED || this.readyState === WebSocket.CLOSING)) {
6711
- if (this.closeRequested = {
6712
- code: e,
6713
- reason: t
6714
- }, this.readyState === WebSocket.CONNECTING) {
6715
- this.readyState = WebSocket.CLOSING;
6716
- return;
6717
- }
6718
- this.closeConnectedTransport(e, t);
6719
- }
6720
- }
6721
- closeConnectedTransport(e = 1e3, t) {
6722
- if (this.readyState !== WebSocket.CLOSED) {
6723
- this.readyState = WebSocket.CLOSING, this.reader?.cancel();
6724
- try {
6725
- this.webTransport.close();
6726
- } catch (e) {
6727
- this._debug.warn("[WebTransport] already closed. Did we get a STOP_SENDING? ignore", e);
6728
- }
6729
- this.readyState = WebSocket.CLOSED, this.emitClose(e, t), this.webTransport.closed.then(() => {
6730
- this.writer = null, this.reader = null, this.stream = null;
6731
- });
6732
- }
6733
- }
6734
- emitClose(e, t) {
6735
- this.closeEventEmitted || (this.closeEventEmitted = !0, this.onclose?.(new CloseEvent("close", {
6736
- code: e,
6737
- reason: t
6738
- })));
6739
- }
6740
- static isBrowserSupported() {
6741
- return !(!("WebTransport" in window && typeof WebTransport == "function") || T.browserName() === "Safari");
6742
- }
6743
6754
  }, wa = /* @__PURE__ */ function(e) {
6744
6755
  return e.EMPTY_ENDPOINT = "EMPTY_ENDPOINT", e.NETWORK_ERROR = "NETWORK_ERROR", e.ABORTED = "ABORTED", e;
6745
6756
  }({}), Ta = class {
@@ -6834,7 +6845,7 @@ var fa = da, pa = {
6834
6845
  });
6835
6846
  return;
6836
6847
  }
6837
- this.forceWebSocket = !0, this._scheduleReconnect();
6848
+ this.forceWebSocket = !0, this._scheduleReconnect(this.currentType === fr.WEBTRANSPORT ? 0 : void 0);
6838
6849
  }
6839
6850
  }
6840
6851
  _disconnect(e) {
@@ -7304,7 +7315,7 @@ var fa = da, pa = {
7304
7315
  }));
7305
7316
  break;
7306
7317
  default:
7307
- if (!t) break;
7318
+ if (!t || t && this._getSocketType() === fr.WEBTRANSPORT) break;
7308
7319
  this.connected ? this._throwError(/* @__PURE__ */ Error(`Signaling error: ${e.error}`)) : e.sequence || (this.conversationReject?.(new O(e.reason || b.SIGNALING_FAILED, {
7309
7320
  message: `Unable to connect to the signaling: ${e.error}`,
7310
7321
  remote: !0
@@ -1,15 +1,15 @@
1
1
  import BaseSignaling, { AddParticipantParams } from '../abstract/BaseSignaling';
2
- import StatsLogger from '../classes/StatsLogger';
3
2
  import { ParticipantIdRegistry } from '../classes/ParticipantIdRegistry';
4
3
  import { SharingStatReport } from '../classes/screenshare/SharingStatReport';
5
4
  import { StatAggregator } from '../classes/stat/StatAggregator';
6
5
  import { StatPings } from '../classes/stat/StatPings';
7
6
  import { StatSignalingCommands } from '../classes/stat/StatSignalingCommands';
8
- import TransportTopology from '../enums/TransportTopology';
7
+ import StatsLogger from '../classes/StatsLogger';
9
8
  import ConversationFeature from '../enums/ConversationFeature';
10
9
  import ConversationOption from '../enums/ConversationOption';
11
10
  import MediaOption from '../enums/MediaOption';
12
11
  import SignalingConnectionType from '../enums/SignalingConnectionType';
12
+ import TransportTopology from '../enums/TransportTopology';
13
13
  import UserRole from '../enums/UserRole';
14
14
  import { type DebugLogger } from '../static/Debug';
15
15
  import { JSONObject } from '../static/Json';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vkontakte/calls-sdk",
3
- "version": "2.8.12-beta.1",
3
+ "version": "2.8.12-beta.3",
4
4
  "author": "vk.com",
5
5
  "description": "Library for video calls based on the vk.com platform",
6
6
  "homepage": "https://vk.com",
@@ -1,33 +1,32 @@
1
1
  import { WebTransportOptions } from '@fails-components/webtransport';
2
2
  import { DebugLogger } from '../static/Debug';
3
3
  declare class WebTransportEventual {
4
+ static isBrowserSupported(): boolean;
5
+ onopen: ((this: WebTransportEventual, ev: Event) => any) | null;
6
+ onmessage: ((this: WebTransportEventual, ev: MessageEvent) => any) | null;
7
+ onerror: ((this: WebTransportEventual, ev: Event) => any) | null;
8
+ onclose: ((this: WebTransportEventual, ev: CloseEvent) => any) | null;
9
+ readyState: number;
4
10
  private webTransport;
5
- private stream;
6
11
  private writer;
7
- private reader;
8
12
  private readonly url;
9
13
  private readonly options;
10
14
  private readonly compression;
11
- private closeRequested;
12
- private closeEventEmitted;
13
15
  private encoder;
14
16
  private decoder;
15
17
  private readonly _debug;
16
- onopen: ((this: WebTransportEventual, ev: Event) => any) | null;
17
- onmessage: ((this: WebTransportEventual, ev: MessageEvent) => any) | null;
18
- onerror: ((this: WebTransportEventual, ev: Event) => any) | null;
19
- onclose: ((this: WebTransportEventual, ev: CloseEvent) => any) | null;
20
- readyState: number;
21
18
  constructor(url: string, options?: WebTransportOptions, debug?: DebugLogger);
19
+ send(data: string): Promise<void>;
20
+ close(code?: number, reason?: string): void;
22
21
  private getCompressionTypeFromUrl;
23
22
  private connect;
24
- private readChunks;
23
+ private observeClosed;
25
24
  private readLoop;
26
- send(data: string): Promise<void>;
25
+ private fail;
26
+ private handleStreamError;
27
+ private requestNativeClose;
28
+ private finishClose;
29
+ private emitEvent;
27
30
  private createErrorEvent;
28
- close(code?: number, reason?: string): void;
29
- private closeConnectedTransport;
30
- private emitClose;
31
- static isBrowserSupported(): boolean;
32
31
  }
33
32
  export { WebTransportEventual as WebTransport };