@formant/data-sdk 0.0.59 → 0.0.63

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.
@@ -17982,6 +17982,25 @@ Found: ${e2.toString().split("\n")[0]}
17982
17982
  return r2.sort((e3, t3) => n2(t3) - n2(e3)).map((e3) => Z(e3));
17983
17983
  });
17984
17984
  }
17985
+ getSessions() {
17986
+ return K(this, void 0, void 0, function* () {
17987
+ if (this.config.lanOnlyMode)
17988
+ throw new Error("getPeers method cannot be used in local-only mode.");
17989
+ const { signalingClient: e2 } = this.config, t2 = yield (() => K(this, void 0, void 0, function* () {
17990
+ try {
17991
+ return yield e2.getPeers(new C.GetPeersRequest(), yield this.getMetadata({}));
17992
+ } catch (e3) {
17993
+ _.a.warn("Error when getting peers", { error: e3 });
17994
+ }
17995
+ }))();
17996
+ if (!t2)
17997
+ return {};
17998
+ const r2 = t2.getPeersList(), n2 = {};
17999
+ for (const e3 of r2)
18000
+ n2[e3.getPeerId()] = e3.getSessionIdsList();
18001
+ return n2;
18002
+ });
18003
+ }
17985
18004
  getPing(e2) {
17986
18005
  const t2 = this.getActiveConnection(e2);
17987
18006
  if (t2)
@@ -18243,10 +18262,14 @@ let urlParams$1 = new URLSearchParams("");
18243
18262
  if (typeof window !== "undefined") {
18244
18263
  urlParams$1 = new URLSearchParams(window.location.search);
18245
18264
  }
18246
- const moduleName$1 = urlParams$1.get("formant_dev");
18247
- if (moduleName$1) {
18265
+ const envDev = urlParams$1.get("formant_dev");
18266
+ if (envDev) {
18248
18267
  FORMANT_API_URL = "https://api-dev.formant.io";
18249
18268
  }
18269
+ const envStage = urlParams$1.get("formant_stage");
18270
+ if (envStage) {
18271
+ FORMANT_API_URL = "https://api-stage.formant.io";
18272
+ }
18250
18273
  function delay(ms) {
18251
18274
  return new Promise((resolve) => setTimeout(resolve, ms));
18252
18275
  }
@@ -18378,8 +18401,13 @@ const _Authentication = class {
18378
18401
  const tokenData = JSON.parse(atob(token.split(".")[1]));
18379
18402
  try {
18380
18403
  let userId;
18381
- _Authentication.isShareToken = tokenData["formant:claims"].type == "share";
18382
- _Authentication.currentOrganization = tokenData["formant:claims"].organizationId;
18404
+ _Authentication.isShareToken = tokenData["formant:claims"] && tokenData["formant:claims"].type == "share";
18405
+ if (tokenData["formant:claims"]) {
18406
+ _Authentication.currentOrganization = tokenData["formant:claims"].organizationId;
18407
+ }
18408
+ if (tokenData["custom:organization_id"]) {
18409
+ _Authentication.currentOrganization = tokenData["custom:organization_id"];
18410
+ }
18383
18411
  if (!_Authentication.isShareToken) {
18384
18412
  userId = tokenData.sub;
18385
18413
  }
@@ -18949,6 +18977,15 @@ class Device {
18949
18977
  throw new Error(`Realtime connection hasn't been started for ${this.id}`);
18950
18978
  }
18951
18979
  }
18980
+ async isInRealtimeSession() {
18981
+ let peers = await Fleet.getPeers();
18982
+ let sessions = await Fleet.getRealtimeSessions();
18983
+ let peer = peers.find((_) => _.deviceId === this.id);
18984
+ if (peer) {
18985
+ return sessions[peer.id].length > 0;
18986
+ }
18987
+ return false;
18988
+ }
18952
18989
  async getAvailableCommands() {
18953
18990
  const result = await fetch(`${FORMANT_API_URL}/v1/admin/command-templates/`, {
18954
18991
  method: "GET",
@@ -19149,6 +19186,34 @@ const _Fleet = class {
19149
19186
  const allDevices = await _Fleet.getDevices();
19150
19187
  return allDevices.filter((_) => onlineIds.includes(_.id));
19151
19188
  }
19189
+ static async getPeers() {
19190
+ if (!Authentication.token) {
19191
+ throw new Error("Not authenticated");
19192
+ }
19193
+ const rtcClient = new dist.exports.RtcClient({
19194
+ signalingClient: new dist.exports.SignalingPromiseClient(FORMANT_API_URL, null, null),
19195
+ getToken: async () => {
19196
+ return defined(Authentication.token, "Realtime when user isn't authorized");
19197
+ },
19198
+ receive: () => {
19199
+ }
19200
+ });
19201
+ return await rtcClient.getPeers();
19202
+ }
19203
+ static async getRealtimeSessions() {
19204
+ if (!Authentication.token) {
19205
+ throw new Error("Not authenticated");
19206
+ }
19207
+ const rtcClient = new dist.exports.RtcClient({
19208
+ signalingClient: new dist.exports.SignalingPromiseClient(FORMANT_API_URL, null, null),
19209
+ getToken: async () => {
19210
+ return defined(Authentication.token, "Realtime when user isn't authorized");
19211
+ },
19212
+ receive: () => {
19213
+ }
19214
+ });
19215
+ return await rtcClient.getSessions();
19216
+ }
19152
19217
  static async getRealtimeDevices() {
19153
19218
  if (!Authentication.token) {
19154
19219
  throw new Error("Not authenticated");