@chitchat/sdk-react-native 0.1.0-dev.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/README.md +5 -0
- package/package.json +10 -0
- package/src/index.js +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# ChitChat React Native SDK
|
|
2
|
+
|
|
3
|
+
`createChitChatNativeClient` uses the official native TLS TCP bridge. The app developer supplies a session-token provider and imports the module; endpoint resolution, reconnects, durable outbox behavior, and TLS transport selection are handled by the SDK.
|
|
4
|
+
|
|
5
|
+
The native bridge contract is deliberately small: `connect`, `onFrame`, `onClose`, `send`, and `close`. It is the location where Android/iOS certificate pinning and binary Protobuf framing are enforced.
|
package/package.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chitchat/sdk-react-native",
|
|
3
|
+
"version": "0.1.0-dev.0",
|
|
4
|
+
"main": "src/index.js",
|
|
5
|
+
"files": ["src", "README.md", "LICENSE"],
|
|
6
|
+
"engines": { "node": ">=18" },
|
|
7
|
+
"dependencies": { "@chitchat/sdk-core": "0.1.0-dev.0" },
|
|
8
|
+
"license": "UNLICENSED",
|
|
9
|
+
"publishConfig": { "access": "public", "tag": "development" }
|
|
10
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
let ReliableRealtimeClient;
|
|
4
|
+
try { ({ ReliableRealtimeClient } = require('@chitchat/sdk-core')); } catch (_) { ({ ReliableRealtimeClient } = require('../../chitchat-core/src')); }
|
|
5
|
+
|
|
6
|
+
const createNativeTcpTransportFactory = ({ nativeModule }) => {
|
|
7
|
+
if (!nativeModule || typeof nativeModule.connect !== 'function') throw new Error('The official ChitChat native TCP module is required');
|
|
8
|
+
return async ({ endpoint, token, protocol }) => {
|
|
9
|
+
let connection; let onMessage = () => {}; let onClose = () => {};
|
|
10
|
+
return {
|
|
11
|
+
onMessage: (listener) => { onMessage = listener; },
|
|
12
|
+
onClose: (listener) => { onClose = listener; },
|
|
13
|
+
open: async () => {
|
|
14
|
+
connection = await nativeModule.connect({ endpoint, token, protocol, tls: true });
|
|
15
|
+
connection.onFrame((frame) => onMessage(frame));
|
|
16
|
+
connection.onClose((reason) => onClose(reason));
|
|
17
|
+
},
|
|
18
|
+
send: (frame) => connection.send(frame),
|
|
19
|
+
close: () => connection ? connection.close() : Promise.resolve()
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const createChitChatNativeClient = ({ endpoint, tokenProvider, nativeModule, ...options }) => new ReliableRealtimeClient({ endpoint, tokenProvider, runtime: 'native', nativeTransportFactory: createNativeTcpTransportFactory({ nativeModule }), ...options });
|
|
25
|
+
|
|
26
|
+
module.exports = { createChitChatNativeClient, createNativeTcpTransportFactory };
|