@chitchat/sdk-web 0.2.0-dev.2 → 0.2.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -3
- package/src/index.js +3 -2
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chitchat/sdk-web",
|
|
3
|
-
"version": "0.2.0-dev.
|
|
3
|
+
"version": "0.2.0-dev.3",
|
|
4
|
+
"description": "Browser WSS transport for the ChitChat Developer Platform",
|
|
5
|
+
"repository": { "type": "git", "url": "git+https://github.com/07Akashh/E2E-Chat.git", "directory": "developer-web/sdk/chitchat-web" },
|
|
6
|
+
"bugs": { "url": "https://github.com/07Akashh/E2E-Chat/issues" },
|
|
7
|
+
"homepage": "https://github.com/07Akashh/E2E-Chat/tree/main/docs/developer-platform",
|
|
4
8
|
"main": "src/index.js",
|
|
5
9
|
"exports": { ".": { "types": "./index.d.ts", "require": "./src/index.js", "import": "./src/index.js" } },
|
|
6
10
|
"types": "index.d.ts",
|
|
7
|
-
"files": ["src", "index.d.ts", "README.md"
|
|
11
|
+
"files": ["src", "index.d.ts", "README.md"],
|
|
8
12
|
"engines": { "node": ">=18" },
|
|
9
|
-
"dependencies": { "@chitchat/sdk-core": "0.2.0-dev.
|
|
13
|
+
"dependencies": { "@chitchat/sdk-core": "0.2.0-dev.2" },
|
|
14
|
+
"keywords": ["chitchat", "realtime", "websocket", "wss", "protobuf"],
|
|
15
|
+
"sideEffects": false,
|
|
10
16
|
"license": "UNLICENSED",
|
|
11
17
|
"publishConfig": { "access": "public", "tag": "development" }
|
|
12
18
|
}
|
package/src/index.js
CHANGED
|
@@ -22,9 +22,10 @@ const binaryFrame = (value, name) => {
|
|
|
22
22
|
|
|
23
23
|
const createWssTransportFactory = ({ WebSocketImpl = globalThis.WebSocket, encode, decode, encodeAuth, isAuthenticationAccepted, authenticationError, allowInsecureWs = false, openTimeoutMs = 15_000 }) => {
|
|
24
24
|
if (!WebSocketImpl || typeof encode !== 'function' || typeof decode !== 'function') throw new Error('WebSocket implementation and protobuf encode/decode functions are required');
|
|
25
|
+
if (typeof isAuthenticationAccepted !== 'function') throw new Error('isAuthenticationAccepted is required so the SDK can verify the realtime handshake');
|
|
25
26
|
if (typeof openTimeoutMs !== 'number' || !Number.isFinite(openTimeoutMs) || openTimeoutMs < 100 || openTimeoutMs > 120_000) throw new Error('openTimeoutMs must be between 100 and 120000');
|
|
26
27
|
return async ({ endpoint, token, protocol }) => {
|
|
27
|
-
let socket; let onMessage = () => {}; let onClose = () => {}; let opened = false; let authenticationPending =
|
|
28
|
+
let socket; let onMessage = () => {}; let onClose = () => {}; let opened = false; let authenticationPending = true;
|
|
28
29
|
const encodeFrame = (frame) => binaryFrame(encode(frame), 'protobuf.encode');
|
|
29
30
|
const encodeAuthentication = () => binaryFrame(encodeAuth ? encodeAuth({ token, protocol }) : encode({ type: 'auth', token, protocol }), 'protobuf authentication encoder');
|
|
30
31
|
return {
|
|
@@ -39,7 +40,7 @@ const createWssTransportFactory = ({ WebSocketImpl = globalThis.WebSocket, encod
|
|
|
39
40
|
socket.binaryType = 'arraybuffer';
|
|
40
41
|
timer = setTimeout(() => { try { socket.close(); } catch (_) {} finish(reject, new Error('WSS connection timed out')); }, openTimeoutMs);
|
|
41
42
|
socket.onopen = () => {
|
|
42
|
-
try { socket.send(encodeAuthentication());
|
|
43
|
+
try { socket.send(encodeAuthentication()); }
|
|
43
44
|
catch (error) { finish(reject, error); try { socket.close(); } catch (_) {} }
|
|
44
45
|
};
|
|
45
46
|
socket.onerror = () => finish(reject, new Error('WSS connection failed'));
|