@chat-leo/chatleolib 0.0.0-stage → 2.0.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/LICENSE +21 -0
- package/README.md +69 -2
- package/dist/ChatLeoWorker.d.ts +83 -0
- package/dist/ChatLeoWorker.d.ts.map +1 -0
- package/dist/ChatLeoWorker.js +255 -0
- package/dist/ChatLeoWorker.js.map +1 -0
- package/dist/ChatRoom.d.ts +121 -0
- package/dist/ChatRoom.d.ts.map +1 -0
- package/dist/ChatRoom.js +416 -0
- package/dist/ChatRoom.js.map +1 -0
- package/dist/ChatStore.d.ts +252 -0
- package/dist/ChatStore.d.ts.map +1 -0
- package/dist/ChatStore.js +774 -0
- package/dist/ChatStore.js.map +1 -0
- package/dist/JwtUtils.d.ts +39 -0
- package/dist/JwtUtils.d.ts.map +1 -0
- package/dist/JwtUtils.js +89 -0
- package/dist/JwtUtils.js.map +1 -0
- package/dist/Outbox.d.ts +68 -0
- package/dist/Outbox.d.ts.map +1 -0
- package/dist/Outbox.js +253 -0
- package/dist/Outbox.js.map +1 -0
- package/dist/UploadManager.d.ts +80 -0
- package/dist/UploadManager.d.ts.map +1 -0
- package/dist/UploadManager.js +204 -0
- package/dist/UploadManager.js.map +1 -0
- package/dist/chatleo-push-sw.js +149 -0
- package/dist/chatleo-push-sw.js.map +1 -0
- package/dist/index.d.ts +236 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +8526 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +8535 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +8541 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/push/PushService.d.ts +32 -0
- package/dist/push/PushService.d.ts.map +1 -0
- package/dist/push/PushService.js +215 -0
- package/dist/push/PushService.js.map +1 -0
- package/dist/push-sw/index.d.ts +9 -0
- package/dist/push-sw/index.d.ts.map +1 -0
- package/dist/push-sw/index.js +142 -0
- package/dist/push-sw/index.js.map +1 -0
- package/dist/push-sw/standalone.d.ts +2 -0
- package/dist/push-sw/standalone.d.ts.map +1 -0
- package/dist/push-sw/standalone.js +3 -0
- package/dist/push-sw/standalone.js.map +1 -0
- package/dist/transport/SocketIoTransport.d.ts +37 -0
- package/dist/transport/SocketIoTransport.d.ts.map +1 -0
- package/dist/transport/SocketIoTransport.js +209 -0
- package/dist/transport/SocketIoTransport.js.map +1 -0
- package/dist/transport/WsV2Transport.d.ts +109 -0
- package/dist/transport/WsV2Transport.d.ts.map +1 -0
- package/dist/transport/WsV2Transport.js +604 -0
- package/dist/transport/WsV2Transport.js.map +1 -0
- package/dist/transport/discovery.d.ts +43 -0
- package/dist/transport/discovery.d.ts.map +1 -0
- package/dist/transport/discovery.js +87 -0
- package/dist/transport/discovery.js.map +1 -0
- package/dist/transport/factory.d.ts +38 -0
- package/dist/transport/factory.d.ts.map +1 -0
- package/dist/transport/factory.js +79 -0
- package/dist/transport/factory.js.map +1 -0
- package/dist/transport/index.d.ts +7 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +5 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/types.d.ts +174 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +35 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/transport/util.d.ts +8 -0
- package/dist/transport/util.d.ts.map +1 -0
- package/dist/transport/util.js +33 -0
- package/dist/transport/util.js.map +1 -0
- package/dist/types/shared.d.ts +281 -0
- package/dist/types/shared.d.ts.map +1 -0
- package/dist/types/shared.js +2 -0
- package/dist/types/shared.js.map +1 -0
- package/dist/types/uploads.d.ts +14 -0
- package/dist/types/uploads.d.ts.map +1 -0
- package/dist/types/uploads.js +3 -0
- package/dist/types/uploads.js.map +1 -0
- package/package.json +70 -3
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decoupled file uploader with concurrency queue management.
|
|
3
|
+
* Emits events for upload progress, completion, and errors without directly modifying ChatStore.
|
|
4
|
+
*
|
|
5
|
+
* Events emitted:
|
|
6
|
+
* - 'uploadQueued': When a file is queued for upload
|
|
7
|
+
* - 'uploadProgress': During file upload with progress percentage
|
|
8
|
+
* - 'uploadCompleted': When upload successfully completes
|
|
9
|
+
* - 'uploadFailed': When upload fails with error details
|
|
10
|
+
* - 'uploadRemoved': When upload is canceled or removed
|
|
11
|
+
*/
|
|
12
|
+
export class UploadManager extends EventTarget {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new UploadManager instance.
|
|
15
|
+
* @param maxConcurrent - Maximum number of concurrent uploads (default: 3)
|
|
16
|
+
*/
|
|
17
|
+
constructor(maxConcurrent = 3) {
|
|
18
|
+
super();
|
|
19
|
+
this.running = 0;
|
|
20
|
+
this.queue = []; // queue of file id
|
|
21
|
+
// Local cache: fileId -> { file, ref, abort, xhr }
|
|
22
|
+
this.files = new Map();
|
|
23
|
+
this.maxConcurrent = maxConcurrent;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Start uploads for a message with the provided files and server acknowledgments.
|
|
27
|
+
* This method combines file registration and upload initiation into a single operation.
|
|
28
|
+
*
|
|
29
|
+
* @param messageId - The message ID these uploads belong to
|
|
30
|
+
* @param fileMap - Map of file IDs to File objects to upload
|
|
31
|
+
* @param acks - Array of server acknowledgments containing upload URLs and metadata
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const fileMap = new Map([
|
|
36
|
+
* ['file1', new File(['content'], 'test.txt')],
|
|
37
|
+
* ['file2', new File(['image'], 'image.png')]
|
|
38
|
+
* ]);
|
|
39
|
+
* const acks = [
|
|
40
|
+
* { file_id: 'file1', upload_url: 'https://...', expires_at: '...' },
|
|
41
|
+
* { file_id: 'file2', upload_url: 'https://...', expires_at: '...' }
|
|
42
|
+
* ];
|
|
43
|
+
* uploadManager.startUploads(messageId, fileMap, acks);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
startUploads(messageId, fileMap, acks) {
|
|
47
|
+
// Register and queue files based on acknowledgments
|
|
48
|
+
for (const ack of acks) {
|
|
49
|
+
const file = fileMap.get(ack.file_id);
|
|
50
|
+
if (!file)
|
|
51
|
+
continue;
|
|
52
|
+
const mime = file.type || 'application/octet-stream';
|
|
53
|
+
const ref = {
|
|
54
|
+
fileId: ack.file_id,
|
|
55
|
+
messageId,
|
|
56
|
+
mime,
|
|
57
|
+
name: file.name,
|
|
58
|
+
size: file.size,
|
|
59
|
+
progress: 0,
|
|
60
|
+
status: 'awaiting_url',
|
|
61
|
+
uploadUrl: ack.upload_url,
|
|
62
|
+
expiresAt: ack.expires_at,
|
|
63
|
+
};
|
|
64
|
+
const abort = new AbortController();
|
|
65
|
+
this.files.set(ack.file_id, { file, ref, abort });
|
|
66
|
+
this.dispatchEvent(new CustomEvent('uploadQueued', { detail: { fileId: ack.file_id, ref } }));
|
|
67
|
+
this.enqueue(ack.file_id);
|
|
68
|
+
}
|
|
69
|
+
this.pump();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Cancel an upload by file ID.
|
|
73
|
+
* Aborts the upload if in progress and removes it from the queue.
|
|
74
|
+
*
|
|
75
|
+
* @param fileId - The ID of the file to cancel
|
|
76
|
+
*/
|
|
77
|
+
cancel(fileId) {
|
|
78
|
+
const entry = this.files.get(fileId);
|
|
79
|
+
if (!entry)
|
|
80
|
+
return;
|
|
81
|
+
try {
|
|
82
|
+
entry.abort.abort();
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
entry.ref.status = 'canceled';
|
|
86
|
+
this.dispatchEvent(new CustomEvent('uploadRemoved', { detail: { fileId, messageId: entry.ref.messageId, ref: entry.ref } }));
|
|
87
|
+
this.files.delete(fileId);
|
|
88
|
+
// Remove from queue if present
|
|
89
|
+
this.queue = this.queue.filter(id => id !== fileId);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Retry a failed or canceled upload.
|
|
94
|
+
* Only works for uploads with 'error' or 'canceled' status.
|
|
95
|
+
*
|
|
96
|
+
* @param fileId - The ID of the file to retry
|
|
97
|
+
*/
|
|
98
|
+
retry(fileId) {
|
|
99
|
+
const entry = this.files.get(fileId);
|
|
100
|
+
if (!entry)
|
|
101
|
+
return;
|
|
102
|
+
// Allow retry only for error/canceled
|
|
103
|
+
if (entry.ref.status !== 'error' && entry.ref.status !== 'canceled')
|
|
104
|
+
return;
|
|
105
|
+
entry.ref.status = 'queued';
|
|
106
|
+
entry.ref.progress = 0;
|
|
107
|
+
entry.abort = new AbortController();
|
|
108
|
+
this.queue.push(fileId);
|
|
109
|
+
this.pump();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Add a file ID to the upload queue if not already present.
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
enqueue(fileId) {
|
|
116
|
+
// avoid duplicates
|
|
117
|
+
if (!this.queue.includes(fileId))
|
|
118
|
+
this.queue.push(fileId);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Process the upload queue, starting uploads up to the concurrency limit.
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
pump() {
|
|
125
|
+
while (this.running < this.maxConcurrent && this.queue.length > 0) {
|
|
126
|
+
const fileId = this.queue.shift();
|
|
127
|
+
const entry = this.files.get(fileId);
|
|
128
|
+
if (!entry)
|
|
129
|
+
continue;
|
|
130
|
+
if (!entry.ref.uploadUrl)
|
|
131
|
+
continue;
|
|
132
|
+
this.running++;
|
|
133
|
+
this.uploadOne(fileId, entry)
|
|
134
|
+
.finally(() => {
|
|
135
|
+
this.running--;
|
|
136
|
+
// continue pumping after each completion
|
|
137
|
+
this.pump();
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Upload a single file using XMLHttpRequest.
|
|
143
|
+
* Emits progress, completion, and error events.
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
uploadOne(fileId, entry) {
|
|
147
|
+
return new Promise((resolve) => {
|
|
148
|
+
const { file, ref } = entry;
|
|
149
|
+
const url = ref.uploadUrl;
|
|
150
|
+
const xhr = new XMLHttpRequest();
|
|
151
|
+
entry.xhr = xhr;
|
|
152
|
+
// Connect AbortController to XMLHttpRequest
|
|
153
|
+
entry.abort.signal.addEventListener('abort', () => {
|
|
154
|
+
xhr.abort();
|
|
155
|
+
});
|
|
156
|
+
xhr.upload.onprogress = (ev) => {
|
|
157
|
+
if (ev.lengthComputable) {
|
|
158
|
+
const pct = Math.round((ev.loaded / ev.total) * 100);
|
|
159
|
+
ref.progress = pct;
|
|
160
|
+
ref.status = 'uploading';
|
|
161
|
+
this.dispatchEvent(new CustomEvent('uploadProgress', { detail: { messageId: ref.messageId, fileId, progress: pct, ref } }));
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
xhr.onload = () => {
|
|
165
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
166
|
+
ref.progress = 100;
|
|
167
|
+
ref.status = 'done';
|
|
168
|
+
this.dispatchEvent(new CustomEvent('uploadCompleted', { detail: { messageId: ref.messageId, fileId, ref } }));
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
ref.status = 'error';
|
|
172
|
+
ref.error = `HTTP ${xhr.status}`;
|
|
173
|
+
this.dispatchEvent(new CustomEvent('uploadFailed', { detail: { messageId: ref.messageId, fileId, error: ref.error, ref } }));
|
|
174
|
+
}
|
|
175
|
+
resolve();
|
|
176
|
+
};
|
|
177
|
+
xhr.onerror = () => {
|
|
178
|
+
ref.status = 'error';
|
|
179
|
+
ref.error = 'Network error';
|
|
180
|
+
this.dispatchEvent(new CustomEvent('uploadFailed', { detail: { messageId: ref.messageId, fileId, error: ref.error, ref } }));
|
|
181
|
+
resolve();
|
|
182
|
+
};
|
|
183
|
+
xhr.onabort = () => {
|
|
184
|
+
ref.status = 'canceled';
|
|
185
|
+
this.dispatchEvent(new CustomEvent('uploadRemoved', { detail: { messageId: ref.messageId, fileId, ref } }));
|
|
186
|
+
resolve();
|
|
187
|
+
};
|
|
188
|
+
try {
|
|
189
|
+
xhr.open('POST', url, true);
|
|
190
|
+
const mime = file.type || ref.mime || 'application/octet-stream';
|
|
191
|
+
xhr.setRequestHeader('Content-Type', mime);
|
|
192
|
+
xhr.setRequestHeader('Authorization', `Bearer ${this.acess_token}`);
|
|
193
|
+
xhr.send(file); // TODO: handle 413 Payload Too Large
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
ref.status = 'error';
|
|
197
|
+
ref.error = (e === null || e === void 0 ? void 0 : e.message) || 'Failed to start upload';
|
|
198
|
+
this.dispatchEvent(new CustomEvent('uploadFailed', { detail: { messageId: ref.messageId, fileId, error: ref.error, ref } }));
|
|
199
|
+
resolve();
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=UploadManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UploadManager.js","sourceRoot":"","sources":["../src/UploadManager.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,aAAc,SAAQ,WAAW;IAU5C;;;OAGG;IACH,YAAY,aAAa,GAAG,CAAC;QAC3B,KAAK,EAAE,CAAC;QAbF,YAAO,GAAG,CAAC,CAAC;QACZ,UAAK,GAAa,EAAE,CAAC,CAAC,mBAAmB;QAIjD,mDAAmD;QAC3C,UAAK,GAAyG,IAAI,GAAG,EAAE,CAAC;QAQ9H,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,YAAY,CACV,SAAiB,EACjB,OAA0B,EAC1B,IAAyE;QAEzE,oDAAoD;QACpD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO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,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;gBAC7H,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ChatLeo push handling for a service worker. Import this module into an existing worker
|
|
6
|
+
* (`registerChatLeoPush(self)`) or serve the generated stand-alone `chatleo-push-sw.js`.
|
|
7
|
+
*
|
|
8
|
+
* The worker holds no ChatLeo token and makes no authenticated request. It only shows and
|
|
9
|
+
* routes notifications; subscription changes are marked for the next page to re-register.
|
|
10
|
+
*/
|
|
11
|
+
const DB_NAME = 'chatleo-push';
|
|
12
|
+
const STORE = 'markers';
|
|
13
|
+
const RE_REGISTER_KEY = 're-register';
|
|
14
|
+
function openDb() {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const request = indexedDB.open(DB_NAME, 1);
|
|
17
|
+
request.onupgradeneeded = () => {
|
|
18
|
+
if (!request.result.objectStoreNames.contains(STORE))
|
|
19
|
+
request.result.createObjectStore(STORE);
|
|
20
|
+
};
|
|
21
|
+
request.onsuccess = () => resolve(request.result);
|
|
22
|
+
request.onerror = () => reject(request.error);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function markReRegister() {
|
|
26
|
+
try {
|
|
27
|
+
const db = await openDb();
|
|
28
|
+
await new Promise(resolve => {
|
|
29
|
+
const tx = db.transaction(STORE, 'readwrite');
|
|
30
|
+
tx.objectStore(STORE).put(true, RE_REGISTER_KEY);
|
|
31
|
+
tx.oncomplete = () => resolve();
|
|
32
|
+
tx.onerror = () => resolve();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (_a) {
|
|
36
|
+
// The next page will register anyway.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function payloadOf(event) {
|
|
40
|
+
var _a;
|
|
41
|
+
try {
|
|
42
|
+
return ((_a = event.data) === null || _a === void 0 ? void 0 : _a.json) ? event.data.json() : null;
|
|
43
|
+
}
|
|
44
|
+
catch (_b) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Ask one window whether it is displaying the room; unknown answers mean "not visible". */
|
|
49
|
+
function visibleRoom(client, roomId) {
|
|
50
|
+
return new Promise(resolve => {
|
|
51
|
+
const timer = setTimeout(() => resolve(false), 150);
|
|
52
|
+
try {
|
|
53
|
+
const channel = new MessageChannel();
|
|
54
|
+
channel.port1.onmessage = (message) => {
|
|
55
|
+
var _a;
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
resolve(!!((_a = message.data) === null || _a === void 0 ? void 0 : _a.visible));
|
|
58
|
+
};
|
|
59
|
+
client.postMessage({ type: 'chatleo:pushVisibility', roomId }, [channel.port2]);
|
|
60
|
+
}
|
|
61
|
+
catch (_a) {
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
resolve(false);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async function updateBadge(scope, delta = 0) {
|
|
68
|
+
if (!('setAppBadge' in scope) || !('clearAppBadge' in scope))
|
|
69
|
+
return;
|
|
70
|
+
try {
|
|
71
|
+
const notifications = await scope.registration.getNotifications();
|
|
72
|
+
const count = Math.max(0, notifications.length + delta);
|
|
73
|
+
if (count === 0)
|
|
74
|
+
await scope.clearAppBadge();
|
|
75
|
+
else
|
|
76
|
+
await scope.setAppBadge(count);
|
|
77
|
+
}
|
|
78
|
+
catch (_a) {
|
|
79
|
+
// Badging is progressive.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function registerChatLeoPush(scope) {
|
|
83
|
+
scope.addEventListener('push', (event) => {
|
|
84
|
+
event.waitUntil((async () => {
|
|
85
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
86
|
+
const payload = payloadOf(event);
|
|
87
|
+
if (!payload)
|
|
88
|
+
return;
|
|
89
|
+
const data = (_c = (_b = (_a = payload.options) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : payload.data) !== null && _c !== void 0 ? _c : {};
|
|
90
|
+
// A host may share its worker with other products: only handle ChatLeo payloads.
|
|
91
|
+
const kind = String((_d = data.kind) !== null && _d !== void 0 ? _d : '');
|
|
92
|
+
const isChatLeo = data.chatleo === true || ['message', 'call', 'call-ringing', 'transcription'].includes(kind) || !!data.room_id;
|
|
93
|
+
if (!isChatLeo)
|
|
94
|
+
return;
|
|
95
|
+
const roomId = String((_e = data.room_id) !== null && _e !== void 0 ? _e : '');
|
|
96
|
+
const clients = await scope.clients.matchAll({ type: 'window', includeUncontrolled: true });
|
|
97
|
+
for (const client of clients) {
|
|
98
|
+
if (client.visibilityState !== 'visible')
|
|
99
|
+
continue;
|
|
100
|
+
if (await visibleRoom(client, roomId))
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
await scope.registration.showNotification((_f = payload.title) !== null && _f !== void 0 ? _f : 'ChatLeo', {
|
|
104
|
+
body: (_j = (_h = (_g = payload.options) === null || _g === void 0 ? void 0 : _g.body) !== null && _h !== void 0 ? _h : payload.body) !== null && _j !== void 0 ? _j : '',
|
|
105
|
+
icon: (_l = (_k = payload.options) === null || _k === void 0 ? void 0 : _k.icon) !== null && _l !== void 0 ? _l : payload.icon,
|
|
106
|
+
badge: (_o = (_m = payload.options) === null || _m === void 0 ? void 0 : _m.badge) !== null && _o !== void 0 ? _o : payload.badge,
|
|
107
|
+
tag: (_r = (_q = (_p = payload.options) === null || _p === void 0 ? void 0 : _p.tag) !== null && _q !== void 0 ? _q : payload.tag) !== null && _r !== void 0 ? _r : roomId,
|
|
108
|
+
renotify: (_t = (_s = payload.options) === null || _s === void 0 ? void 0 : _s.renotify) !== null && _t !== void 0 ? _t : true,
|
|
109
|
+
data: {
|
|
110
|
+
...((_v = (_u = payload.options) === null || _u === void 0 ? void 0 : _u.data) !== null && _v !== void 0 ? _v : data),
|
|
111
|
+
url: (_0 = (_z = (_y = (_x = (_w = payload.options) === null || _w === void 0 ? void 0 : _w.data) === null || _x === void 0 ? void 0 : _x.url) !== null && _y !== void 0 ? _y : data.url) !== null && _z !== void 0 ? _z : payload.url) !== null && _0 !== void 0 ? _0 : payload.clickUrl,
|
|
112
|
+
room_id: roomId,
|
|
113
|
+
kind: data.kind,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
await updateBadge(scope, 1);
|
|
117
|
+
})());
|
|
118
|
+
});
|
|
119
|
+
scope.addEventListener('notificationclick', (event) => {
|
|
120
|
+
var _a, _b;
|
|
121
|
+
(_b = (_a = event.notification) === null || _a === void 0 ? void 0 : _a.close) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
122
|
+
event.waitUntil((async () => {
|
|
123
|
+
var _a, _b, _c, _d;
|
|
124
|
+
const data = (_b = (_a = event.notification) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
125
|
+
const roomId = String((_c = data.room_id) !== null && _c !== void 0 ? _c : '');
|
|
126
|
+
const clients = await scope.clients.matchAll({ type: 'window', includeUncontrolled: true });
|
|
127
|
+
for (const client of clients) {
|
|
128
|
+
if ('focus' in client)
|
|
129
|
+
await client.focus();
|
|
130
|
+
client.postMessage({ type: 'chatleo:openRoom', roomId });
|
|
131
|
+
await updateBadge(scope, -1);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const url = (_d = data.url) !== null && _d !== void 0 ? _d : (roomId ? `/?room=${encodeURIComponent(roomId)}` : '/');
|
|
135
|
+
if (scope.clients.openWindow)
|
|
136
|
+
await scope.clients.openWindow(url);
|
|
137
|
+
await updateBadge(scope, -1);
|
|
138
|
+
})());
|
|
139
|
+
});
|
|
140
|
+
scope.addEventListener('pushsubscriptionchange', (event) => {
|
|
141
|
+
// The worker cannot authenticate; the next page start re-registers the new subscription.
|
|
142
|
+
event.waitUntil(markReRegister());
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
registerChatLeoPush(self);
|
|
147
|
+
|
|
148
|
+
})();
|
|
149
|
+
//# sourceMappingURL=chatleo-push-sw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatleo-push-sw.js","sources":["../src/push-sw/index.ts","../src/push-sw/standalone.ts"],"sourcesContent":["/**\n * ChatLeo push handling for a service worker. Import this module into an existing worker\n * (`registerChatLeoPush(self)`) or serve the generated stand-alone `chatleo-push-sw.js`.\n *\n * The worker holds no ChatLeo token and makes no authenticated request. It only shows and\n * routes notifications; subscription changes are marked for the next page to re-register.\n */\n\nconst DB_NAME = 'chatleo-push';\nconst STORE = 'markers';\nconst RE_REGISTER_KEY = 're-register';\n\nfunction openDb(): Promise<IDBDatabase> {\n return new Promise((resolve, reject) => {\n const request = indexedDB.open(DB_NAME, 1);\n request.onupgradeneeded = () => {\n if (!request.result.objectStoreNames.contains(STORE)) request.result.createObjectStore(STORE);\n };\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error);\n });\n}\n\nasync function markReRegister(): Promise<void> {\n try {\n const db = await openDb();\n await new Promise<void>(resolve => {\n const tx = db.transaction(STORE, 'readwrite');\n tx.objectStore(STORE).put(true, RE_REGISTER_KEY);\n tx.oncomplete = () => resolve();\n tx.onerror = () => resolve();\n });\n } catch {\n // The next page will register anyway.\n }\n}\n\nfunction payloadOf(event: any): any {\n try {\n return event.data?.json ? event.data.json() : null;\n } catch {\n return null;\n }\n}\n\n/** Ask one window whether it is displaying the room; unknown answers mean \"not visible\". */\nfunction visibleRoom(client: any, roomId: string): Promise<boolean> {\n return new Promise(resolve => {\n const timer = setTimeout(() => resolve(false), 150);\n try {\n const channel = new MessageChannel();\n channel.port1.onmessage = (message: MessageEvent) => {\n clearTimeout(timer);\n resolve(!!message.data?.visible);\n };\n client.postMessage({ type: 'chatleo:pushVisibility', roomId }, [channel.port2]);\n } catch {\n clearTimeout(timer);\n resolve(false);\n }\n });\n}\n\nasync function updateBadge(scope: any, delta = 0): Promise<void> {\n if (!('setAppBadge' in scope) || !('clearAppBadge' in scope)) return;\n try {\n const notifications = await scope.registration.getNotifications();\n const count = Math.max(0, notifications.length + delta);\n if (count === 0) await scope.clearAppBadge();\n else await scope.setAppBadge(count);\n } catch {\n // Badging is progressive.\n }\n}\n\nexport function registerChatLeoPush(scope: any): void {\n scope.addEventListener('push', (event: any) => {\n event.waitUntil(\n (async () => {\n const payload = payloadOf(event);\n if (!payload) return;\n const data = payload.options?.data ?? payload.data ?? {};\n // A host may share its worker with other products: only handle ChatLeo payloads.\n const kind = String(data.kind ?? '');\n const isChatLeo = data.chatleo === true || ['message', 'call', 'call-ringing', 'transcription'].includes(kind) || !!data.room_id;\n if (!isChatLeo) return;\n\n const roomId = String(data.room_id ?? '');\n const clients = await scope.clients.matchAll({ type: 'window', includeUncontrolled: true });\n for (const client of clients) {\n if (client.visibilityState !== 'visible') continue;\n if (await visibleRoom(client, roomId)) return;\n }\n\n await scope.registration.showNotification(payload.title ?? 'ChatLeo', {\n body: payload.options?.body ?? payload.body ?? '',\n icon: payload.options?.icon ?? payload.icon,\n badge: payload.options?.badge ?? payload.badge,\n tag: payload.options?.tag ?? payload.tag ?? roomId,\n renotify: payload.options?.renotify ?? true,\n data: {\n ...(payload.options?.data ?? data),\n url: payload.options?.data?.url ?? data.url ?? payload.url ?? payload.clickUrl,\n room_id: roomId,\n kind: data.kind,\n },\n });\n await updateBadge(scope, 1);\n })(),\n );\n });\n\n scope.addEventListener('notificationclick', (event: any) => {\n event.notification?.close?.();\n event.waitUntil(\n (async () => {\n const data = event.notification?.data ?? {};\n const roomId = String(data.room_id ?? '');\n const clients = await scope.clients.matchAll({ type: 'window', includeUncontrolled: true });\n for (const client of clients) {\n if ('focus' in client) await client.focus();\n client.postMessage({ type: 'chatleo:openRoom', roomId });\n await updateBadge(scope, -1);\n return;\n }\n const url = data.url ?? (roomId ? `/?room=${encodeURIComponent(roomId)}` : '/');\n if (scope.clients.openWindow) await scope.clients.openWindow(url);\n await updateBadge(scope, -1);\n })(),\n );\n });\n\n scope.addEventListener('pushsubscriptionchange', (event: any) => {\n // The worker cannot authenticate; the next page start re-registers the new subscription.\n event.waitUntil(markReRegister());\n });\n}\n","import { registerChatLeoPush } from './index';\n\ndeclare const self: any;\n\nregisterChatLeoPush(self);\n"],"names":[],"mappings":";;;IAAA;;;;;;IAMG;IAEH,MAAM,OAAO,GAAG,cAAc;IAC9B,MAAM,KAAK,GAAG,SAAS;IACvB,MAAM,eAAe,GAAG,aAAa;IAErC,SAAS,MAAM,GAAA;QACb,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;YACrC,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1C,QAAA,OAAO,CAAC,eAAe,GAAG,MAAK;gBAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC;IAAE,gBAAA,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC;IAC/F,QAAA,CAAC;IACD,QAAA,OAAO,CAAC,SAAS,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;IACjD,QAAA,OAAO,CAAC,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;IAC/C,IAAA,CAAC,CAAC;IACJ;IAEA,eAAe,cAAc,GAAA;IAC3B,IAAA,IAAI;IACF,QAAA,MAAM,EAAE,GAAG,MAAM,MAAM,EAAE;IACzB,QAAA,MAAM,IAAI,OAAO,CAAO,OAAO,IAAG;gBAChC,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC;IAC7C,YAAA,EAAE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M,MAAM,IAAI,OAAO,EAAE;oBAC5B,IAAI,OAAO,IAAI,MAAM;IAAE,oBAAA,MAAM,MAAM,CAAC,KAAK,EAAE;oBAC3C,MAAM,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC;IACxD,gBAAA,MAAM,WAAW,CAAC,KAAK,EAAE,EAAE,CAAC;oBAC5B;gBACF;gBACA,MAAM,GAAG,GAAG,CAAA,EAAA,GAAA,IAAI,CAAC,GAAG,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,EAAA,IAAK,MAAM,GAAG,CAAA,OAAA,EAAU,kBAAkB,CAAC,MAAM,CAAC,CAAA,CAAE,GAAG,GAAG,CAAC;IAC/E,YAAA,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU;oBAAE,MAAM,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;IACjE,YAAA,MAAM,WAAW,CAAC,KAAK,EAAE,EAAE,CAAC;YAC9B,CAAC,GAAG,CACL;IACH,IAAA,CAAC,CAAC;QAEF,KAAK,CAAC,gBAAgB,CAAC,wBAAwB,EAAE,CAAC,KAAU,KAAI;;IAE9D,QAAA,KAAK,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;IACnC,IAAA,CAAC,CAAC;IACJ;;ICpIA,mBAAmB,CAAC,IAAI,CAAC;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { UserProfile, ChatMessageSent } from './types/shared';
|
|
2
|
+
import { ChatStore, ConnectionStatus } from './ChatStore';
|
|
3
|
+
import { TransportSetting } from './transport/factory';
|
|
4
|
+
import type { ActiveCall, CallCredentials, CallMode, NotificationLevel, PushConfig, PushPreferences, PushState } from './types/shared';
|
|
5
|
+
import { PushService } from './push/PushService';
|
|
6
|
+
export interface ChatLeoClient {
|
|
7
|
+
chatLeoLib?: ChatLeoLib;
|
|
8
|
+
chatStore?: ChatStore;
|
|
9
|
+
serverUrl?: string;
|
|
10
|
+
setLoading?(loading: boolean): void;
|
|
11
|
+
setLoggedIn?(isLoggedIn: boolean, profile?: UserProfile | null): void;
|
|
12
|
+
setConnected?(isConnected: boolean): void;
|
|
13
|
+
/** Optional richer status callback; callers that only implement setConnected still work. */
|
|
14
|
+
setConnectionStatus?(status: ConnectionStatus): void;
|
|
15
|
+
setSessionExpired?(expired: boolean): void;
|
|
16
|
+
}
|
|
17
|
+
type ConnectionOptions = {
|
|
18
|
+
username?: string;
|
|
19
|
+
password?: string;
|
|
20
|
+
ticket?: string;
|
|
21
|
+
/** Real-time protocol for this login; overrides `ChatLeoLib.transport` (e.g. from the `transport` attribute). */
|
|
22
|
+
transport?: TransportSetting;
|
|
23
|
+
};
|
|
24
|
+
/** Why a sign-in attempt failed, so a host application can show a useful message. */
|
|
25
|
+
export type ChatLeoLoginFailure = 'invalid_credentials' | 'invalid_ticket' | 'unreachable' | 'server_error';
|
|
26
|
+
/** A sign-in failure with a machine-readable reason. */
|
|
27
|
+
export declare class ChatLeoLoginError extends Error {
|
|
28
|
+
readonly reason: ChatLeoLoginFailure;
|
|
29
|
+
readonly status?: number | undefined;
|
|
30
|
+
constructor(reason: ChatLeoLoginFailure, status?: number | undefined, message?: string);
|
|
31
|
+
}
|
|
32
|
+
/** Tokens and profile a host application can persist to restore a session later. */
|
|
33
|
+
export interface ChatLeoSession {
|
|
34
|
+
serverUrl: string;
|
|
35
|
+
accessToken: string;
|
|
36
|
+
refreshToken: string;
|
|
37
|
+
profile: UserProfile;
|
|
38
|
+
}
|
|
39
|
+
/** Error from a ChatLeo call REST endpoint, with the server's code preserved. */
|
|
40
|
+
export declare class ChatCallError extends Error {
|
|
41
|
+
readonly status: number;
|
|
42
|
+
readonly code: string;
|
|
43
|
+
constructor(status: number, code: string, message?: string);
|
|
44
|
+
}
|
|
45
|
+
export declare class ChatLeoLib {
|
|
46
|
+
#private;
|
|
47
|
+
/** Set to `true` before first login to enable the experimental SharedWorker cross-tab connection. */
|
|
48
|
+
static useSharedWorker: boolean;
|
|
49
|
+
/** Absolute URL to the bundled SharedWorker script. Must be set when `useSharedWorker` is true. */
|
|
50
|
+
static workerScriptUrl: string;
|
|
51
|
+
/**
|
|
52
|
+
* Real-time protocol: `socketio` (default), `v2` (ChatLeo Protocol v2) or `auto` (v2 when the
|
|
53
|
+
* server's `/.well-known/chatleo` offers it, otherwise Socket.IO). A `transport` passed to
|
|
54
|
+
* `requestConnection` (the `transport` attribute of `<chatleo-component>`) takes precedence.
|
|
55
|
+
*/
|
|
56
|
+
static transport: TransportSetting;
|
|
57
|
+
private serverUrlName;
|
|
58
|
+
private accessToken;
|
|
59
|
+
private refreshToken;
|
|
60
|
+
private userProfile;
|
|
61
|
+
private transportOverride;
|
|
62
|
+
private transport;
|
|
63
|
+
private transportUnsubscribe;
|
|
64
|
+
private isLoggedIn;
|
|
65
|
+
private messagesByRoom;
|
|
66
|
+
private chatStore;
|
|
67
|
+
private clients;
|
|
68
|
+
private loginPromise;
|
|
69
|
+
private refreshTimer;
|
|
70
|
+
private isRefreshing;
|
|
71
|
+
private refreshPromise;
|
|
72
|
+
private refreshRetryCount;
|
|
73
|
+
private static readonly MAX_REFRESH_RETRIES;
|
|
74
|
+
private resumeDebounceTimer;
|
|
75
|
+
private lastSyncedAt;
|
|
76
|
+
private static readonly RESUME_SYNC_COOLDOWN_MS;
|
|
77
|
+
/** `null` until the first room list / sync response tells us whether the server sequences. */
|
|
78
|
+
private supportsSequencing;
|
|
79
|
+
private syncInFlight;
|
|
80
|
+
private readonly readMarkerTimers;
|
|
81
|
+
private readonly gapFetches;
|
|
82
|
+
private readonly outbox;
|
|
83
|
+
private static readonly READ_MARKER_DEBOUNCE_MS;
|
|
84
|
+
private static readonly MESSAGE_PAGE_SIZE;
|
|
85
|
+
private sharedWorker;
|
|
86
|
+
private workerPort;
|
|
87
|
+
private workerSessionKey;
|
|
88
|
+
private workerRequests;
|
|
89
|
+
private usingSharedWorker;
|
|
90
|
+
/** `calls="auto"` fetches discovery once; `off` never shows or requests calls. */
|
|
91
|
+
private callsEnabled;
|
|
92
|
+
private callsSupported;
|
|
93
|
+
private callsLookup?;
|
|
94
|
+
private transportKind;
|
|
95
|
+
private pushServiceInstance?;
|
|
96
|
+
constructor();
|
|
97
|
+
/**
|
|
98
|
+
* Signs in with credentials and completes the session (transport, rooms, users).
|
|
99
|
+
*
|
|
100
|
+
* Unlike `login()`, this throws a `ChatLeoLoginError` with a reason, which is what an
|
|
101
|
+
* application shell needs to tell "wrong password" from "server unreachable".
|
|
102
|
+
*/
|
|
103
|
+
signIn(options: {
|
|
104
|
+
username?: string;
|
|
105
|
+
password?: string;
|
|
106
|
+
ticket?: string;
|
|
107
|
+
transport?: TransportSetting;
|
|
108
|
+
}): Promise<UserProfile>;
|
|
109
|
+
/** The current session, or `null` when not signed in. */
|
|
110
|
+
getSession(): ChatLeoSession | null;
|
|
111
|
+
/** The reactive state store (rooms, users, presence and unread totals). */
|
|
112
|
+
get store(): ChatStore;
|
|
113
|
+
/**
|
|
114
|
+
* Restores a session persisted by the host application.
|
|
115
|
+
*
|
|
116
|
+
* The access token is refreshed when it is near expiry; the refresh token is not
|
|
117
|
+
* validated eagerly, so an offline start still opens the shell. A revoked refresh
|
|
118
|
+
* token ends the session through the normal `sessionExpired` path.
|
|
119
|
+
*/
|
|
120
|
+
restoreSession(session: ChatLeoSession): Promise<UserProfile | null>;
|
|
121
|
+
login(username: string, password: string): Promise<UserProfile | null>;
|
|
122
|
+
loginWithTicket(ticket: string): Promise<UserProfile | null>;
|
|
123
|
+
sendChatMessage(message: ChatMessageSent): string;
|
|
124
|
+
/** Retry a failed message with the same `client_id` (manual retry from the UI). */
|
|
125
|
+
retryMessage(roomId: string, clientId: string): void;
|
|
126
|
+
/** Remove a failed/pending message locally and stop retrying it. */
|
|
127
|
+
discardMessage(roomId: string, clientId: string): void;
|
|
128
|
+
/** Whether the server advertised the `calls` feature (false until `ensureCallsAvailable`). */
|
|
129
|
+
get callsAvailable(): boolean;
|
|
130
|
+
/** `calls="off"` disables the UI and all call requests. */
|
|
131
|
+
setCallsEnabled(enabled: boolean): void;
|
|
132
|
+
/** Fetch discovery once and return whether calls are available. */
|
|
133
|
+
ensureCallsAvailable(): Promise<boolean>;
|
|
134
|
+
/** Start a call in a room, or return the room's active call. */
|
|
135
|
+
startCall(roomId: string, mode?: CallMode): Promise<ActiveCall>;
|
|
136
|
+
/** Join (or accept) a call and return the credentials for the local user. */
|
|
137
|
+
joinCall(callId: string): Promise<CallCredentials>;
|
|
138
|
+
declineCall(callId: string): Promise<void>;
|
|
139
|
+
leaveCall(callId: string): Promise<void>;
|
|
140
|
+
endCall(callId: string): Promise<void>;
|
|
141
|
+
/** Fetch a fresh SFU token for a call (the SFU announces expiry). */
|
|
142
|
+
refreshCallToken(callId: string): Promise<CallCredentials>;
|
|
143
|
+
/**
|
|
144
|
+
* Let a participant of a stage call publish (a speaker). Room admins only; the participant's
|
|
145
|
+
* client then fetches a new token and the SFU applies the role. Resolves with whether the
|
|
146
|
+
* role changed.
|
|
147
|
+
*/
|
|
148
|
+
promoteCallParticipant(callId: string, userId: string): Promise<boolean>;
|
|
149
|
+
/** Return a participant of a stage call to the audience. */
|
|
150
|
+
demoteCallParticipant(callId: string, userId: string): Promise<boolean>;
|
|
151
|
+
/** Lazily created push subscription service (browser + server). */
|
|
152
|
+
get push(): PushService | undefined;
|
|
153
|
+
setPushServiceWorkerPath(path: string): void;
|
|
154
|
+
ensurePushAvailable(): Promise<boolean>;
|
|
155
|
+
pushConfig(): Promise<PushConfig>;
|
|
156
|
+
registerPushSubscription(body: {
|
|
157
|
+
endpoint: string;
|
|
158
|
+
keys: unknown;
|
|
159
|
+
device_id?: string;
|
|
160
|
+
}): Promise<void>;
|
|
161
|
+
unregisterPushSubscription(endpoint: string): Promise<void>;
|
|
162
|
+
pushCheckin(body?: Record<string, unknown>): Promise<void>;
|
|
163
|
+
notificationPreferences(): Promise<PushPreferences>;
|
|
164
|
+
setNotificationPreferences(preferences: PushPreferences): Promise<PushPreferences>;
|
|
165
|
+
setRoomNotificationLevel(roomId: string, level: NotificationLevel): Promise<void>;
|
|
166
|
+
pushState(): Promise<PushState | null>;
|
|
167
|
+
enablePush(): Promise<PushState | null>;
|
|
168
|
+
disablePush(): Promise<PushState | null>;
|
|
169
|
+
registerClient(client: ChatLeoClient): void;
|
|
170
|
+
private loadMessagesForRooms;
|
|
171
|
+
unregisterClient(client: ChatLeoClient): void;
|
|
172
|
+
requestConnection(client: ChatLeoClient, options?: ConnectionOptions): Promise<{
|
|
173
|
+
status: "connected";
|
|
174
|
+
} | {
|
|
175
|
+
status: "waiting";
|
|
176
|
+
} | {
|
|
177
|
+
status: "pending-or-connected";
|
|
178
|
+
} | {
|
|
179
|
+
status: "error";
|
|
180
|
+
}>;
|
|
181
|
+
private performLogin;
|
|
182
|
+
private broadcastLoading;
|
|
183
|
+
private broadcastLoggedIn;
|
|
184
|
+
private broadcastConnectionStatus;
|
|
185
|
+
/**
|
|
186
|
+
* Notifies all registered UI clients that the socket connection state changed,
|
|
187
|
+
* and dispatches a `chatleo:connected` window event so that external handlers
|
|
188
|
+
* (e.g. a host application listening on `window`) can react.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* window.addEventListener('chatleo:connected', (e) => {
|
|
193
|
+
* const { connected } = (e as CustomEvent<{ connected: boolean }>).detail;
|
|
194
|
+
* if (!connected) window.location.reload();
|
|
195
|
+
* });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
private broadcastConnected;
|
|
199
|
+
findDirectMessageRoomIdByUser(userId: string): string | null;
|
|
200
|
+
ensureDirectMessageRoom(userId: string, use_external_id?: boolean): Promise<{
|
|
201
|
+
roomId: string;
|
|
202
|
+
created: boolean;
|
|
203
|
+
}>;
|
|
204
|
+
/**
|
|
205
|
+
* Try to attach to the shared worker for this session.
|
|
206
|
+
* Returns true if the worker was successfully attached, false on fallback.
|
|
207
|
+
*/
|
|
208
|
+
private initSharedWorker;
|
|
209
|
+
private handleWorkerMessage;
|
|
210
|
+
/** Debounce multiple simultaneous resume triggers into one call. */
|
|
211
|
+
private scheduleResume;
|
|
212
|
+
/** Recovery sequence run on tab resume. */
|
|
213
|
+
private onResume;
|
|
214
|
+
/**
|
|
215
|
+
* Refresh the access token if it is expired or within the near-expiry window.
|
|
216
|
+
* Never calls #handleSessionExpired; leaves that exclusively to #performTokenRefresh
|
|
217
|
+
* when the *refresh* endpoint itself returns 401/403.
|
|
218
|
+
*/
|
|
219
|
+
private ensureFreshToken;
|
|
220
|
+
/** Re-fetch missed data after a reconnect: one sync request when supported, legacy otherwise. */
|
|
221
|
+
private runCatchUpSync;
|
|
222
|
+
private broadcastSessionExpired;
|
|
223
|
+
/**
|
|
224
|
+
* Public logout method
|
|
225
|
+
* Clears all tokens and state
|
|
226
|
+
*/
|
|
227
|
+
logout(): void;
|
|
228
|
+
}
|
|
229
|
+
export { SocketIoTransport, WsV2Transport, TransportError } from './transport';
|
|
230
|
+
export type { Transport, TransportCommand, TransportEvent, TransportKind, SendResult } from './transport';
|
|
231
|
+
export type { TransportSetting } from './transport/factory';
|
|
232
|
+
export { ChatStore } from './ChatStore';
|
|
233
|
+
export type { ConnectionStatus } from './ChatStore';
|
|
234
|
+
export { ChatRoom } from './ChatRoom';
|
|
235
|
+
export * from './types/shared';
|
|
236
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAA+B,eAAe,EAA4B,MAAM,gBAAgB,CAAC;AACrH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAK1D,OAAO,EAAqD,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE1G,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,iBAAi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