ulai-js-sdk 0.1.2 → 0.1.4

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/events.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.EventsClient = void 0;
7
7
  const eventemitter3_1 = __importDefault(require("eventemitter3"));
8
+ const url_1 = require("./url");
8
9
  class EventsClient extends eventemitter3_1.default {
9
10
  ws = null;
10
11
  url;
@@ -21,23 +22,7 @@ class EventsClient extends eventemitter3_1.default {
21
22
  this.url = this.buildUrl(cpBase);
22
23
  }
23
24
  buildUrl(cpBase) {
24
- const cleanHost = cpBase
25
- .replace(/^https?:\/\//, '')
26
- .replace(/^wss?:\/\//, '')
27
- .replace(/\/$/, '');
28
- const isLocal = cleanHost.startsWith('localhost') ||
29
- cleanHost.startsWith('127.0.0.1');
30
- let scheme = 'wss';
31
- if (isLocal) {
32
- scheme = 'ws';
33
- }
34
- else if (typeof window !== 'undefined' && window.location.protocol === 'http:') {
35
- scheme = 'ws';
36
- }
37
- else if (cpBase.startsWith('http://')) {
38
- scheme = 'ws';
39
- }
40
- return `${scheme}://${cleanHost}/api/v1/events`;
25
+ return (0, url_1.wsUrl)(cpBase, '/api/v1/events');
41
26
  }
42
27
  connect(sessionId, eventsToken) {
43
28
  this.sessionId = sessionId;
package/dist/signaling.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SignalingClient = void 0;
7
7
  const eventemitter3_1 = __importDefault(require("eventemitter3"));
8
+ const url_1 = require("./url");
8
9
  class SignalingClient extends eventemitter3_1.default {
9
10
  ws = null;
10
11
  url;
@@ -19,21 +20,7 @@ class SignalingClient extends eventemitter3_1.default {
19
20
  this.url = this.buildUrl(nodeAddress, ticket);
20
21
  }
21
22
  buildUrl(nodeAddress, ticket) {
22
- const cleanAddress = nodeAddress
23
- .replace(/^https?:\/\//, '')
24
- .replace(/^wss?:\/\//, '')
25
- .replace(/\/$/, '');
26
- const isLocal = cleanAddress.startsWith('localhost') ||
27
- cleanAddress.startsWith('127.0.0.1');
28
- // Default to wss unless connecting to localhost/127.0.0.1 over plain http
29
- let scheme = 'wss';
30
- if (isLocal) {
31
- scheme = 'ws';
32
- }
33
- else if (typeof window !== 'undefined' && window.location.protocol === 'http:') {
34
- scheme = 'ws';
35
- }
36
- return `${scheme}://${cleanAddress}/webrtc/room?ticket=${encodeURIComponent(ticket)}`;
23
+ return (0, url_1.wsUrl)(nodeAddress, `/webrtc/room?ticket=${encodeURIComponent(ticket)}`);
37
24
  }
38
25
  connect() {
39
26
  this.isClosedManually = false;
package/dist/url.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The WebSocket URL for `path` on `address`.
3
+ *
4
+ * Secure (wss) unless the address says otherwise (http:// or ws://), or has no scheme and points at this
5
+ * machine. The page's own scheme doesn't decide it: a page served over http may open wss, and Ulai's remote
6
+ * endpoints only accept wss.
7
+ */
8
+ export declare function wsUrl(address: string, path: string): string;
package/dist/url.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wsUrl = wsUrl;
4
+ /**
5
+ * The WebSocket URL for `path` on `address`.
6
+ *
7
+ * Secure (wss) unless the address says otherwise (http:// or ws://), or has no scheme and points at this
8
+ * machine. The page's own scheme doesn't decide it: a page served over http may open wss, and Ulai's remote
9
+ * endpoints only accept wss.
10
+ */
11
+ function wsUrl(address, path) {
12
+ const scheme = address.match(/^(https?|wss?):\/\//)?.[1];
13
+ const host = address.replace(/^(https?|wss?):\/\//, '').replace(/\/$/, '');
14
+ const isLocal = host.startsWith('localhost') || host.startsWith('127.0.0.1');
15
+ const insecure = scheme ? scheme === 'http' || scheme === 'ws' : isLocal;
16
+ return `${insecure ? 'ws' : 'wss'}://${host}${path}`;
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ulai-js-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Ulai Cloud JS/TS Client SDK for WebRTC Sessions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,5 +31,9 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "eventemitter3": "^5.0.1"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/ulaidotin/ulai-js-sdk.git"
34
38
  }
35
39
  }