UNPKG

@huddle01/web-core

Version:

The Huddle01 Javascript SDK offers a comprehensive suite of methods and event listeners that allow for seamless real-time audio and video communication with minimal coding required.

2,161 lines 73.1 kB
'use strict';

var chunk3S34XHJL_cjs = require('./chunk-3S34XHJL.cjs');
var chunkHX55BIO2_cjs = require('./chunk-HX55BIO2.cjs');
var chunkHS7ILUYH_cjs = require('./chunk-HS7ILUYH.cjs');
var chunkUM7UGER4_cjs = require('./chunk-UM7UGER4.cjs');
var chunkNYECY7ZG_cjs = require('./chunk-NYECY7ZG.cjs');
var chunkO5HDCTOE_cjs = require('./chunk-O5HDCTOE.cjs');
var chunkUIH7JJYU_cjs = require('./chunk-UIH7JJYU.cjs');

// ../types/dist/socket.types.js
exports.ESocketCloseCode = void 0;
(function(ESocketCloseCode2) {
  ESocketCloseCode2[ESocketCloseCode2["ABNORMAL_CLOSURE"] = 1006] = "ABNORMAL_CLOSURE";
  ESocketCloseCode2[ESocketCloseCode2["NORMAL_CLOSURE"] = 1e3] = "NORMAL_CLOSURE";
  ESocketCloseCode2[ESocketCloseCode2["BROWSER_TAB_CLOSE"] = 1001] = "BROWSER_TAB_CLOSE";
  ESocketCloseCode2[ESocketCloseCode2["GOING_AWAY"] = 4001] = "GOING_AWAY";
  ESocketCloseCode2[ESocketCloseCode2["CONNECTION_EXPIRED"] = 4002] = "CONNECTION_EXPIRED";
  ESocketCloseCode2[ESocketCloseCode2["CONNECTION_ERROR"] = 4006] = "CONNECTION_ERROR";
  ESocketCloseCode2[ESocketCloseCode2["ROOM_CLOSED"] = 4007] = "ROOM_CLOSED";
  ESocketCloseCode2[ESocketCloseCode2["ROOM_ENTRY_DENIED"] = 4008] = "ROOM_ENTRY_DENIED";
  ESocketCloseCode2[ESocketCloseCode2["KICKED"] = 4009] = "KICKED";
  ESocketCloseCode2[ESocketCloseCode2["MAX_PEERS_REACHED"] = 4010] = "MAX_PEERS_REACHED";
  ESocketCloseCode2[ESocketCloseCode2["ROOM_EXPIRED"] = 4011] = "ROOM_EXPIRED";
})(exports.ESocketCloseCode || (exports.ESocketCloseCode = {}));
var SocketCloseReason = {
  [exports.ESocketCloseCode.ROOM_CLOSED]: "ROOM_CLOSED",
  [exports.ESocketCloseCode.ABNORMAL_CLOSURE]: "ABNORMAL_CLOSURE",
  [exports.ESocketCloseCode.NORMAL_CLOSURE]: "NORMAL_CLOSURE",
  [exports.ESocketCloseCode.BROWSER_TAB_CLOSE]: "BROWSER_TAB_CLOSE",
  [exports.ESocketCloseCode.GOING_AWAY]: "GOING_AWAY",
  [exports.ESocketCloseCode.CONNECTION_ERROR]: "CONNECTION_ERROR",
  [exports.ESocketCloseCode.CONNECTION_EXPIRED]: "CONNECTION_EXPIRED",
  [exports.ESocketCloseCode.ROOM_ENTRY_DENIED]: "ROOM_ENTRY_DENIED",
  [exports.ESocketCloseCode.KICKED]: "KICKED",
  [exports.ESocketCloseCode.MAX_PEERS_REACHED]: "MAX_PEERS_REACHED",
  [exports.ESocketCloseCode.ROOM_EXPIRED]: "ROOM_EXPIRED"
};

// ../protoc/dist/rtc/rtp_capabilities_pb.js
var ProtoRtpCodecCapability = class _ProtoRtpCodecCapability extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: string kind = 1;
   */
  kind = "";
  /**
   * @generated from field: string mimeType = 2;
   */
  mimeType = "";
  /**
   * @generated from field: int32 preferredPayloadType = 3;
   */
  preferredPayloadType = 0;
  /**
   * @generated from field: int32 clockRate = 4;
   */
  clockRate = 0;
  /**
   * @generated from field: int32 channels = 5;
   */
  channels = 0;
  /**
   * @generated from field: map<string, string> parameters = 6;
   */
  parameters = {};
  /**
   * @generated from field: repeated ProtoRtpCodecCapability.ProtoRtcpFeedback rtcpFeedback = 7;
   */
  rtcpFeedback = [];
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto3.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto3;
  static typeName = "ProtoRtpCodecCapability";
  static fields = chunkUM7UGER4_cjs.proto3.util.newFieldList(() => [
    {
      no: 1,
      name: "kind",
      kind: "scalar",
      T: 9
      /* ScalarType.STRING */
    },
    {
      no: 2,
      name: "mimeType",
      kind: "scalar",
      T: 9
      /* ScalarType.STRING */
    },
    {
      no: 3,
      name: "preferredPayloadType",
      kind: "scalar",
      T: 5
      /* ScalarType.INT32 */
    },
    {
      no: 4,
      name: "clockRate",
      kind: "scalar",
      T: 5
      /* ScalarType.INT32 */
    },
    {
      no: 5,
      name: "channels",
      kind: "scalar",
      T: 5
      /* ScalarType.INT32 */
    },
    { no: 6, name: "parameters", kind: "map", K: 9, V: {
      kind: "scalar",
      T: 9
      /* ScalarType.STRING */
    } },
    { no: 7, name: "rtcpFeedback", kind: "message", T: ProtoRtpCodecCapability_ProtoRtcpFeedback, repeated: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ProtoRtpCodecCapability().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ProtoRtpCodecCapability().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ProtoRtpCodecCapability().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto3.util.equals(_ProtoRtpCodecCapability, a, b);
  }
};
var ProtoRtpCodecCapability_ProtoRtcpFeedback = class _ProtoRtpCodecCapability_ProtoRtcpFeedback extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: string type = 1;
   */
  type = "";
  /**
   * @generated from field: string parameter = 2;
   */
  parameter = "";
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto3.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto3;
  static typeName = "ProtoRtpCodecCapability.ProtoRtcpFeedback";
  static fields = chunkUM7UGER4_cjs.proto3.util.newFieldList(() => [
    {
      no: 1,
      name: "type",
      kind: "scalar",
      T: 9
      /* ScalarType.STRING */
    },
    {
      no: 2,
      name: "parameter",
      kind: "scalar",
      T: 9
      /* ScalarType.STRING */
    }
  ]);
  static fromBinary(bytes, options) {
    return new _ProtoRtpCodecCapability_ProtoRtcpFeedback().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ProtoRtpCodecCapability_ProtoRtcpFeedback().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ProtoRtpCodecCapability_ProtoRtcpFeedback().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto3.util.equals(_ProtoRtpCodecCapability_ProtoRtcpFeedback, a, b);
  }
};
var ProtoRtpHeaderExtension = class _ProtoRtpHeaderExtension extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: string kind = 1;
   */
  kind = "";
  /**
   * @generated from field: string uri = 2;
   */
  uri = "";
  /**
   * @generated from field: int32 preferredId = 3;
   */
  preferredId = 0;
  /**
   * @generated from field: bool preferredEncrypt = 4;
   */
  preferredEncrypt = false;
  /**
   * @generated from field: string direction = 5;
   */
  direction = "";
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto3.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto3;
  static typeName = "ProtoRtpHeaderExtension";
  static fields = chunkUM7UGER4_cjs.proto3.util.newFieldList(() => [
    {
      no: 1,
      name: "kind",
      kind: "scalar",
      T: 9
      /* ScalarType.STRING */
    },
    {
      no: 2,
      name: "uri",
      kind: "scalar",
      T: 9
      /* ScalarType.STRING */
    },
    {
      no: 3,
      name: "preferredId",
      kind: "scalar",
      T: 5
      /* ScalarType.INT32 */
    },
    {
      no: 4,
      name: "preferredEncrypt",
      kind: "scalar",
      T: 8
      /* ScalarType.BOOL */
    },
    {
      no: 5,
      name: "direction",
      kind: "scalar",
      T: 9
      /* ScalarType.STRING */
    }
  ]);
  static fromBinary(bytes, options) {
    return new _ProtoRtpHeaderExtension().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ProtoRtpHeaderExtension().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ProtoRtpHeaderExtension().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto3.util.equals(_ProtoRtpHeaderExtension, a, b);
  }
};
var ProtoRtpCapabilities = class _ProtoRtpCapabilities extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: repeated ProtoRtpCodecCapability codecs = 1;
   */
  codecs = [];
  /**
   * @generated from field: repeated ProtoRtpHeaderExtension headerExtensions = 2;
   */
  headerExtensions = [];
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto3.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto3;
  static typeName = "ProtoRtpCapabilities";
  static fields = chunkUM7UGER4_cjs.proto3.util.newFieldList(() => [
    { no: 1, name: "codecs", kind: "message", T: ProtoRtpCodecCapability, repeated: true },
    { no: 2, name: "headerExtensions", kind: "message", T: ProtoRtpHeaderExtension, repeated: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ProtoRtpCapabilities().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ProtoRtpCapabilities().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ProtoRtpCapabilities().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto3.util.equals(_ProtoRtpCapabilities, a, b);
  }
};

// ../protoc/dist/client/response_pb.js
var Hello = class _Hello extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: required string roomId = 2;
   */
  roomId;
  /**
   * @generated from field: required string sessionId = 3;
   */
  sessionId;
  /**
   * @generated from field: required Permissions acl = 4;
   */
  acl;
  /**
   * @generated from field: optional string role = 5;
   */
  role;
  /**
   * @generated from field: optional string metadata = 6;
   */
  metadata;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "Hello";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "roomId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "sessionId", kind: "scalar", T: 9, req: true },
    { no: 4, name: "acl", kind: "message", T: chunkHS7ILUYH_cjs.Permissions, req: true },
    { no: 5, name: "role", kind: "scalar", T: 9, opt: true },
    { no: 6, name: "metadata", kind: "scalar", T: 9, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _Hello().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _Hello().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _Hello().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_Hello, a, b);
  }
};
var RoomControls = class _RoomControls extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required bool roomLocked = 1;
   */
  roomLocked;
  /**
   * @generated from field: required bool allowProduce = 2;
   */
  allowProduce;
  /**
   * @generated from field: required RoomControls.ProduceSources allowProduceSources = 3;
   */
  allowProduceSources;
  /**
   * @generated from field: required bool allowConsume = 4;
   */
  allowConsume;
  /**
   * @generated from field: required bool allowSendData = 5;
   */
  allowSendData;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "RoomControls";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "roomLocked", kind: "scalar", T: 8, req: true },
    { no: 2, name: "allowProduce", kind: "scalar", T: 8, req: true },
    { no: 3, name: "allowProduceSources", kind: "message", T: RoomControls_ProduceSources, req: true },
    { no: 4, name: "allowConsume", kind: "scalar", T: 8, req: true },
    { no: 5, name: "allowSendData", kind: "scalar", T: 8, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _RoomControls().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _RoomControls().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _RoomControls().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_RoomControls, a, b);
  }
};
var RoomControls_ProduceSources = class _RoomControls_ProduceSources extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required bool cam = 1;
   */
  cam;
  /**
   * @generated from field: required bool mic = 2;
   */
  mic;
  /**
   * @generated from field: required bool screen = 3;
   */
  screen;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "RoomControls.ProduceSources";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "cam", kind: "scalar", T: 8, req: true },
    { no: 2, name: "mic", kind: "scalar", T: 8, req: true },
    { no: 3, name: "screen", kind: "scalar", T: 8, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _RoomControls_ProduceSources().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _RoomControls_ProduceSources().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _RoomControls_ProduceSources().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_RoomControls_ProduceSources, a, b);
  }
};
var PeersInfo = class _PeersInfo extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: optional string metadata = 3;
   */
  metadata;
  /**
   * @generated from field: optional string role = 5;
   */
  role;
  /**
   * @generated from field: repeated PeersInfo.ProducerInfo producers = 4;
   */
  producers = [];
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "PeersInfo";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "metadata", kind: "scalar", T: 9, opt: true },
    { no: 5, name: "role", kind: "scalar", T: 9, opt: true },
    { no: 4, name: "producers", kind: "message", T: PeersInfo_ProducerInfo, repeated: true }
  ]);
  static fromBinary(bytes, options) {
    return new _PeersInfo().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _PeersInfo().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _PeersInfo().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_PeersInfo, a, b);
  }
};
var PeersInfo_ProducerInfo = class _PeersInfo_ProducerInfo extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string id = 1;
   */
  id;
  /**
   * @generated from field: required string label = 2;
   */
  label;
  /**
   * @generated from field: optional bool paused = 3;
   */
  paused;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "PeersInfo.ProducerInfo";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "id", kind: "scalar", T: 9, req: true },
    { no: 2, name: "label", kind: "scalar", T: 9, req: true },
    { no: 3, name: "paused", kind: "scalar", T: 8, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _PeersInfo_ProducerInfo().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _PeersInfo_ProducerInfo().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _PeersInfo_ProducerInfo().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_PeersInfo_ProducerInfo, a, b);
  }
};
var RoomInfo = class _RoomInfo extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required bool roomLocked = 1;
   */
  roomLocked;
  /**
   * @generated from field: required RoomControls config = 2;
   */
  config;
  /**
   * @generated from field: repeated PeersInfo peers = 3;
   */
  peers = [];
  /**
   * @generated from field: repeated LobbyPeers lobbyPeers = 4;
   */
  lobbyPeers = [];
  /**
   * @generated from field: optional string metadata = 5;
   */
  metadata;
  /**
   * @generated from field: required int64 startTime = 6;
   */
  startTime;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "RoomInfo";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "roomLocked", kind: "scalar", T: 8, req: true },
    { no: 2, name: "config", kind: "message", T: RoomControls, req: true },
    { no: 3, name: "peers", kind: "message", T: PeersInfo, repeated: true },
    { no: 4, name: "lobbyPeers", kind: "message", T: LobbyPeers, repeated: true },
    { no: 5, name: "metadata", kind: "scalar", T: 9, opt: true },
    { no: 6, name: "startTime", kind: "scalar", T: 3, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _RoomInfo().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _RoomInfo().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _RoomInfo().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_RoomInfo, a, b);
  }
};
var LobbyPeers = class _LobbyPeers extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: optional string metadata = 3;
   */
  metadata;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "LobbyPeers";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "metadata", kind: "scalar", T: 9, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _LobbyPeers().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _LobbyPeers().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _LobbyPeers().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_LobbyPeers, a, b);
  }
};
var ConnectRoomResponse = class _ConnectRoomResponse extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string roomId = 1;
   */
  roomId;
  /**
   * @generated from field: required RoomInfo roomInfo = 2;
   */
  roomInfo;
  /**
   * @generated from field: required ProtoRtpCapabilities routerRTPCapabilities = 3;
   */
  routerRTPCapabilities;
  /**
   * @generated from field: repeated ConnectRoomResponse.RTCIceServer turnServers = 4;
   */
  turnServers = [];
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "ConnectRoomResponse";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "roomId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "roomInfo", kind: "message", T: RoomInfo, req: true },
    { no: 3, name: "routerRTPCapabilities", kind: "message", T: ProtoRtpCapabilities, req: true },
    { no: 4, name: "turnServers", kind: "message", T: ConnectRoomResponse_RTCIceServer, repeated: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ConnectRoomResponse().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ConnectRoomResponse().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ConnectRoomResponse().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_ConnectRoomResponse, a, b);
  }
};
var ConnectRoomResponse_RTCIceServer = class _ConnectRoomResponse_RTCIceServer extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string urls = 1;
   */
  urls;
  /**
   * @generated from field: optional string username = 2;
   */
  username;
  /**
   * @generated from field: optional string credential = 3;
   */
  credential;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "ConnectRoomResponse.RTCIceServer";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "urls", kind: "scalar", T: 9, req: true },
    { no: 2, name: "username", kind: "scalar", T: 9, opt: true },
    { no: 3, name: "credential", kind: "scalar", T: 9, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ConnectRoomResponse_RTCIceServer().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ConnectRoomResponse_RTCIceServer().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ConnectRoomResponse_RTCIceServer().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_ConnectRoomResponse_RTCIceServer, a, b);
  }
};
var CreateTransportOnClient = class _CreateTransportOnClient extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string transportType = 1;
   */
  transportType;
  /**
   * @generated from field: required ProtoTransportSDPInfo transportSDPInfo = 2;
   */
  transportSDPInfo;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "CreateTransportOnClient";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "transportType", kind: "scalar", T: 9, req: true },
    { no: 2, name: "transportSDPInfo", kind: "message", T: chunkHS7ILUYH_cjs.ProtoTransportSDPInfo, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _CreateTransportOnClient().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _CreateTransportOnClient().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _CreateTransportOnClient().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_CreateTransportOnClient, a, b);
  }
};
var ConnectTransportResponse = class _ConnectTransportResponse extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string transportType = 1;
   */
  transportType;
  /**
   * @generated from field: required string transportId = 2;
   */
  transportId;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "ConnectTransportResponse";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "transportType", kind: "scalar", T: 9, req: true },
    { no: 2, name: "transportId", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ConnectTransportResponse().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ConnectTransportResponse().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ConnectTransportResponse().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_ConnectTransportResponse, a, b);
  }
};
var ProduceResponse = class _ProduceResponse extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: required string producerId = 2;
   */
  producerId;
  /**
   * @generated from field: required string label = 3;
   */
  label;
  /**
   * @generated from field: optional AppData appData = 4;
   */
  appData;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "ProduceResponse";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "producerId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "label", kind: "scalar", T: 9, req: true },
    { no: 4, name: "appData", kind: "message", T: chunkHS7ILUYH_cjs.AppData, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ProduceResponse().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ProduceResponse().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ProduceResponse().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_ProduceResponse, a, b);
  }
};
var ProduceDataResponse = class _ProduceDataResponse extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string id = 1;
   */
  id;
  /**
   * @generated from field: required string dataProducerId = 2;
   */
  dataProducerId;
  /**
   * @generated from field: required string label = 3;
   */
  label;
  /**
   * @generated from field: required string peerId = 4;
   */
  peerId;
  /**
   * @generated from field: required string protocol = 5;
   */
  protocol;
  /**
   * @generated from field: required ProtoSctpStreamParameters sctpStreamParameters = 6;
   */
  sctpStreamParameters;
  /**
   * @generated from field: optional AppData appData = 7;
   */
  appData;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "ProduceDataResponse";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "id", kind: "scalar", T: 9, req: true },
    { no: 2, name: "dataProducerId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "label", kind: "scalar", T: 9, req: true },
    { no: 4, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 5, name: "protocol", kind: "scalar", T: 9, req: true },
    { no: 6, name: "sctpStreamParameters", kind: "message", T: chunkHS7ILUYH_cjs.ProtoSctpStreamParameters, req: true },
    { no: 7, name: "appData", kind: "message", T: chunkHS7ILUYH_cjs.AppData, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ProduceDataResponse().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ProduceDataResponse().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ProduceDataResponse().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_ProduceDataResponse, a, b);
  }
};
var ConsumeDataResponse = class _ConsumeDataResponse extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string id = 1;
   */
  id;
  /**
   * @generated from field: required string dataProducerId = 2;
   */
  dataProducerId;
  /**
   * @generated from field: required string label = 3;
   */
  label;
  /**
   * @generated from field: required string peerId = 4;
   */
  peerId;
  /**
   * @generated from field: required string protocol = 5;
   */
  protocol;
  /**
   * @generated from field: required ProtoSctpStreamParameters sctpStreamParameters = 6;
   */
  sctpStreamParameters;
  /**
   * @generated from field: optional AppData appData = 7;
   */
  appData;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "ConsumeDataResponse";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "id", kind: "scalar", T: 9, req: true },
    { no: 2, name: "dataProducerId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "label", kind: "scalar", T: 9, req: true },
    { no: 4, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 5, name: "protocol", kind: "scalar", T: 9, req: true },
    { no: 6, name: "sctpStreamParameters", kind: "message", T: chunkHS7ILUYH_cjs.ProtoSctpStreamParameters, req: true },
    { no: 7, name: "appData", kind: "message", T: chunkHS7ILUYH_cjs.AppData, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ConsumeDataResponse().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ConsumeDataResponse().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ConsumeDataResponse().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_ConsumeDataResponse, a, b);
  }
};
var SyncMeetingStateResponse = class _SyncMeetingStateResponse extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required RoomInfo roomInfo = 1;
   */
  roomInfo;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "SyncMeetingStateResponse";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "roomInfo", kind: "message", T: RoomInfo, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _SyncMeetingStateResponse().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _SyncMeetingStateResponse().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _SyncMeetingStateResponse().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_SyncMeetingStateResponse, a, b);
  }
};
var ConsumeResponse = class _ConsumeResponse extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string label = 1;
   */
  label;
  /**
   * @generated from field: required string consumerId = 2;
   */
  consumerId;
  /**
   * @generated from field: required string producerId = 3;
   */
  producerId;
  /**
   * @generated from field: required string kind = 4;
   */
  kind;
  /**
   * @generated from field: required ProtoRtpParameters rtpParameters = 5;
   */
  rtpParameters;
  /**
   * @generated from field: required string producerPeerId = 6;
   */
  producerPeerId;
  /**
   * @generated from field: optional AppData appData = 7;
   */
  appData;
  /**
   * @generated from field: optional bool producerPaused = 8;
   */
  producerPaused;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "ConsumeResponse";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "label", kind: "scalar", T: 9, req: true },
    { no: 2, name: "consumerId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "producerId", kind: "scalar", T: 9, req: true },
    { no: 4, name: "kind", kind: "scalar", T: 9, req: true },
    { no: 5, name: "rtpParameters", kind: "message", T: chunkUM7UGER4_cjs.ProtoRtpParameters, req: true },
    { no: 6, name: "producerPeerId", kind: "scalar", T: 9, req: true },
    { no: 7, name: "appData", kind: "message", T: chunkHS7ILUYH_cjs.AppData, opt: true },
    { no: 8, name: "producerPaused", kind: "scalar", T: 8, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ConsumeResponse().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ConsumeResponse().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ConsumeResponse().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_ConsumeResponse, a, b);
  }
};
var CloseProducerSuccess = class _CloseProducerSuccess extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: required string producerId = 2;
   */
  producerId;
  /**
   * @generated from field: required string label = 3;
   */
  label;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "CloseProducerSuccess";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "producerId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "label", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _CloseProducerSuccess().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _CloseProducerSuccess().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _CloseProducerSuccess().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_CloseProducerSuccess, a, b);
  }
};
var PauseProducerSuccess = class _PauseProducerSuccess extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: required string producerId = 2;
   */
  producerId;
  /**
   * @generated from field: required string label = 3;
   */
  label;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "PauseProducerSuccess";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "producerId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "label", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _PauseProducerSuccess().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _PauseProducerSuccess().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _PauseProducerSuccess().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_PauseProducerSuccess, a, b);
  }
};
var ResumeProducerSuccess = class _ResumeProducerSuccess extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: required string producerId = 2;
   */
  producerId;
  /**
   * @generated from field: required string label = 3;
   */
  label;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "ResumeProducerSuccess";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "producerId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "label", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ResumeProducerSuccess().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ResumeProducerSuccess().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ResumeProducerSuccess().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_ResumeProducerSuccess, a, b);
  }
};
var CloseConsumerSuccess = class _CloseConsumerSuccess extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: required string consumerId = 2;
   */
  consumerId;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "CloseConsumerSuccess";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "consumerId", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _CloseConsumerSuccess().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _CloseConsumerSuccess().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _CloseConsumerSuccess().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_CloseConsumerSuccess, a, b);
  }
};
var RestartTransportIceResponse = class _RestartTransportIceResponse extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string transportType = 1;
   */
  transportType;
  /**
   * @generated from field: required ProtoIceParameters iceParameters = 2;
   */
  iceParameters;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "RestartTransportIceResponse";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "transportType", kind: "scalar", T: 9, req: true },
    { no: 2, name: "iceParameters", kind: "message", T: chunkHS7ILUYH_cjs.ProtoIceParameters, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _RestartTransportIceResponse().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _RestartTransportIceResponse().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _RestartTransportIceResponse().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_RestartTransportIceResponse, a, b);
  }
};
var NewPeerJoined = class _NewPeerJoined extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: optional string metadata = 2;
   */
  metadata;
  /**
   * @generated from field: optional string role = 3;
   */
  role;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "NewPeerJoined";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "metadata", kind: "scalar", T: 9, opt: true },
    { no: 3, name: "role", kind: "scalar", T: 9, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _NewPeerJoined().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _NewPeerJoined().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _NewPeerJoined().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_NewPeerJoined, a, b);
  }
};
var NewLobbyPeer = class _NewLobbyPeer extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: optional string metadata = 2;
   */
  metadata;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "NewLobbyPeer";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "metadata", kind: "scalar", T: 9, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _NewLobbyPeer().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _NewLobbyPeer().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _NewLobbyPeer().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_NewLobbyPeer, a, b);
  }
};
var NewPermissions = class _NewPermissions extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required Permissions acl = 2;
   */
  acl;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "NewPermissions";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 2, name: "acl", kind: "message", T: chunkHS7ILUYH_cjs.Permissions, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _NewPermissions().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _NewPermissions().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _NewPermissions().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_NewPermissions, a, b);
  }
};
var NewRoomControls = class _NewRoomControls extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required RoomControls controls = 1;
   */
  controls;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "NewRoomControls";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "controls", kind: "message", T: RoomControls, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _NewRoomControls().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _NewRoomControls().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _NewRoomControls().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_NewRoomControls, a, b);
  }
};
var NewPeerRole = class _NewPeerRole extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: required string role = 2;
   */
  role;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "NewPeerRole";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "role", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _NewPeerRole().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _NewPeerRole().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _NewPeerRole().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_NewPeerRole, a, b);
  }
};
var ReceiveData = class _ReceiveData extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string from = 1;
   */
  from;
  /**
   * @generated from field: required string payload = 2;
   */
  payload;
  /**
   * @generated from field: optional string label = 3;
   */
  label;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "ReceiveData";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "from", kind: "scalar", T: 9, req: true },
    { no: 2, name: "payload", kind: "scalar", T: 9, req: true },
    { no: 3, name: "label", kind: "scalar", T: 9, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _ReceiveData().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _ReceiveData().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _ReceiveData().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_ReceiveData, a, b);
  }
};
var PeerMetadataUpdated = class _PeerMetadataUpdated extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: required string metadata = 2;
   */
  metadata;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "PeerMetadataUpdated";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "metadata", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _PeerMetadataUpdated().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _PeerMetadataUpdated().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _PeerMetadataUpdated().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_PeerMetadataUpdated, a, b);
  }
};
var RoomMetadataUpdated = class _RoomMetadataUpdated extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string metadata = 1;
   */
  metadata;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "RoomMetadataUpdated";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "metadata", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _RoomMetadataUpdated().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _RoomMetadataUpdated().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _RoomMetadataUpdated().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_RoomMetadataUpdated, a, b);
  }
};
var RoomClosedProducers = class _RoomClosedProducers extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: repeated RoomClosedProducers.CloseProducerInfo producers = 1;
   */
  producers = [];
  /**
   * @generated from field: required RoomClosedProducers.CloseProducerReason reason = 2;
   */
  reason;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "RoomClosedProducers";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "producers", kind: "message", T: RoomClosedProducers_CloseProducerInfo, repeated: true },
    { no: 2, name: "reason", kind: "message", T: RoomClosedProducers_CloseProducerReason, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _RoomClosedProducers().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _RoomClosedProducers().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _RoomClosedProducers().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_RoomClosedProducers, a, b);
  }
};
var RoomClosedProducers_CloseProducerInfo = class _RoomClosedProducers_CloseProducerInfo extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: required string producerId = 2;
   */
  producerId;
  /**
   * @generated from field: required string label = 3;
   */
  label;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "RoomClosedProducers.CloseProducerInfo";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "producerId", kind: "scalar", T: 9, req: true },
    { no: 3, name: "label", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _RoomClosedProducers_CloseProducerInfo().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _RoomClosedProducers_CloseProducerInfo().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _RoomClosedProducers_CloseProducerInfo().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_RoomClosedProducers_CloseProducerInfo, a, b);
  }
};
var RoomClosedProducers_CloseProducerReason = class _RoomClosedProducers_CloseProducerReason extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required int32 code = 1;
   */
  code;
  /**
   * @generated from field: required string tag = 2;
   */
  tag;
  /**
   * @generated from field: required string message = 3;
   */
  message;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "RoomClosedProducers.CloseProducerReason";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "code", kind: "scalar", T: 5, req: true },
    { no: 2, name: "tag", kind: "scalar", T: 9, req: true },
    { no: 3, name: "message", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _RoomClosedProducers_CloseProducerReason().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _RoomClosedProducers_CloseProducerReason().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _RoomClosedProducers_CloseProducerReason().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_RoomClosedProducers_CloseProducerReason, a, b);
  }
};
var PeerLeft = class _PeerLeft extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "PeerLeft";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _PeerLeft().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _PeerLeft().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _PeerLeft().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_PeerLeft, a, b);
  }
};
var LobbyPeerLeft = class _LobbyPeerLeft extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string peerId = 1;
   */
  peerId;
  /**
   * @generated from field: required string status = 2;
   */
  status;
  /**
   * @generated from field: optional string message = 3;
   */
  message;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "LobbyPeerLeft";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "peerId", kind: "scalar", T: 9, req: true },
    { no: 2, name: "status", kind: "scalar", T: 9, req: true },
    { no: 3, name: "message", kind: "scalar", T: 9, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _LobbyPeerLeft().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _LobbyPeerLeft().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _LobbyPeerLeft().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_LobbyPeerLeft, a, b);
  }
};
var WaitingRoom = class _WaitingRoom extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string reason = 1;
   */
  reason;
  /**
   * @generated from field: optional string metadata = 2;
   */
  metadata;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "WaitingRoom";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "reason", kind: "scalar", T: 9, req: true },
    { no: 2, name: "metadata", kind: "scalar", T: 9, opt: true }
  ]);
  static fromBinary(bytes, options) {
    return new _WaitingRoom().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _WaitingRoom().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _WaitingRoom().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_WaitingRoom, a, b);
  }
};
var Error2 = class _Error extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from field: required string event = 1;
   */
  event;
  /**
   * @generated from field: required string error = 2;
   */
  error;
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "Error";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "event", kind: "scalar", T: 9, req: true },
    { no: 2, name: "error", kind: "scalar", T: 9, req: true }
  ]);
  static fromBinary(bytes, options) {
    return new _Error().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _Error().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _Error().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_Error, a, b);
  }
};
var Response = class _Response extends chunkUM7UGER4_cjs.Message {
  /**
   * @generated from oneof Response.Response
   */
  Response = { case: void 0 };
  constructor(data) {
    super();
    chunkUM7UGER4_cjs.proto2.util.initPartial(data, this);
  }
  static runtime = chunkUM7UGER4_cjs.proto2;
  static typeName = "Response";
  static fields = chunkUM7UGER4_cjs.proto2.util.newFieldList(() => [
    { no: 1, name: "hello", kind: "message", T: Hello, oneof: "Response" },
    { no: 2, name: "connectRoomResponse", kind: "message", T: ConnectRoomResponse, oneof: "Response" },
    { no: 3, name: "createTransportOnClient", kind: "message", T: CreateTransportOnClient, oneof: "Response" },
    { no: 4, name: "produceResponse", kind: "message", T: ProduceResponse, oneof: "Response" },
    { no: 25, name: "consumeDataResponse", kind: "message", T: ConsumeDataResponse, oneof: "Response" },
    { no: 5, name: "produceDataResponse", kind: "message", T: ProduceDataResponse, oneof: "Response" },
    { no: 6, name: "syncMeetingStateResponse", kind: "message", T: SyncMeetingStateResponse, oneof: "Response" },
    { no: 7, name: "consumeResponse", kind: "message", T: ConsumeResponse, oneof: "Response" },
    { no: 8, name: "closeProducerSuccess", kind: "message", T: CloseProducerSuccess, oneof: "Response" },
    { no: 26, name: "pauseProducerSuccess", kind: "message", T: PauseProducerSuccess, oneof: "Response" },
    { no: 27, name: "resumeProducerSuccess", kind: "message", T: ResumeProducerSuccess, oneof: "Response" },
    { no: 9, name: "closeConsumerSuccess", kind: "message", T: CloseConsumerSuccess, oneof: "Response" },
    { no: 10, name: "connectTransportResponse", kind: "message", T: ConnectTransportResponse, oneof: "Response" },
    { no: 11, name: "restartTransportIceResponse", kind: "message", T: RestartTransportIceResponse, oneof: "Response" },
    { no: 12, name: "newPeerJoined", kind: "message", T: NewPeerJoined, oneof: "Response" },
    { no: 13, name: "newLobbyPeer", kind: "message", T: NewLobbyPeer, oneof: "Response" },
    { no: 14, name: "newPermissions", kind: "message", T: NewPermissions, oneof: "Response" },
    { no: 15, name: "newRoomControls", kind: "message", T: NewRoomControls, oneof: "Response" },
    { no: 16, name: "newPeerRole", kind: "message", T: NewPeerRole, oneof: "Response" },
    { no: 17, name: "receiveData", kind: "message", T: ReceiveData, oneof: "Response" },
    { no: 18, name: "peerMetadataUpdated", kind: "message", T: PeerMetadataUpdated, oneof: "Response" },
    { no: 19, name: "roomMetadataUpdated", kind: "message", T: RoomMetadataUpdated, oneof: "Response" },
    { no: 20, name: "roomClosedProducers", kind: "message", T: RoomClosedProducers, oneof: "Response" },
    { no: 21, name: "peerLeft", kind: "message", T: PeerLeft, oneof: "Response" },
    { no: 22, name: "lobbyPeerLeft", kind: "message", T: LobbyPeerLeft, oneof: "Response" },
    { no: 23, name: "waitingRoom", kind: "message", T: WaitingRoom, oneof: "Response" },
    { no: 24, name: "error", kind: "message", T: Error2, oneof: "Response" }
  ]);
  static fromBinary(bytes, options) {
    return new _Response().fromBinary(bytes, options);
  }
  static fromJson(jsonValue, options) {
    return new _Response().fromJson(jsonValue, options);
  }
  static fromJsonString(jsonString, options) {
    return new _Response().fromJsonString(jsonString, options);
  }
  static equals(a, b) {
    return chunkUM7UGER4_cjs.proto2.util.equals(_Response, a, b);
  }
};

// package.json
var package_default = {
  version: "2.5.0"};

// src/Socket.ts
var logger = chunkO5HDCTOE_cjs.mainLogger.createSubLogger("Socket.ts");
var Socket = class _Socket extends chunkUIH7JJYU_cjs.EnhancedEventEmitter {
  /**
   * Socket Instance, Singleton class
   */
  static __instance = null;
  /**
   * Retry count for the socket connection, if the connection is closed abnormally, we try to reconnect 5 times
   */
  __retryCount = 0;
  /**
   * Current connection state of the socket connection
   */
  __connectionState = "uninitialized";
  /**
   * websocket polyfill
   */
  __wsPolyfill;
  /**
   * Underlying WebSocket connection, until we dont call Socket.connect(); this will be null
   */
  __ws = null;
  /**
   * Map of all the subscribed events/topics for the socket connection
   */
  __subscribedMap = /* @__PURE__ */ new Map();
  /**
   * Geo data of the current socket connection, specific to the Local Peer who joined the meeting
   */
  __geoData = null;
  /**
   * Endpoint of the socket server, this is fetched from the API server
   */
  __ENDPOINT = null;
  /**
   * API URL for Huddle01 Network, this is used to fetch the socket server URL
   */
  __HUDDLE_API_URL = "https://apira.huddle01.media/api/v1";
  /**
   * Token of the current socket connection, specific to the Local Peer who joined the meeting
   */
  token = null;
  /**
   * Platform of the current socket connection, specific to the Local Peer who joined the meeting
   */
  versions = [`core@${package_default.version}`];
  set __platform(platform) {
    this.versions[1] = platform;
  }
  /**
   * Returns the underlying WebSocket connection, throws an error if the connection is not initialized
   * @throws `Error` if the connection is not initialized
   */
  get ws() {
    if (!this.__ws) {
      throw new Error("\u{1F534} Socket Not Initialised");
    }
    return this.__ws;
  }
  /**
   * Getter for the region of the current socket connection
   */
  get region() {
    return this.__geoData?.region;
  }
  /**
   * Getter for the geo data of the current socket connection
   */
  get geoData() {
    return this.__geoData;
  }
  /**
   * Returns the current connection state of the socket connection
   */
  get connectionState() {
    return this.__connectionState;
  }
  /**
   * Returns true if the socket connection is connected
   */
  get connected() {
    return this.__ws?.OPEN === 1 && this.connectionState === "connected";
  }
  /**
   * Returns true if the socket connection is connecting
   */
  get connecting() {
    return this.__ws?.CONNECTING === 0 && this.connectionState === "connecting";
  }
  /**
   * Returns true if the socket connection is closed
   */
  get closed() {
    return this.__ws?.CLOSED === 3 || this.__ws?.CLOSING === 2;
  }
  /**
   * Sets the current connection state of the socket connection
   */
  set connectionState(state) {
    logger.info(`\u{1F50C} WebSocket state changed to ${state}`);
    this.__connectionState = state;
  }
  /**
   * Update the token for this socket
   * @throws `Error` if the token is already set
   */
  setToken(token) {
    if (this.token) {
      throw new Error("\u{1F534} Token Already Set");
    }
    this.token = token;
    this.emit("token-updated", token);
  }
  /**
   * Set a new region for the socket connection
   */
  setRegion(region) {
    if (this.geoData) {
      this.geoData.region = region;
    } else {
      this.__geoData = {
        country: "IN",
        region
      };
    }
    this.emit("region-updated", region);
  }
  /**
   * @protected - For Internal Use Only
   */
  setHuddleApiUrl = (url) => {
    this.__HUDDLE_API_URL = url;
  };
  /**
   * Creates the socket and returns the instance of the socket if already initialized
   * you need to call connect method to connect to the server
   * @param data
   * @returns
   */
  static create(wsPolyfill, options) {
    if (!_Socket.__instance) {
      _Socket.__instance = new _Socket(wsPolyfill, options);
    }
    return _Socket.__instance;
  }
  /**
   * Returns the instance of the socket connection, throws an error if the connection is not initialized
   * @throws `Error` if the connection is not initialized
   */
  static getInstance() {
    if (!_Socket.__instance) {
      throw new Error(
        "\u{1F534} Socket Instance Not Initialised, You are trying to do something which is not possible"
      );
    }
    return _Socket.__instance;
  }
  constructor(wsPolyfill, options) {
    super();
    this.__wsPolyfill = wsPolyfill || null;
    if (options?.huddle_api_url) {
      this.__HUDDLE_API_URL = options.huddle_api_url;
    }
  }
  /**
   *
   */
  __getGeoData = async () => {
    const fn = async () => {
      const resp = await fetch(
        "https://shinigami.huddle01.com/api/get-geolocation"
      );
      const data = await resp?.json();
      const geolocationdata = chunk3S34XHJL_cjs.GeolocationSchema.safeParse(data);
      if (!geolocationdata.success) {
        throw new Error("\u{1F534} Error While Finding the Region to connect to");
      }
      return {
        region: geolocationdata.data.globalRegion,
        country: geolocationdata.data.country
      };
    };
    return chunkHX55BIO2_cjs.apiCallWithRetry(fn);
  };
  /**
   * Connect to the socket server using the token, this will establish the connection with the server
   *
   * Every `token` is unique for each New Peer Trying to connect. Reusing the token will result in an repeated connection error, until the connection is closed.
   * @param data - `{ token: string }`
   * @throws `Error` if the socket connection cannot be established
   */
  connect = async (data) => {
    if (!_Socket.__instance) {
      throw new Error("\u{1F534} Socket Instance Not Initialised");
    }
    if (!this.token) {
      this.setToken(data.token);
    }
    if (this.connectionState === "connected") {
      logger.error("\u{1F534} Socket Already Connected");
      return _Socket.__instance;
    }
    if (this.connectionState === "connecting") {
      logger.error("\u{1F534} Socket Already Connecting");
      return _Socket.__instance;
    }
    if (this.__ws) {
      logger.error("\u{1F534} Socket Already Initialized");
      return _Socket.__instance;
    }
    logger.info("\u{1F50C} Connecting to the socket server");
    if (!this.__geoData) {
      const geoData = await this.__getGeoData();
      this.__geoData = geoData;
    }
    const url = await this.__getConfigUrl(
      data.token,
      this.__geoData.region,
      this.__geoData.country,
      this.versions
    );
    this.connectionState = "connecting";
    this.emit("connecting");
    if (this.__wsPolyfill) this.__ws = new this.__wsPolyfill(url);
    else this.__ws = new WebSocket(url);
    this.__ws.binaryType = "arraybuffer";
    this.__ws.onmessage = this.__handleIncomingMessage;
    this.__registerSocketEvents(this.ws);
    const socketConnectionPromise = new Promise((resolve, reject) => {
      const handleSuccess = () => {
        logger.info("\u2705 WebSocket Connection Established Promise Resolved");
        handleRemoveListeners();
        resolve();
      };
      const handleClose = () => {
        logger.error(
          "\u{1F534} Error Connecting WebSocket, Closing the Connection, Try Again."
        );
        handleRemoveListeners();
        reject(
          new Error(
            "\u274C Error Connecting WebSocket, Closing the Connection, Try Again."
          )
        );
      };
      const handleRemoveListeners = () => {
        this.off("connected", handleSuccess);
        this.off("closed", handleClose);
      };
      this.once("connected", handleSuccess);
      this.once("closed", handleClose);
    });
    await socketConnectionPromise;
    return _Socket.__instance;
  };
  /**
   * Closes the underlying socket connection, and clears all the event listeners and subscriptions to events as well as
   * any other information related to the connection.
   * @param code `{ ESocketCloseCode }`
   */
  close = (code, reconnect = false) => {
    if (this.__ws) {
      this.__ws.onmessage = null;
    }
    const reason = SocketCloseReason[code];
    if (code >= 3e3 && code <= 4999 || code === 1e3) {
      logger.info(`\u{1F534} Closing the WebSocket Connection, ${code} ${reason}`);
      this.__ws?.close(code, reason);
      this.__ws = null;
      this.token = null;
      this.__ENDPOINT = null;
      this.__retryCount = 0;
      this.emit("token-updated", null);
      this.connectionState = "closed";
      this.emit("closed", code);
      logger.info("\u{1F50C} WebSocket Connection closed");
      return;
    }
    this.__ws?.close();
    if (this.__ws) {
      this.__unregisterSocketEvents(this.ws);
    }
    this.__ws = null;
    if (code === exports.ESocketCloseCode.ABNORMAL_CLOSURE || reconnect) {
      logger.info(
        "\u{1F50C} Socket Connection closed abnormally, Trying to Reconnect",
        {
          code,
          reason
        }
      );
      if (this.__retryCount < 7) {
        const delay = 2 ** this.__retryCount * 1e3;
        setTimeout(
          () => {
            if (this.token) {
              try {
                logger.info(
                  "\u{1F514} Trying to reconnect, Attempt:",
                  this.__retryCount
                );
                this.connectionState = "reconnecting";
                this.emit("reconnecting");
                this.connect({ token: this.token }).then(() => {
                  if (this.__retryCount > 0) {
                    this.emit("reconnected");
                  }
                  this.__retryCount = 0;
                }).catch(() => {
                  if (this.__retryCount === 7) {
                    logger.error("All Reconnection Attempt failed");
                  }
                });
              } catch (err) {
                logger.error(
                  `Reconnection Attempt ${this.__retryCount} failed`
                );
              }
            }
          },
          Math.min(delay, 2e4)
        );
        this.__retryCount++;
      } else {
        logger.error(
          "\u{1F534} Socket connection closed abnormally, reconnecting failed"
        );
        this.close(exports.ESocketCloseCode.CONNECTION_EXPIRED);
      }
    } else {
      logger.info("\u{1F50C} Socket Connection closed", code, reason);
      this.connectionState = "closed";
      this.emit("closed", code);
    }
  };
  /**
   * Publish a message to the server using the socket connection based on some events/topics
   */
  publish = (event, data) => {
    try {
      const message = new chunkHS7ILUYH_cjs.Request({
        // @ts-ignore - TS doesn't understand that the value of event is a key of ClientToSushiEvents
        request: {
          case: event,
          value: new chunkHS7ILUYH_cjs.ProtoRequestEvent[event](data)
        }
      });
      const binaryData = message.toBinary();
      this.ws.send(binaryData);
    } catch (error) {
      logger.error("\u{1F534} Error While Sending the Message", error);
    }
  };
  /**
   * Subscribe to a specific event/topic from the server
   */
  subscribe = (event, fn) => {
    if (this.__subscribedMap.has(event)) {
      logger.warn("\u26A0\uFE0F Overriding existing event handler");
    }
    this.__subscribedMap.set(event, fn);
  };
  /**
   * Get the config url for the socket connection based on the token and region
   * @param token Local Peer specific meeting token
   * @param region Local Peer specific region
   * @returns
   */
  async __getConfigUrl(token, region, country, versions) {
    if (this.__ENDPOINT) {
      return this.__ENDPOINT;
    }
    const fn = async () => {
      const apiServerUrl = this.__HUDDLE_API_URL;
      const res = await fetch(`${apiServerUrl}/getSushiUrl`, {
        method: "GET",
        headers: {
          "Content-Type": "application/json",
          authorization: `Bearer ${token}`
        }
      });
      if (!res.ok) {
        throw new Error("\u{1F534} Error While Fetching the Url");
      }
      const { url } = await res.json();
      this.__ENDPOINT = url.replace("https://", "wss://").replace("http://", "ws://");
      const wssAddress = `${this.__ENDPOINT}/ws`;
      const versionsString = versions.join(",");
      const wsAddress = `${wssAddress}?${[
        `token=${token}`,
        `version=${versionsString}`,
        `region=${region}`,
        `country=${country}`
      ].join("&")}`;
      this.__ENDPOINT = wsAddress;
      return wsAddress;
    };
    return chunkHX55BIO2_cjs.apiCallWithRetry(fn);
  }
  /**
   * !Important
   * Handle the incoming message from the server based on the events received from the server and call the subscribed event handler
   */
  __handleIncomingMessage = (event) => {
    try {
      const eventData = new Uint8Array(event.data);
      const msg = Response.fromBinary(eventData).Response;
      logger.debug("\u{1F4E8} Incoming message", msg);
      const eventName = msg.case;
      if (eventName === void 0) {
        throw new Error("\u{1F534} Can't find the event name, Found: { undefined }");
      }
      const data = JSON.parse(JSON.stringify(msg.value));
      logger.info("\u{1F4E8} Incoming message event name: ", eventName);
      const fn = this.__subscribedMap.get(eventName);
      if (fn) {
        fn(data);
      }
    } catch (error) {
      logger.error("\u{1F534} Error: Handling Incoming Message", error);
    }
  };
  __handleSocketError = (ev) => {
    logger.error("\u274C Socket connection error", ev);
  };
  /**
   * @description Handle the socket close event which is sent by the server
   * @param ev CloseEvent
   */
  __handleSocketClose = (ev) => {
    logger.info("\u{1F514} Socket connection closed emitted", ev);
    const code = ev.code;
    const reason = ev.reason;
    const isCloudflareClose = reason?.toLowerCase().includes("cloudflare");
    const isReactNativeStreamEnd = chunkNYECY7ZG_cjs.isReactNative() && reason?.toLowerCase().includes("stream end encountered");
    this.close(code, isCloudflareClose || isReactNativeStreamEnd);
  };
  /**
   * @description Handle the socket open event which is sent after the connection is established with the server
   * @param ev Event
   */
  __handleSocketOpen = (ev) => {
    logger.debug("WebSocket Connection Open", ev);
    this.connectionState = "connected";
    this.emit("connected");
  };
  /**
   * @description Register the socket events
   * @param ws WebSocket
   */
  __registerSocketEvents = (ws) => {
    ws.onerror = this.__handleSocketError;
    ws.onclose = this.__handleSocketClose;
    ws.onopen = this.__handleSocketOpen;
  };
  /**
   * @description Unregister the socket events
   * @param ws WebSocket
   */
  __unregisterSocketEvents = (ws) => {
    ws.onerror = null;
    ws.onclose = null;
    ws.onopen = null;
  };
};
var Socket_default = Socket;

exports.Socket_default = Socket_default;