@signalwire/js 3.17.0 → 3.18.0-dev.202212131653.0cf1c92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1350,11 +1350,11 @@ var JWTSession = class extends BaseJWTSession {
1350
1350
  }
1351
1351
  }
1352
1352
  super(__spreadProps(__spreadValues({}, options), {
1353
- host: (decodedJwt == null ? void 0 : decodedJwt.ch) || options.host
1353
+ host: options.host || (decodedJwt == null ? void 0 : decodedJwt.ch)
1354
1354
  }));
1355
1355
  this.options = options;
1356
1356
  __publicField(this, "WebSocketConstructor", WebSocket);
1357
- __publicField(this, "agent", "@signalwire/js/browser/3.17.0");
1357
+ __publicField(this, "agent", "@signalwire/js/browser/3.18.0-dev.202212131653.0cf1c92.0");
1358
1358
  }
1359
1359
  get allowHijack() {
1360
1360
  return this.options._hijack;
@@ -1495,6 +1495,133 @@ var Client3 = function(pubSubOptions) {
1495
1495
  // src/pubSub/index.ts
1496
1496
  var PubSubMessage = PubSub.PubSubMessage;
1497
1497
 
1498
+ // src/fabric/index.ts
1499
+ var fabric_exports = {};
1500
+ __export(fabric_exports, {
1501
+ Client: () => Client4,
1502
+ getAddresses: () => getAddresses
1503
+ });
1504
+
1505
+ // src/fabric/httpClient.ts
1506
+ import { AuthError, HttpError } from "@signalwire/core";
1507
+ async function http(input, init) {
1508
+ const response = await fetch(input, init);
1509
+ if (!response.ok) {
1510
+ if (response.status === 401) {
1511
+ throw new AuthError(response.status, "Unauthorized");
1512
+ }
1513
+ let errorResponse;
1514
+ try {
1515
+ errorResponse = await response.json();
1516
+ } catch (e) {
1517
+ }
1518
+ const errorMessage = (errorResponse == null ? void 0 : errorResponse.errors) ? JSON.stringify(errorResponse.errors) : "Not Found";
1519
+ throw new HttpError(response.status, errorMessage, errorResponse);
1520
+ }
1521
+ try {
1522
+ response.parsedBody = await response.json();
1523
+ } catch (e) {
1524
+ }
1525
+ return response;
1526
+ }
1527
+ var createHttpClient = (_a, fetcher = http) => {
1528
+ var _b = _a, { baseUrl, timeout = 3e4 } = _b, globalOptions = __objRest(_b, ["baseUrl", "timeout"]);
1529
+ const apiClient = async (path, options) => {
1530
+ const headers = __spreadValues(__spreadValues(__spreadValues({}, (options == null ? void 0 : options.body) ? { "Content-Type": "application/json" } : {}), globalOptions.headers), options == null ? void 0 : options.headers);
1531
+ const reqInit = getRequestInit(__spreadProps(__spreadValues(__spreadValues({}, globalOptions), options), {
1532
+ headers
1533
+ }));
1534
+ let timerId;
1535
+ if (timeout) {
1536
+ const controller = new AbortController();
1537
+ const signal = controller.signal;
1538
+ reqInit.signal = signal;
1539
+ timerId = setTimeout(() => {
1540
+ controller.abort();
1541
+ }, timeout);
1542
+ }
1543
+ try {
1544
+ const response = await fetcher(getUrl({
1545
+ path,
1546
+ baseUrl,
1547
+ searchParams: options == null ? void 0 : options.searchParams
1548
+ }), reqInit);
1549
+ return { body: response.parsedBody };
1550
+ } catch (e) {
1551
+ throw e;
1552
+ } finally {
1553
+ timerId && clearTimeout(timerId);
1554
+ }
1555
+ };
1556
+ return apiClient;
1557
+ };
1558
+ var getBody = (body) => {
1559
+ return typeof body === "string" ? body : JSON.stringify(body);
1560
+ };
1561
+ var getRequestInit = (options) => {
1562
+ return Object.entries(options).reduce((reducer, [key, value]) => {
1563
+ if (key === "body") {
1564
+ return __spreadProps(__spreadValues({}, reducer), {
1565
+ body: getBody(value)
1566
+ });
1567
+ } else if (value != void 0) {
1568
+ return __spreadProps(__spreadValues({}, reducer), {
1569
+ [key]: value
1570
+ });
1571
+ }
1572
+ return reducer;
1573
+ }, {});
1574
+ };
1575
+ var getUrl = ({
1576
+ path,
1577
+ baseUrl,
1578
+ searchParams
1579
+ }) => {
1580
+ const url = new URL(path, baseUrl);
1581
+ if (searchParams) {
1582
+ Object.entries(searchParams).forEach(([key, value]) => {
1583
+ if (value != void 0) {
1584
+ url.searchParams.append(key, value);
1585
+ }
1586
+ });
1587
+ }
1588
+ return url.toString();
1589
+ };
1590
+
1591
+ // src/fabric/getAddresses.ts
1592
+ var getAddresses = async ({
1593
+ spaceHost,
1594
+ accessToken
1595
+ }) => {
1596
+ const path = "/addresses";
1597
+ const client = createHttpClient({
1598
+ baseUrl: `https://${spaceHost}`,
1599
+ headers: {
1600
+ Authorization: `Bearer ${accessToken}`
1601
+ }
1602
+ });
1603
+ const { body } = await client(path);
1604
+ const anotherPage = async (url) => {
1605
+ const { search } = new URL(url);
1606
+ const { body: body2 } = await client(`${path}${search}`);
1607
+ return buildResult(body2);
1608
+ };
1609
+ const buildResult = (body2) => {
1610
+ return {
1611
+ addresses: body2.data,
1612
+ nextPage: async () => {
1613
+ const { next } = body2.links;
1614
+ return next ? anotherPage(next) : void 0;
1615
+ },
1616
+ prevPage: async () => {
1617
+ const { prev } = body2.links;
1618
+ return prev ? anotherPage(prev) : void 0;
1619
+ }
1620
+ };
1621
+ };
1622
+ return buildResult(body);
1623
+ };
1624
+
1498
1625
  // src/video.ts
1499
1626
  var video_exports = {};
1500
1627
  __export(video_exports, {
@@ -1746,8 +1873,8 @@ var RoomSession = function(roomOptions) {
1746
1873
  const authState = client._sessionAuthState;
1747
1874
  const mediaOptions = getJoinMediaParams(__spreadValues({
1748
1875
  authState,
1749
- sendAudio: Boolean(audioFromConstructor),
1750
- sendVideo: Boolean(videoFromConstructor)
1876
+ sendAudio: Boolean(audio),
1877
+ sendVideo: Boolean(video)
1751
1878
  }, params));
1752
1879
  if (!checkMediaParams(mediaOptions)) {
1753
1880
  client.disconnect();
@@ -1755,6 +1882,7 @@ var RoomSession = function(roomOptions) {
1755
1882
  ${JSON.stringify(params, null, 2)}
1756
1883
  `));
1757
1884
  }
1885
+ getLogger8().debug("Set mediaOptions", mediaOptions);
1758
1886
  room.updateMediaOptions({
1759
1887
  audio: mediaOptions.mustSendAudio ? audio || true : false,
1760
1888
  video: mediaOptions.mustSendVideo ? video || true : false,
@@ -1789,6 +1917,101 @@ ${JSON.stringify(params, null, 2)}
1789
1917
  });
1790
1918
  };
1791
1919
 
1920
+ // src/fabric/buildCall.ts
1921
+ var buildCall = ({
1922
+ strategy,
1923
+ params,
1924
+ userParams
1925
+ }) => {
1926
+ let obj;
1927
+ let start;
1928
+ switch (strategy) {
1929
+ case "room":
1930
+ obj = new RoomSession(__spreadValues({
1931
+ token: params.token
1932
+ }, userParams));
1933
+ start = (joinParams) => {
1934
+ return new Promise((resolve, reject) => {
1935
+ obj.on("room.joined", (params2) => resolve(params2));
1936
+ return obj.join(joinParams).catch((error) => reject(error));
1937
+ });
1938
+ };
1939
+ break;
1940
+ default:
1941
+ throw new Error(`Unknown strategy: '${strategy}'`);
1942
+ }
1943
+ const interceptors = {
1944
+ start
1945
+ };
1946
+ return new Proxy(obj, {
1947
+ get(target, prop, receiver) {
1948
+ if (prop in interceptors) {
1949
+ return interceptors[prop];
1950
+ }
1951
+ return Reflect.get(target, prop, receiver);
1952
+ }
1953
+ });
1954
+ };
1955
+
1956
+ // src/fabric/Client.ts
1957
+ var Client4 = class {
1958
+ constructor(options) {
1959
+ this.options = options;
1960
+ __publicField(this, "httpClient");
1961
+ this.httpClient = createHttpClient({
1962
+ baseUrl: `https://${this.host}`,
1963
+ headers: {
1964
+ Authorization: `Bearer ${this.options.accessToken}`
1965
+ }
1966
+ });
1967
+ }
1968
+ get host() {
1969
+ var _a;
1970
+ return (_a = this.options.host) != null ? _a : "fabric.signalwire.com";
1971
+ }
1972
+ async getAddresses() {
1973
+ const path = "/addresses";
1974
+ const { body } = await this.httpClient(path);
1975
+ const anotherPage = async (url) => {
1976
+ const { search } = new URL(url);
1977
+ const { body: body2 } = await this.httpClient(`${path}${search}`);
1978
+ return buildResult(body2);
1979
+ };
1980
+ const buildResult = (body2) => {
1981
+ return {
1982
+ addresses: body2.data,
1983
+ nextPage: async () => {
1984
+ const { next } = body2.links;
1985
+ return next ? anotherPage(next) : void 0;
1986
+ },
1987
+ prevPage: async () => {
1988
+ const { prev } = body2.links;
1989
+ return prev ? anotherPage(prev) : void 0;
1990
+ }
1991
+ };
1992
+ };
1993
+ return buildResult(body);
1994
+ }
1995
+ async createCall(_a) {
1996
+ var _b = _a, {
1997
+ uri
1998
+ } = _b, userParams = __objRest(_b, [
1999
+ "uri"
2000
+ ]);
2001
+ const path = "/call";
2002
+ const { body } = await this.httpClient(path, {
2003
+ method: "POST",
2004
+ body: { uri }
2005
+ });
2006
+ console.log("Dial Response", body);
2007
+ return buildCall(__spreadProps(__spreadValues({}, body), {
2008
+ userParams: __spreadValues({
2009
+ host: this.host.includes("swire") ? "relay.swire.io" : void 0
2010
+ }, userParams)
2011
+ }));
2012
+ }
2013
+ };
2014
+
1792
2015
  // src/webrtc.ts
1793
2016
  var webrtc_exports = {};
1794
2017
  __export(webrtc_exports, {
@@ -1855,6 +2078,7 @@ import {
1855
2078
  } from "@signalwire/webrtc";
1856
2079
  export {
1857
2080
  chat_exports as Chat,
2081
+ fabric_exports as Fabric,
1858
2082
  pubSub_exports as PubSub,
1859
2083
  video_exports as Video,
1860
2084
  webrtc_exports as WebRTC