simplex-chat 0.0.1
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 +661 -0
- package/README.md +40 -0
- package/dist/browser_globals.d.ts +8 -0
- package/dist/browser_globals.js +4 -0
- package/dist/browser_globals.js.map +1 -0
- package/dist/client.d.ts +53 -0
- package/dist/client.js +267 -0
- package/dist/client.js.map +1 -0
- package/dist/command.d.ts +150 -0
- package/dist/command.js +68 -0
- package/dist/command.js.map +1 -0
- package/dist/index-web.d.ts +2 -0
- package/dist/index-web.js +3 -0
- package/dist/index-web.js.map +1 -0
- package/dist/index.bundle.js +537 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +585 -0
- package/dist/queue.d.ts +24 -0
- package/dist/queue.js +72 -0
- package/dist/queue.js.map +1 -0
- package/dist/response.d.ts +379 -0
- package/dist/response.js +2 -0
- package/dist/response.js.map +1 -0
- package/dist/test.html +7 -0
- package/dist/transport.d.ts +51 -0
- package/dist/transport.js +122 -0
- package/dist/transport.js.map +1 -0
- package/dist/websocket.d.ts +8 -0
- package/dist/websocket.js +4 -0
- package/dist/websocket.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { ChatType, ChatItemId, MsgContent, DeleteMode, Profile } from "./command";
|
|
2
|
+
export declare type ChatResponse = CRActiveUser | CRChatStarted | CRChatRunning | CRApiChats | CRApiChat | CRApiParsedMarkdown | CRUserSMPServers | CRNewChatItem | CRChatItemStatusUpdated | CRChatItemUpdated | CRChatItemDeleted | CRMsgIntegrityError | CRCmdOk | CRUserContactLink | CRUserContactLinkUpdated | CRContactRequestRejected | CRUserProfile | CRUserProfileNoChange | CRUserProfileUpdated | CRInvitation | CRSentConfirmation | CRSentInvitation | CRContactUpdated | CRContactDeleted | CRUserContactLinkCreated | CRUserContactLinkDeleted | CRReceivedContactRequest | CRAcceptingContactRequest | CRContactAlreadyExists | CRContactRequestAlreadyAccepted | CRContactConnecting | CRContactConnected | CRContactAnotherClient | CRContactDisconnected | CRContactSubscribed | CRContactSubError | CRContactSubSummary | CRGroupEmpty | CRPendingSubSummary | CRUserContactLinkSubscribed | CRUserContactLinkSubError | CRMessageError | CRChatCmdError | CRChatError;
|
|
3
|
+
declare type ChatResponseTag = "activeUser" | "chatStarted" | "chatRunning" | "apiChats" | "apiChat" | "apiParsedMarkdown" | "userSMPServers" | "newChatItem" | "chatItemStatusUpdated" | "chatItemUpdated" | "chatItemDeleted" | "msgIntegrityError" | "cmdOk" | "userContactLink" | "userContactLinkUpdated" | "userContactLinkCreated" | "userContactLinkDeleted" | "contactRequestRejected" | "userProfile" | "userProfileNoChange" | "userProfileUpdated" | "invitation" | "sentConfirmation" | "sentInvitation" | "contactUpdated" | "contactDeleted" | "receivedContactRequest" | "acceptingContactRequest" | "contactAlreadyExists" | "contactRequestAlreadyAccepted" | "contactConnecting" | "contactConnected" | "contactAnotherClient" | "contactDisconnected" | "contactSubscribed" | "contactSubError" | "contactSubSummary" | "groupEmpty" | "pendingSubSummary" | "userContactLinkSubscribed" | "userContactLinkSubError" | "messageError" | "chatCmdError" | "chatError";
|
|
4
|
+
interface CR {
|
|
5
|
+
type: ChatResponseTag;
|
|
6
|
+
}
|
|
7
|
+
export interface CRActiveUser extends CR {
|
|
8
|
+
type: "activeUser";
|
|
9
|
+
user: User;
|
|
10
|
+
}
|
|
11
|
+
export interface CRChatStarted extends CR {
|
|
12
|
+
type: "chatStarted";
|
|
13
|
+
}
|
|
14
|
+
export interface CRChatRunning extends CR {
|
|
15
|
+
type: "chatRunning";
|
|
16
|
+
}
|
|
17
|
+
export interface CRApiChats extends CR {
|
|
18
|
+
type: "apiChats";
|
|
19
|
+
chats: Chat[];
|
|
20
|
+
}
|
|
21
|
+
export interface CRApiChat extends CR {
|
|
22
|
+
type: "apiChat";
|
|
23
|
+
chat: Chat;
|
|
24
|
+
}
|
|
25
|
+
export interface CRApiParsedMarkdown extends CR {
|
|
26
|
+
type: "apiParsedMarkdown";
|
|
27
|
+
formattedText?: FormattedText[];
|
|
28
|
+
}
|
|
29
|
+
export interface CRUserSMPServers extends CR {
|
|
30
|
+
type: "userSMPServers";
|
|
31
|
+
smpServers: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface CRNewChatItem extends CR {
|
|
34
|
+
type: "newChatItem";
|
|
35
|
+
chatItem: AChatItem;
|
|
36
|
+
}
|
|
37
|
+
export interface CRChatItemStatusUpdated extends CR {
|
|
38
|
+
type: "chatItemStatusUpdated";
|
|
39
|
+
chatItem: AChatItem;
|
|
40
|
+
}
|
|
41
|
+
export interface CRChatItemUpdated extends CR {
|
|
42
|
+
type: "chatItemUpdated";
|
|
43
|
+
chatItem: AChatItem;
|
|
44
|
+
}
|
|
45
|
+
export interface CRChatItemDeleted extends CR {
|
|
46
|
+
type: "chatItemDeleted";
|
|
47
|
+
deletedChatItem: AChatItem;
|
|
48
|
+
toChatItem: AChatItem;
|
|
49
|
+
}
|
|
50
|
+
export interface CRMsgIntegrityError extends CR {
|
|
51
|
+
type: "msgIntegrityError";
|
|
52
|
+
msgError: MsgErrorType;
|
|
53
|
+
}
|
|
54
|
+
export interface CRCmdOk extends CR {
|
|
55
|
+
type: "cmdOk";
|
|
56
|
+
}
|
|
57
|
+
export interface CRUserContactLink extends CR {
|
|
58
|
+
type: "userContactLink";
|
|
59
|
+
connReqContact: string;
|
|
60
|
+
autoAccept: boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface CRUserContactLinkUpdated extends CR {
|
|
63
|
+
type: "userContactLinkUpdated";
|
|
64
|
+
connReqContact: string;
|
|
65
|
+
autoAccept: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface CRContactRequestRejected extends CR {
|
|
68
|
+
type: "contactRequestRejected";
|
|
69
|
+
contactRequest: UserContactRequest;
|
|
70
|
+
}
|
|
71
|
+
export interface CRUserProfile extends CR {
|
|
72
|
+
type: "userProfile";
|
|
73
|
+
profile: Profile;
|
|
74
|
+
}
|
|
75
|
+
export interface CRUserProfileNoChange extends CR {
|
|
76
|
+
type: "userProfileNoChange";
|
|
77
|
+
}
|
|
78
|
+
export interface CRUserProfileUpdated extends CR {
|
|
79
|
+
type: "userProfileUpdated";
|
|
80
|
+
fromProfile: Profile;
|
|
81
|
+
toProfile: Profile;
|
|
82
|
+
}
|
|
83
|
+
export interface CRInvitation extends CR {
|
|
84
|
+
type: "invitation";
|
|
85
|
+
connReqInvitation: string;
|
|
86
|
+
}
|
|
87
|
+
export interface CRSentConfirmation extends CR {
|
|
88
|
+
type: "sentConfirmation";
|
|
89
|
+
}
|
|
90
|
+
export interface CRSentInvitation extends CR {
|
|
91
|
+
type: "sentInvitation";
|
|
92
|
+
}
|
|
93
|
+
export interface CRContactUpdated extends CR {
|
|
94
|
+
type: "contactUpdated";
|
|
95
|
+
fromContact: Contact;
|
|
96
|
+
toContact: Contact;
|
|
97
|
+
}
|
|
98
|
+
export interface CRContactDeleted extends CR {
|
|
99
|
+
type: "contactDeleted";
|
|
100
|
+
contact: Contact;
|
|
101
|
+
}
|
|
102
|
+
export interface CRUserContactLinkCreated extends CR {
|
|
103
|
+
type: "userContactLinkCreated";
|
|
104
|
+
connReqContact: string;
|
|
105
|
+
}
|
|
106
|
+
export interface CRUserContactLinkDeleted extends CR {
|
|
107
|
+
type: "userContactLinkDeleted";
|
|
108
|
+
}
|
|
109
|
+
export interface CRReceivedContactRequest extends CR {
|
|
110
|
+
type: "receivedContactRequest";
|
|
111
|
+
contactRequest: UserContactRequest;
|
|
112
|
+
}
|
|
113
|
+
export interface CRAcceptingContactRequest extends CR {
|
|
114
|
+
type: "acceptingContactRequest";
|
|
115
|
+
contact: Contact;
|
|
116
|
+
}
|
|
117
|
+
export interface CRContactAlreadyExists extends CR {
|
|
118
|
+
type: "contactAlreadyExists";
|
|
119
|
+
contact: Contact;
|
|
120
|
+
}
|
|
121
|
+
export interface CRContactRequestAlreadyAccepted extends CR {
|
|
122
|
+
type: "contactRequestAlreadyAccepted";
|
|
123
|
+
contact: Contact;
|
|
124
|
+
}
|
|
125
|
+
export interface CRContactConnecting extends CR {
|
|
126
|
+
type: "contactConnecting";
|
|
127
|
+
contact: Contact;
|
|
128
|
+
}
|
|
129
|
+
export interface CRContactConnected extends CR {
|
|
130
|
+
type: "contactConnected";
|
|
131
|
+
contact: Contact;
|
|
132
|
+
}
|
|
133
|
+
export interface CRContactAnotherClient extends CR {
|
|
134
|
+
type: "contactAnotherClient";
|
|
135
|
+
contact: Contact;
|
|
136
|
+
}
|
|
137
|
+
export interface CRContactDisconnected extends CR {
|
|
138
|
+
type: "contactDisconnected";
|
|
139
|
+
contact: Contact;
|
|
140
|
+
}
|
|
141
|
+
export interface CRContactSubscribed extends CR {
|
|
142
|
+
type: "contactSubscribed";
|
|
143
|
+
contact: Contact;
|
|
144
|
+
}
|
|
145
|
+
export interface CRContactSubError extends CR {
|
|
146
|
+
type: "contactSubError";
|
|
147
|
+
contact: Contact;
|
|
148
|
+
chatError: ChatError;
|
|
149
|
+
}
|
|
150
|
+
export interface CRContactSubSummary extends CR {
|
|
151
|
+
type: "contactSubSummary";
|
|
152
|
+
contactSubscriptions: ContactSubStatus[];
|
|
153
|
+
}
|
|
154
|
+
export interface CRGroupEmpty extends CR {
|
|
155
|
+
type: "groupEmpty";
|
|
156
|
+
groupInfo: GroupInfo;
|
|
157
|
+
}
|
|
158
|
+
export interface CRPendingSubSummary extends CR {
|
|
159
|
+
type: "pendingSubSummary";
|
|
160
|
+
pendingSubStatus: PendingSubStatus[];
|
|
161
|
+
}
|
|
162
|
+
export interface CRUserContactLinkSubscribed extends CR {
|
|
163
|
+
type: "userContactLinkSubscribed";
|
|
164
|
+
}
|
|
165
|
+
export interface CRUserContactLinkSubError extends CR {
|
|
166
|
+
type: "userContactLinkSubError";
|
|
167
|
+
chatError: ChatError;
|
|
168
|
+
}
|
|
169
|
+
export interface CRMessageError extends CR {
|
|
170
|
+
type: "messageError";
|
|
171
|
+
severity: string;
|
|
172
|
+
errorMessage: string;
|
|
173
|
+
}
|
|
174
|
+
export interface CRChatCmdError extends CR {
|
|
175
|
+
type: "chatCmdError";
|
|
176
|
+
chatError: ChatError;
|
|
177
|
+
}
|
|
178
|
+
export interface CRChatError extends CR {
|
|
179
|
+
type: "chatError";
|
|
180
|
+
chatError: ChatError;
|
|
181
|
+
}
|
|
182
|
+
export interface User {
|
|
183
|
+
userId: number;
|
|
184
|
+
userContactId: number;
|
|
185
|
+
localDisplayName: string;
|
|
186
|
+
profile: Profile;
|
|
187
|
+
activeUser: boolean;
|
|
188
|
+
}
|
|
189
|
+
export interface Chat {
|
|
190
|
+
chatInfo: ChatInfo;
|
|
191
|
+
chatItems: [ChatItem];
|
|
192
|
+
chatStats: ChatStats;
|
|
193
|
+
}
|
|
194
|
+
export declare type ChatInfo = CInfoDirect | CInfoGroup | CInfoContactRequest;
|
|
195
|
+
interface IChatInfo {
|
|
196
|
+
type: ChatType;
|
|
197
|
+
}
|
|
198
|
+
interface CInfoDirect extends IChatInfo {
|
|
199
|
+
type: ChatType.CTDirect;
|
|
200
|
+
contact: Contact;
|
|
201
|
+
}
|
|
202
|
+
interface CInfoGroup extends IChatInfo {
|
|
203
|
+
type: ChatType.CTGroup;
|
|
204
|
+
groupInfo: GroupInfo;
|
|
205
|
+
}
|
|
206
|
+
interface CInfoContactRequest extends IChatInfo {
|
|
207
|
+
type: ChatType.CTContactRequest;
|
|
208
|
+
contactRequest: UserContactRequest;
|
|
209
|
+
}
|
|
210
|
+
export interface Contact {
|
|
211
|
+
contactId: number;
|
|
212
|
+
localDisplayName: string;
|
|
213
|
+
profile: Profile;
|
|
214
|
+
activeConn: Connection;
|
|
215
|
+
viaGroup?: number;
|
|
216
|
+
createdAt: Date;
|
|
217
|
+
}
|
|
218
|
+
export interface GroupInfo {
|
|
219
|
+
groupId: number;
|
|
220
|
+
localDisplayName: string;
|
|
221
|
+
groupProfile: GroupProfile;
|
|
222
|
+
membership: GroupMember;
|
|
223
|
+
createdAt: Date;
|
|
224
|
+
}
|
|
225
|
+
export interface GroupProfile {
|
|
226
|
+
displayName: string;
|
|
227
|
+
fullName: string;
|
|
228
|
+
image?: string;
|
|
229
|
+
}
|
|
230
|
+
export interface GroupMember {
|
|
231
|
+
groupMemberId: number;
|
|
232
|
+
memberId: string;
|
|
233
|
+
localDisplayName: string;
|
|
234
|
+
memberProfile: Profile;
|
|
235
|
+
memberContactId?: number;
|
|
236
|
+
activeConn?: Connection;
|
|
237
|
+
}
|
|
238
|
+
export interface UserContactRequest {
|
|
239
|
+
contactRequestId: number;
|
|
240
|
+
localDisplayName: string;
|
|
241
|
+
profile: Profile;
|
|
242
|
+
createdAt: Date;
|
|
243
|
+
}
|
|
244
|
+
interface Connection {
|
|
245
|
+
connId: number;
|
|
246
|
+
}
|
|
247
|
+
export interface AChatItem {
|
|
248
|
+
chatInfo: ChatInfo;
|
|
249
|
+
chatItem: ChatItem;
|
|
250
|
+
}
|
|
251
|
+
export interface ChatItem {
|
|
252
|
+
chatDir: CIDirection;
|
|
253
|
+
meta: CIMeta;
|
|
254
|
+
content: CIContent;
|
|
255
|
+
formattedText?: FormattedText[];
|
|
256
|
+
quotedItem?: CIQuote;
|
|
257
|
+
}
|
|
258
|
+
export declare type CIDirection = CIDirectSnd | CIDirectRcv | CIGroupSnd | CIGroupRcv;
|
|
259
|
+
interface ICIDirection {
|
|
260
|
+
type: "directSnd" | "directRcv" | "groupSnd" | "groupRcv";
|
|
261
|
+
}
|
|
262
|
+
interface CIDirectSnd extends ICIDirection {
|
|
263
|
+
type: "directSnd";
|
|
264
|
+
}
|
|
265
|
+
interface CIDirectRcv extends ICIDirection {
|
|
266
|
+
type: "directRcv";
|
|
267
|
+
}
|
|
268
|
+
interface CIGroupSnd extends ICIDirection {
|
|
269
|
+
type: "groupSnd";
|
|
270
|
+
}
|
|
271
|
+
interface CIGroupRcv extends ICIDirection {
|
|
272
|
+
type: "groupRcv";
|
|
273
|
+
groupMember: GroupMember;
|
|
274
|
+
}
|
|
275
|
+
export interface CIMeta {
|
|
276
|
+
itemId: ChatItemId;
|
|
277
|
+
itemTs: Date;
|
|
278
|
+
itemText: string;
|
|
279
|
+
itemStatus: CIStatus;
|
|
280
|
+
createdAt: Date;
|
|
281
|
+
itemDeleted: boolean;
|
|
282
|
+
itemEdited: boolean;
|
|
283
|
+
editable: boolean;
|
|
284
|
+
}
|
|
285
|
+
export declare type CIContent = CISndMsgContent | CIRcvMsgContent | CISndDeleted | CIRcvDeleted | CISndFileInvitation | CIRcvFileInvitation;
|
|
286
|
+
interface ICIContent {
|
|
287
|
+
type: "sndMsgContent" | "rcvMsgContent" | "sndDeleted" | "rcvDeleted" | "sndFileInvitation" | "rcvFileInvitation";
|
|
288
|
+
}
|
|
289
|
+
interface CISndMsgContent extends ICIContent {
|
|
290
|
+
type: "sndMsgContent";
|
|
291
|
+
msgContent: MsgContent;
|
|
292
|
+
}
|
|
293
|
+
interface CIRcvMsgContent extends ICIContent {
|
|
294
|
+
type: "rcvMsgContent";
|
|
295
|
+
msgContent: MsgContent;
|
|
296
|
+
}
|
|
297
|
+
interface CISndDeleted extends ICIContent {
|
|
298
|
+
type: "sndDeleted";
|
|
299
|
+
deleteMode: DeleteMode;
|
|
300
|
+
}
|
|
301
|
+
interface CIRcvDeleted extends ICIContent {
|
|
302
|
+
type: "rcvDeleted";
|
|
303
|
+
deleteMode: DeleteMode;
|
|
304
|
+
}
|
|
305
|
+
interface CISndFileInvitation extends ICIContent {
|
|
306
|
+
type: "sndFileInvitation";
|
|
307
|
+
fileId: number;
|
|
308
|
+
filePath: string;
|
|
309
|
+
}
|
|
310
|
+
interface CIRcvFileInvitation extends ICIContent {
|
|
311
|
+
type: "rcvFileInvitation";
|
|
312
|
+
rcvFileTransfer: RcvFileTransfer;
|
|
313
|
+
}
|
|
314
|
+
interface RcvFileTransfer {
|
|
315
|
+
}
|
|
316
|
+
export interface ChatStats {
|
|
317
|
+
unreadCount: number;
|
|
318
|
+
minUnreadItemId: number;
|
|
319
|
+
}
|
|
320
|
+
export interface CIQuote {
|
|
321
|
+
chatDir?: CIDirection;
|
|
322
|
+
itemId?: number;
|
|
323
|
+
sharedMsgId?: string;
|
|
324
|
+
sentAt: Date;
|
|
325
|
+
content: MsgContent;
|
|
326
|
+
formattedText?: FormattedText[];
|
|
327
|
+
}
|
|
328
|
+
export declare type CIStatus = CISndNew | CISndSent | CISndErrorAuth | CISndError | CIRcvNew | CIRcvRead;
|
|
329
|
+
interface ICIStatus {
|
|
330
|
+
type: "sndNew" | "sndSent" | "sndErrorAuth" | "sndError" | "rcvNew" | "rcvRead";
|
|
331
|
+
}
|
|
332
|
+
interface CISndNew extends ICIStatus {
|
|
333
|
+
type: "sndNew";
|
|
334
|
+
}
|
|
335
|
+
interface CISndSent extends ICIStatus {
|
|
336
|
+
type: "sndSent";
|
|
337
|
+
}
|
|
338
|
+
interface CISndErrorAuth extends ICIStatus {
|
|
339
|
+
type: "sndErrorAuth";
|
|
340
|
+
}
|
|
341
|
+
interface CISndError extends ICIStatus {
|
|
342
|
+
type: "sndError";
|
|
343
|
+
agentError: AgentErrorType;
|
|
344
|
+
}
|
|
345
|
+
interface CIRcvNew extends ICIStatus {
|
|
346
|
+
type: "rcvNew";
|
|
347
|
+
}
|
|
348
|
+
interface CIRcvRead extends ICIStatus {
|
|
349
|
+
type: "rcvRead";
|
|
350
|
+
}
|
|
351
|
+
interface FormattedText {
|
|
352
|
+
}
|
|
353
|
+
interface MsgErrorType {
|
|
354
|
+
}
|
|
355
|
+
export declare type ChatError = ChatErrorChat | ChatErrorAgent | ChatErrorStore;
|
|
356
|
+
interface ChatErrorChat {
|
|
357
|
+
type: "error";
|
|
358
|
+
errorType: ChatErrorType;
|
|
359
|
+
}
|
|
360
|
+
interface ChatErrorAgent {
|
|
361
|
+
type: "errorAgent";
|
|
362
|
+
}
|
|
363
|
+
interface ChatErrorStore {
|
|
364
|
+
type: "errorStore";
|
|
365
|
+
}
|
|
366
|
+
declare type ChatErrorType = CENoActiveUser | CEActiveUserExists;
|
|
367
|
+
interface CENoActiveUser {
|
|
368
|
+
type: "noActiveUser";
|
|
369
|
+
}
|
|
370
|
+
interface CEActiveUserExists {
|
|
371
|
+
type: "activeUserExists";
|
|
372
|
+
}
|
|
373
|
+
interface ContactSubStatus {
|
|
374
|
+
}
|
|
375
|
+
interface PendingSubStatus {
|
|
376
|
+
}
|
|
377
|
+
interface AgentErrorType {
|
|
378
|
+
}
|
|
379
|
+
export {};
|
package/dist/response.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":""}
|
package/dist/test.html
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ABQueue, NextIter } from "./queue";
|
|
2
|
+
import { ChatResponse } from "./response";
|
|
3
|
+
export declare class TransportError extends Error {
|
|
4
|
+
}
|
|
5
|
+
export declare abstract class Transport<W, R> {
|
|
6
|
+
readonly queue: ABQueue<R>;
|
|
7
|
+
protected constructor(qSize: number);
|
|
8
|
+
[Symbol.asyncIterator](): Transport<W, R>;
|
|
9
|
+
abstract close(): Promise<void>;
|
|
10
|
+
abstract write(bytes: W): Promise<void>;
|
|
11
|
+
read(): Promise<R>;
|
|
12
|
+
next(): Promise<NextIter<R>>;
|
|
13
|
+
}
|
|
14
|
+
declare type WSData = Uint8Array | string;
|
|
15
|
+
export declare class WSTransport extends Transport<WSData, WSData> {
|
|
16
|
+
private readonly sock;
|
|
17
|
+
readonly timeout: number;
|
|
18
|
+
private constructor();
|
|
19
|
+
static connect(url: string, timeout: number, qSize: number): Promise<WSTransport>;
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
write(data: WSData): Promise<void>;
|
|
22
|
+
readBinary(size: number): Promise<Uint8Array>;
|
|
23
|
+
}
|
|
24
|
+
export interface ChatServer {
|
|
25
|
+
readonly host: string;
|
|
26
|
+
readonly port?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare const localServer: ChatServer;
|
|
29
|
+
export interface ChatSrvRequest {
|
|
30
|
+
corrId: string;
|
|
31
|
+
cmd: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ChatSrvResponse {
|
|
34
|
+
corrId?: string;
|
|
35
|
+
resp: ChatResponse;
|
|
36
|
+
}
|
|
37
|
+
export declare class ChatResponseError extends Error {
|
|
38
|
+
message: string;
|
|
39
|
+
data?: string | undefined;
|
|
40
|
+
constructor(message: string, data?: string | undefined);
|
|
41
|
+
}
|
|
42
|
+
export declare class ChatTransport extends Transport<ChatSrvRequest, ChatSrvResponse | ChatResponseError> {
|
|
43
|
+
private readonly ws;
|
|
44
|
+
readonly timeout: number;
|
|
45
|
+
private constructor();
|
|
46
|
+
static connect(srv: ChatServer | string, timeout: number, qSize: number): Promise<ChatTransport>;
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
write(cmd: ChatSrvRequest): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export declare function noop(): void;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ABQueue } from "./queue";
|
|
2
|
+
export class TransportError extends Error {
|
|
3
|
+
}
|
|
4
|
+
export class Transport {
|
|
5
|
+
constructor(qSize) {
|
|
6
|
+
this.queue = new ABQueue(qSize);
|
|
7
|
+
}
|
|
8
|
+
[Symbol.asyncIterator]() {
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
async read() {
|
|
12
|
+
return this.queue.dequeue();
|
|
13
|
+
}
|
|
14
|
+
async next() {
|
|
15
|
+
return this.queue.next();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class WSTransport extends Transport {
|
|
19
|
+
constructor(sock, timeout, qSize) {
|
|
20
|
+
super(qSize);
|
|
21
|
+
this.sock = sock;
|
|
22
|
+
this.timeout = timeout;
|
|
23
|
+
}
|
|
24
|
+
static connect(url, timeout, qSize) {
|
|
25
|
+
const sock = new WebSocket(url);
|
|
26
|
+
const t = new WSTransport(sock, timeout, qSize);
|
|
27
|
+
sock.onmessage = async ({ data }) => await t.queue.enqueue(data);
|
|
28
|
+
sock.onclose = async () => await t.queue.close();
|
|
29
|
+
sock.onerror = () => sock.close();
|
|
30
|
+
return withTimeout(timeout, () => new Promise((r) => (sock.onopen = () => r(t))));
|
|
31
|
+
}
|
|
32
|
+
close() {
|
|
33
|
+
this.sock.close();
|
|
34
|
+
return Promise.resolve();
|
|
35
|
+
}
|
|
36
|
+
write(data) {
|
|
37
|
+
const buffered = this.sock.bufferedAmount;
|
|
38
|
+
this.sock.send(data);
|
|
39
|
+
return withTimeout(this.timeout, async () => {
|
|
40
|
+
while (this.sock.bufferedAmount > buffered)
|
|
41
|
+
await delay();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async readBinary(size) {
|
|
45
|
+
const data = await this.read();
|
|
46
|
+
if (typeof data == "string")
|
|
47
|
+
throw new TransportError("invalid text block: expected binary");
|
|
48
|
+
if (data.byteLength !== size)
|
|
49
|
+
throw new TransportError("invalid block size");
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function withTimeout(ms, action) {
|
|
54
|
+
return Promise.race([
|
|
55
|
+
action(),
|
|
56
|
+
(async () => {
|
|
57
|
+
await delay(ms);
|
|
58
|
+
throw new Error("timeout");
|
|
59
|
+
})(),
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
export const localServer = {
|
|
63
|
+
host: "localhost",
|
|
64
|
+
port: "5225",
|
|
65
|
+
};
|
|
66
|
+
export class ChatResponseError extends Error {
|
|
67
|
+
constructor(message, data) {
|
|
68
|
+
super(message);
|
|
69
|
+
this.message = message;
|
|
70
|
+
this.data = data;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export class ChatTransport extends Transport {
|
|
74
|
+
constructor(ws, timeout, qSize) {
|
|
75
|
+
super(qSize);
|
|
76
|
+
this.ws = ws;
|
|
77
|
+
this.timeout = timeout;
|
|
78
|
+
}
|
|
79
|
+
static async connect(srv, timeout, qSize) {
|
|
80
|
+
const uri = typeof srv == "string" ? srv : `ws://${srv.host}:${srv.port || "5225"}`;
|
|
81
|
+
const ws = await WSTransport.connect(uri, timeout, qSize);
|
|
82
|
+
const c = new ChatTransport(ws, timeout, qSize);
|
|
83
|
+
processWSQueue(c, ws).then(noop, noop);
|
|
84
|
+
return c;
|
|
85
|
+
}
|
|
86
|
+
async close() {
|
|
87
|
+
await this.ws.close();
|
|
88
|
+
}
|
|
89
|
+
async write(cmd) {
|
|
90
|
+
return this.ws.write(JSON.stringify(cmd));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function noop() { }
|
|
94
|
+
async function processWSQueue(c, ws) {
|
|
95
|
+
var _a;
|
|
96
|
+
for await (const data of ws) {
|
|
97
|
+
const str = (data instanceof Promise ? await data : data);
|
|
98
|
+
if (typeof str != "string") {
|
|
99
|
+
await c.queue.enqueue(new ChatResponseError("websocket data is not a string"));
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
let resp;
|
|
103
|
+
try {
|
|
104
|
+
const json = JSON.parse(str);
|
|
105
|
+
if (typeof ((_a = json === null || json === void 0 ? void 0 : json.resp) === null || _a === void 0 ? void 0 : _a.type) == "string") {
|
|
106
|
+
resp = json;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
resp = new ChatResponseError("invalid response format", str);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
resp = new ChatResponseError(err.message, str);
|
|
114
|
+
}
|
|
115
|
+
await c.queue.enqueue(resp);
|
|
116
|
+
}
|
|
117
|
+
await c.queue.close();
|
|
118
|
+
}
|
|
119
|
+
function delay(ms) {
|
|
120
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../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version":3,"file":"websocket.js","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":";AAAA,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAqB,CAAA;AAEvD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,EAAC,KAAK,EAAE,EAAE,EAAC,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "simplex-chat",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "SimpleX Chat client",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "npm run prettier:check && npm run eslint && jest --coverage",
|
|
12
|
+
"build": "npm run prettier:write && npm run eslint && tsc && ./copy && npm run bundle",
|
|
13
|
+
"bundle": "rollup dist/index-web.js --file dist/index.bundle.js --format umd --name simplex",
|
|
14
|
+
"eslint": "eslint --ext .ts ./src/**/*.ts",
|
|
15
|
+
"prettier:write": "prettier --write './**/*.{json,yaml,js,ts}'",
|
|
16
|
+
"prettier:check": "prettier --list-different './**/*.{json,yaml,js,ts}'"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/simplex-chat/simplex-chat.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"messenger",
|
|
24
|
+
"chat",
|
|
25
|
+
"privacy",
|
|
26
|
+
"security"
|
|
27
|
+
],
|
|
28
|
+
"author": "SimpleX Chat",
|
|
29
|
+
"license": "AGPL-3.0",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/simplex-chat/simplex-chat/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/simplex-chat/simplex-chat/packages/simplex-chat-client/typescript#readme",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"isomorphic-ws": "^4.0.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/jest": "^27.5.1",
|
|
39
|
+
"@types/node": "^17.0.24",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
|
41
|
+
"@typescript-eslint/parser": "^5.23.0",
|
|
42
|
+
"eslint": "^8.15.0",
|
|
43
|
+
"eslint-config-prettier": "^8.5.0",
|
|
44
|
+
"husky": "^7.0.4",
|
|
45
|
+
"jest": "^28.1.0",
|
|
46
|
+
"lint-staged": "^12.3.8",
|
|
47
|
+
"prettier": "^2.6.2",
|
|
48
|
+
"rollup": "^2.72.1",
|
|
49
|
+
"ts-jest": "^28.0.2",
|
|
50
|
+
"typescript": "^4.6.3"
|
|
51
|
+
},
|
|
52
|
+
"husky": {
|
|
53
|
+
"hooks": {
|
|
54
|
+
"pre-commit": "lint-staged"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"lint-staged": {
|
|
58
|
+
"**/*": "prettier --write --ignore-unknown"
|
|
59
|
+
}
|
|
60
|
+
}
|