call-engine-wx 0.1.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 ADDED
@@ -0,0 +1,127 @@
1
+ # call-engine-wx
2
+
3
+ Pure-JS `TUICallEngine` for WeChat Mini Program. **No WASM.**
4
+
5
+ API shape mirrors [`@trtc/call-engine-lite-wx`](../TUICallEngine-wx) so
6
+ that `TUICallKit` and existing business code can switch over without
7
+ changing event names or method signatures.
8
+
9
+ ## Why?
10
+
11
+ The legacy SDK ships a C++ core compiled to WASM plus a JS glue layer.
12
+ That works, but it adds ~hundreds of KB to the WeChat MP package and
13
+ requires a WASM-capable runtime. For the subset of API actually used in
14
+ production we can implement the call state machine directly in JS on
15
+ top of `@tencentcloud/lite-chat` and `@tencentcloud/trtc-cloud-wx`,
16
+ shaving most of the bundle weight.
17
+
18
+ `call-engine-wx` is the JS-only reimplementation. This cut implements
19
+ **login / logout / `calls`** plus the event plumbing. The remaining
20
+ call-signalling APIs (`call` / `accept` / `reject` / `hangup` / ...)
21
+ will land in follow-up increments on top of the same lite-chat session.
22
+
23
+ > **Note on transport.** `calls` does NOT use lite-chat's
24
+ > `createInvitation` / `onNewInvitationReceived` business APIs. It
25
+ > talks directly to the v3 backend service `call_engine_srv` via
26
+ > `chat.callExperimentalAPI('sendCallEngineSSOPacket', ...)` —
27
+ > the same mechanism used by the sibling pure-JS package
28
+ > `call-engine-wx`. The wire protocol is byte-identical to the C++
29
+ > reference at `tuikit_engine/src/pipeline/call/module/v3_call/`.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ pnpm add call-engine-wx @tencentcloud/lite-chat
35
+ # only if you'll call getTRTCCloudInstance() / video features
36
+ pnpm add @tencentcloud/trtc-cloud-wx
37
+ ```
38
+
39
+ `@tencentcloud/trtc-cloud-wx` is declared as an **optional**
40
+ peer-dependency. If your use case is "just login / receive offline
41
+ invites", you do not need to install it.
42
+
43
+ ## Quickstart
44
+
45
+ ```js
46
+ import TUICallEngine, { TUICallEvent } from 'call-engine-wx';
47
+
48
+ TUICallEngine.once('ready', async () => {
49
+ const engine = TUICallEngine.createInstance({ SDKAppID });
50
+
51
+ engine.on(TUICallEvent.SDK_READY, () => {
52
+ console.log('SDK ready');
53
+ });
54
+ engine.on(TUICallEvent.KICKED_OUT, () => { /* ... */ });
55
+ engine.on(TUICallEvent.onUserSigExpired, () => { /* refresh userSig */ });
56
+
57
+ await engine.login({ userID, userSig });
58
+ });
59
+ ```
60
+
61
+ ### With an existing lite-chat instance
62
+
63
+ ```js
64
+ import TencentCloudChat from '@tencentcloud/lite-chat';
65
+ import TUICallEngine from 'call-engine-wx';
66
+
67
+ const tim = TencentCloudChat.create({ SDKAppID });
68
+ const engine = TUICallEngine.createInstance({ SDKAppID, tim });
69
+ await engine.login({ userID, userSig });
70
+ ```
71
+
72
+ ## API (already implemented)
73
+
74
+ | Method | Notes |
75
+ | --- | --- |
76
+ | `TUICallEngine.createInstance(options)` | Singleton create / reuse. |
77
+ | `TUICallEngine.once('ready', fn)` | Fires on next microtask (no WASM to wait for). |
78
+ | `engine.login({ userID, userSig })` | Calls `tim.login`, emits `SDK_READY`. |
79
+ | `engine.logout()` | Calls `tim.logout`. |
80
+ | `engine.destroyInstance()` | Logout + unbind + drop singleton. |
81
+ | `engine.on / off / once` | Local event bus. |
82
+ | `engine.getTim()` | Underlying lite-chat instance. |
83
+ | `engine.getTRTCCloudInstance()` | Lazy `TRTCCloud.createInstance()`. |
84
+ | `engine.setLogLevel(level)` | Forwarded to lite-chat. |
85
+ | `engine.calls(params)` | Multi-party call. Enters the TRTC room and sends `call_engine_srv.start_call`. See below. |
86
+
87
+ ### `engine.calls(params)`
88
+
89
+ ```js
90
+ const { inviteId, roomId, callResultList } = await engine.calls({
91
+ inviteeList: ['userA', 'userB'],
92
+ mediaType: CallMediaType.VIDEO, // or CallMediaType.AUDIO
93
+ groupID: 'optional-group-id',
94
+ // roomID: 12345678, // optional, auto-generated if absent
95
+ timeout: 30, // seconds
96
+ userData: 'free-form string',
97
+ // offlinePushInfo: { ... } // optional, see ICallsParams type
98
+ });
99
+ ```
100
+
101
+ The return shape:
102
+
103
+ | Field | Type | Notes |
104
+ | --- | --- | --- |
105
+ | `inviteId` | `string` | Server-issued call_id; needed for cancel / accept / hangup. |
106
+ | `roomId` | `{ intRoomId, strRoomId }` | The TRTC room actually joined. |
107
+ | `callResultList` | `Array` | Per-callee outcome (`SUCCESS` / `INVITED` / `LINE_BUSY`). |
108
+
109
+ Side effects emitted on the engine event bus:
110
+
111
+ - `onUserJoin(userId)` for each invitee with `INVITED` (1)
112
+ - `onUserInviting(userId)` for each invitee with `SUCCESS` (0)
113
+ - `onUserLineBusy(userId)` for each invitee with `LINE_BUSY` (2)
114
+ - `onCallNotConnected({ callInfo, userId, reason: LINE_BUSY })` if every
115
+ invitee returned busy. The TRTC room is left automatically in that case.
116
+
117
+ If `start_call` fails (transport error or backend rejection), the engine
118
+ leaves the TRTC room and rejects the promise with `{ code, message }`.
119
+
120
+ ## API (not yet implemented)
121
+
122
+ `call` / `accept` / `reject` / `hangup` / `inviteUser` /
123
+ `switchCallMediaType` / `openCamera` / `closeCamera` / `openMicrophone` /
124
+ `closeMicrophone` / `startRemoteView` / `stopRemoteView` / ...
125
+
126
+ These will be added on top of the same lite-chat session, using the
127
+ backend `call_engine_srv` SSO protocol — no WASM involved.