simplex-chat 0.0.1 → 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 +1 -18
- package/dist/client.d.ts +17 -10
- package/dist/client.js +63 -94
- package/dist/client.js.map +1 -1
- package/dist/command.d.ts +6 -3
- package/dist/command.js +16 -10
- package/dist/command.js.map +1 -1
- package/dist/index-web.d.ts +0 -1
- package/dist/index-web.js +5 -2
- package/dist/index-web.js.map +1 -1
- package/dist/index.bundle.js +9 -535
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/queue.js +7 -2
- package/dist/queue.js.map +1 -1
- package/dist/response.d.ts +19 -5
- package/dist/response.js +20 -1
- package/dist/response.js.map +1 -1
- package/dist/transport.js +18 -9
- package/dist/transport.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -6,24 +6,7 @@
|
|
|
6
6
|
npm i simplex-chat
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
const ChatClient = require("simplex-chat").ChatClient
|
|
11
|
-
const chat = await ChatClient.create("ws://localhost:5225")
|
|
12
|
-
await processMessages(chat)
|
|
13
|
-
const user = await chat.apiGetActiveUser()
|
|
14
|
-
|
|
15
|
-
async function processMessages(chat) {
|
|
16
|
-
for await (const m of chat.msgQ) {
|
|
17
|
-
const msg = m instanceof Promise ? await m : m
|
|
18
|
-
switch (msg.type) {
|
|
19
|
-
case "newChatItem": // do something
|
|
20
|
-
return
|
|
21
|
-
default:
|
|
22
|
-
console.log(msg)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
```
|
|
9
|
+
See example of chat bot in [squaring-bot.js](./examples/squaring-bot.js)
|
|
27
10
|
|
|
28
11
|
## Documentation
|
|
29
12
|
|
package/dist/client.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { ChatServer, ChatResponseError } from "./transport";
|
|
|
3
3
|
import { ChatCommand, ChatType } from "./command";
|
|
4
4
|
import { ChatResponse } from "./response";
|
|
5
5
|
import * as CC from "./command";
|
|
6
|
-
import * as
|
|
6
|
+
import * as CR from "./response";
|
|
7
7
|
export interface ChatClientConfig {
|
|
8
8
|
readonly qSize: number;
|
|
9
9
|
readonly tcpTimeout: number;
|
|
10
10
|
}
|
|
11
11
|
export interface Request {
|
|
12
12
|
readonly resolve: (resp: ChatResponse) => void;
|
|
13
|
-
readonly reject: (err?: ChatResponseError |
|
|
13
|
+
readonly reject: (err?: ChatResponseError | CR.CRChatCmdError) => void;
|
|
14
14
|
}
|
|
15
15
|
export declare class ChatCommandError extends Error {
|
|
16
16
|
message: string;
|
|
@@ -36,18 +36,25 @@ export declare class ChatClient {
|
|
|
36
36
|
sendChatCmdStr(cmd: string): Promise<ChatResponse>;
|
|
37
37
|
sendChatCommand(command: ChatCommand): Promise<ChatResponse>;
|
|
38
38
|
disconnect(): Promise<void>;
|
|
39
|
-
apiGetActiveUser(): Promise<
|
|
40
|
-
apiCreateActiveUser(profile: CC.Profile): Promise<
|
|
39
|
+
apiGetActiveUser(): Promise<CR.User | undefined>;
|
|
40
|
+
apiCreateActiveUser(profile: CC.Profile): Promise<CR.User>;
|
|
41
41
|
apiStartChat(): Promise<void>;
|
|
42
|
-
apiGetChats(): Promise<
|
|
43
|
-
apiGetChat(chatType: ChatType, chatId: number, pagination?: CC.ChatPagination): Promise<
|
|
44
|
-
apiSendMessage(chatType: ChatType, chatId: number, message: CC.ComposedMessage): Promise<
|
|
45
|
-
apiSendTextMessage(chatType: ChatType, chatId: number, text: string): Promise<
|
|
46
|
-
apiUpdateChatItem(chatType: ChatType, chatId: number, chatItemId: CC.ChatItemId, msgContent: CC.MsgContent): Promise<
|
|
47
|
-
apiDeleteChatItem(chatType: ChatType, chatId: number, chatItemId: number, deleteMode: CC.DeleteMode): Promise<
|
|
42
|
+
apiGetChats(): Promise<CR.Chat[]>;
|
|
43
|
+
apiGetChat(chatType: ChatType, chatId: number, pagination?: CC.ChatPagination): Promise<CR.Chat>;
|
|
44
|
+
apiSendMessage(chatType: ChatType, chatId: number, message: CC.ComposedMessage): Promise<CR.AChatItem>;
|
|
45
|
+
apiSendTextMessage(chatType: ChatType, chatId: number, text: string): Promise<CR.AChatItem>;
|
|
46
|
+
apiUpdateChatItem(chatType: ChatType, chatId: number, chatItemId: CC.ChatItemId, msgContent: CC.MsgContent): Promise<CR.ChatItem>;
|
|
47
|
+
apiDeleteChatItem(chatType: ChatType, chatId: number, chatItemId: number, deleteMode: CC.DeleteMode): Promise<CR.ChatItem>;
|
|
48
48
|
apiCreateLink(): Promise<string>;
|
|
49
49
|
apiConnect(connReq: string): Promise<ConnReqType>;
|
|
50
50
|
apiDeleteChat(chatType: ChatType, chatId: number): Promise<void>;
|
|
51
51
|
apiUpdateProfile(profile: CC.Profile): Promise<CC.Profile | undefined>;
|
|
52
|
+
apiCreateUserAddress(): Promise<string>;
|
|
53
|
+
apiDeleteUserAddress(): Promise<void>;
|
|
54
|
+
apiGetUserAddress(): Promise<string | undefined>;
|
|
55
|
+
apiAcceptContactRequest(contactReqId: number): Promise<CR.Contact>;
|
|
56
|
+
apiRejectContactRequest(contactReqId: number): Promise<void>;
|
|
57
|
+
apiChatRead(chatType: ChatType, chatId: number, itemRange?: CC.ItemRange): Promise<void>;
|
|
58
|
+
private okChatCommand;
|
|
52
59
|
get connected(): boolean;
|
|
53
60
|
}
|
package/dist/client.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatClient = exports.ConnReqType = exports.ChatCommandError = void 0;
|
|
4
|
+
const queue_1 = require("./queue");
|
|
5
|
+
const transport_1 = require("./transport");
|
|
6
|
+
const CC = require("./command");
|
|
7
|
+
class ChatCommandError extends Error {
|
|
5
8
|
constructor(message, response) {
|
|
6
9
|
super(message);
|
|
7
10
|
this.message = message;
|
|
8
11
|
this.response = response;
|
|
9
12
|
}
|
|
10
13
|
}
|
|
11
|
-
|
|
14
|
+
exports.ChatCommandError = ChatCommandError;
|
|
15
|
+
var ConnReqType;
|
|
12
16
|
(function (ConnReqType) {
|
|
13
17
|
ConnReqType["Invitation"] = "invitation";
|
|
14
18
|
ConnReqType["Contact"] = "contact";
|
|
15
|
-
})(ConnReqType || (ConnReqType = {}));
|
|
16
|
-
|
|
19
|
+
})(ConnReqType = exports.ConnReqType || (exports.ConnReqType = {}));
|
|
20
|
+
class ChatClient {
|
|
17
21
|
constructor(server, config, msgQ, client, transport) {
|
|
18
22
|
this.server = server;
|
|
19
23
|
this.config = config;
|
|
@@ -24,16 +28,16 @@ export class ChatClient {
|
|
|
24
28
|
this.clientCorrId = 0;
|
|
25
29
|
this.sentCommands = new Map();
|
|
26
30
|
}
|
|
27
|
-
static async create(server = localServer, cfg = ChatClient.defaultConfig) {
|
|
28
|
-
const transport = await ChatTransport.connect(server, cfg.tcpTimeout, cfg.qSize);
|
|
29
|
-
const msgQ = new ABQueue(cfg.qSize);
|
|
30
|
-
const client = runClient().then(noop, noop);
|
|
31
|
+
static async create(server = transport_1.localServer, cfg = ChatClient.defaultConfig) {
|
|
32
|
+
const transport = await transport_1.ChatTransport.connect(server, cfg.tcpTimeout, cfg.qSize);
|
|
33
|
+
const msgQ = new queue_1.ABQueue(cfg.qSize);
|
|
34
|
+
const client = runClient().then(transport_1.noop, transport_1.noop);
|
|
31
35
|
const c = new ChatClient(server, cfg, msgQ, client, transport);
|
|
32
36
|
return c;
|
|
33
37
|
async function runClient() {
|
|
34
38
|
for await (const t of transport) {
|
|
35
39
|
const apiResp = (t instanceof Promise ? await t : t);
|
|
36
|
-
if (apiResp instanceof ChatResponseError) {
|
|
40
|
+
if (apiResp instanceof transport_1.ChatResponseError) {
|
|
37
41
|
console.log("chat response error: ", apiResp);
|
|
38
42
|
}
|
|
39
43
|
else {
|
|
@@ -42,12 +46,7 @@ export class ChatClient {
|
|
|
42
46
|
const req = c.sentCommands.get(corrId);
|
|
43
47
|
if (req) {
|
|
44
48
|
c.sentCommands.delete(corrId);
|
|
45
|
-
|
|
46
|
-
req.reject(resp);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
req.resolve(resp);
|
|
50
|
-
}
|
|
49
|
+
req.resolve(resp);
|
|
51
50
|
}
|
|
52
51
|
else {
|
|
53
52
|
// TODO send error to errQ?
|
|
@@ -65,7 +64,7 @@ export class ChatClient {
|
|
|
65
64
|
sendChatCmdStr(cmd) {
|
|
66
65
|
const corrId = `${++this.clientCorrId}`;
|
|
67
66
|
const t = { corrId, cmd };
|
|
68
|
-
this.transport.write(t).then(noop, noop);
|
|
67
|
+
this.transport.write(t).then(transport_1.noop, transport_1.noop);
|
|
69
68
|
return new Promise((resolve, reject) => this.sentCommands.set(corrId, { resolve, reject }));
|
|
70
69
|
}
|
|
71
70
|
sendChatCommand(command) {
|
|
@@ -181,85 +180,55 @@ export class ChatClient {
|
|
|
181
180
|
// if case let .apiParsedMarkdown(formattedText) = r { return formattedText }
|
|
182
181
|
// throw r
|
|
183
182
|
// }
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
// func rejectContactRequest(_ contactRequest: UserContactRequest) async {
|
|
229
|
-
// do {
|
|
230
|
-
// try await apiRejectContactRequest(contactReqId: contactRequest.apiId)
|
|
231
|
-
// DispatchQueue.main.async { ChatModel.shared.removeChat(contactRequest.id) }
|
|
232
|
-
// } catch let error {
|
|
233
|
-
// logger.error("rejectContactRequest: \(error.localizedDescription)")
|
|
234
|
-
// }
|
|
235
|
-
// }
|
|
236
|
-
// func markChatRead(_ chat: Chat) async {
|
|
237
|
-
// do {
|
|
238
|
-
// let minItemId = chat.chatStats.minUnreadItemId
|
|
239
|
-
// let itemRange = (minItemId, chat.chatItems.last?.id ?? minItemId)
|
|
240
|
-
// let cInfo = chat.chatInfo
|
|
241
|
-
// try await apiChatRead(type: cInfo.chatType, id: cInfo.apiId, itemRange: itemRange)
|
|
242
|
-
// DispatchQueue.main.async { ChatModel.shared.markChatItemsRead(cInfo) }
|
|
243
|
-
// } catch {
|
|
244
|
-
// logger.error("markChatRead apiChatRead error: \(error.localizedDescription)")
|
|
245
|
-
// }
|
|
246
|
-
// }
|
|
247
|
-
// func markChatItemRead(_ cInfo: ChatInfo, _ cItem: ChatItem) async {
|
|
248
|
-
// do {
|
|
249
|
-
// try await apiChatRead(type: cInfo.chatType, id: cInfo.apiId, itemRange: (cItem.id, cItem.id))
|
|
250
|
-
// DispatchQueue.main.async { ChatModel.shared.markChatItemRead(cInfo, cItem) }
|
|
251
|
-
// } catch {
|
|
252
|
-
// logger.error("markChatItemRead apiChatRead error: \(error.localizedDescription)")
|
|
253
|
-
// }
|
|
254
|
-
// }
|
|
255
|
-
// private async okChatCommand(command: ChatCommand): Promise<void> {
|
|
256
|
-
// const resp = await this.sendChatCommand(command)
|
|
257
|
-
// if (resp.type !== "cmdOk") throw new ChatCommandError("unexpected response", resp)
|
|
258
|
-
// }
|
|
183
|
+
async apiCreateUserAddress() {
|
|
184
|
+
const r = await this.sendChatCommand({ type: "createMyAddress" });
|
|
185
|
+
if (r.type === "userContactLinkCreated")
|
|
186
|
+
return r.connReqContact;
|
|
187
|
+
throw new ChatCommandError("error creating user address", r);
|
|
188
|
+
}
|
|
189
|
+
async apiDeleteUserAddress() {
|
|
190
|
+
const r = await this.sendChatCommand({ type: "deleteMyAddress" });
|
|
191
|
+
if (r.type === "userContactLinkDeleted")
|
|
192
|
+
return;
|
|
193
|
+
throw new ChatCommandError("error deleting user address", r);
|
|
194
|
+
}
|
|
195
|
+
async apiGetUserAddress() {
|
|
196
|
+
const r = await this.sendChatCommand({ type: "showMyAddress" });
|
|
197
|
+
switch (r.type) {
|
|
198
|
+
case "userContactLink":
|
|
199
|
+
return r.connReqContact;
|
|
200
|
+
default:
|
|
201
|
+
if (r.type === "chatCmdError" && r.chatError.type === "errorStore" && r.chatError.storeError.type === "userContactLinkNotFound") {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
throw new ChatCommandError("error loading user address", r);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async apiAcceptContactRequest(contactReqId) {
|
|
208
|
+
const r = await this.sendChatCommand({ type: "apiAcceptContact", contactReqId });
|
|
209
|
+
if (r.type === "acceptingContactRequest")
|
|
210
|
+
return r.contact;
|
|
211
|
+
throw new ChatCommandError("error accepting contact request", r);
|
|
212
|
+
}
|
|
213
|
+
async apiRejectContactRequest(contactReqId) {
|
|
214
|
+
const r = await this.sendChatCommand({ type: "apiRejectContact", contactReqId });
|
|
215
|
+
if (r.type === "contactRequestRejected")
|
|
216
|
+
return;
|
|
217
|
+
throw new ChatCommandError("error rejecting contact request", r);
|
|
218
|
+
}
|
|
219
|
+
apiChatRead(chatType, chatId, itemRange) {
|
|
220
|
+
return this.okChatCommand({ type: "apiChatRead", chatType, chatId, itemRange });
|
|
221
|
+
}
|
|
222
|
+
async okChatCommand(command) {
|
|
223
|
+
const r = await this.sendChatCommand(command);
|
|
224
|
+
if (r.type !== "cmdOk")
|
|
225
|
+
throw new ChatCommandError(`${command.type} command error`, r);
|
|
226
|
+
}
|
|
259
227
|
get connected() {
|
|
260
228
|
return this._connected;
|
|
261
229
|
}
|
|
262
230
|
}
|
|
231
|
+
exports.ChatClient = ChatClient;
|
|
263
232
|
ChatClient.defaultConfig = {
|
|
264
233
|
qSize: 16,
|
|
265
234
|
tcpTimeout: 4000,
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAC/B,2CAA4H;AAG5H,gCAA+B;AAa/B,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAmB,OAAe,EAAS,QAAsB;QAC/D,KAAK,CAAC,OAAO,CAAC,CAAA;QADG,YAAO,GAAP,OAAO,CAAQ;QAAS,aAAQ,GAAR,QAAQ,CAAc;IAEjE,CAAC;CACF;AAJD,4CAIC;AAED,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,kCAAmB,CAAA;AACrB,CAAC,EAHW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAGtB;AAED,MAAa,UAAU;IAUrB,YACW,MAA2B,EAC3B,MAAwB,EACxB,IAA2B,EAC3B,MAAqB,EACb,SAAwB;QAJhC,WAAM,GAAN,MAAM,CAAqB;QAC3B,WAAM,GAAN,MAAM,CAAkB;QACxB,SAAI,GAAJ,IAAI,CAAuB;QAC3B,WAAM,GAAN,MAAM,CAAe;QACb,cAAS,GAAT,SAAS,CAAe;QAdnC,eAAU,GAAG,IAAI,CAAA;QACjB,iBAAY,GAAG,CAAC,CAAA;QACP,iBAAY,GAAG,IAAI,GAAG,EAAmB,CAAA;IAavD,CAAC;IAEJ,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAA8B,uBAAW,EAAE,MAAwB,UAAU,CAAC,aAAa;QAC7G,MAAM,SAA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,GAAG,OAAO,CAAC,IAAI,gBAAgB,EAAE,CAAC,CAAC,CAAA;IACxF,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;;AAnOH,gCAoOC;AA/NQ,wBAAa,GAAqB;IACvC,KAAK,EAAE,EAAE;IACT,UAAU,EAAE,IAAI;CACjB,CAAA"}
|
package/dist/command.d.ts
CHANGED
|
@@ -55,6 +55,9 @@ export interface APIChatRead extends IChatCommand {
|
|
|
55
55
|
type: "apiChatRead";
|
|
56
56
|
chatType: ChatType;
|
|
57
57
|
chatId: number;
|
|
58
|
+
itemRange?: ItemRange;
|
|
59
|
+
}
|
|
60
|
+
export interface ItemRange {
|
|
58
61
|
fromItem: ChatItemId;
|
|
59
62
|
toItem: ChatItemId;
|
|
60
63
|
}
|
|
@@ -115,9 +118,9 @@ export interface Profile {
|
|
|
115
118
|
image?: string;
|
|
116
119
|
}
|
|
117
120
|
export declare enum ChatType {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
Direct = "@",
|
|
122
|
+
Group = "#",
|
|
123
|
+
ContactRequest = "<@"
|
|
121
124
|
}
|
|
122
125
|
export declare type ChatPagination = {
|
|
123
126
|
count: number;
|
package/dist/command.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cmdString = exports.DeleteMode = exports.ChatType = void 0;
|
|
4
|
+
var ChatType;
|
|
2
5
|
(function (ChatType) {
|
|
3
|
-
ChatType["
|
|
4
|
-
ChatType["
|
|
5
|
-
ChatType["
|
|
6
|
-
})(ChatType || (ChatType = {}));
|
|
7
|
-
|
|
6
|
+
ChatType["Direct"] = "@";
|
|
7
|
+
ChatType["Group"] = "#";
|
|
8
|
+
ChatType["ContactRequest"] = "<@";
|
|
9
|
+
})(ChatType = exports.ChatType || (exports.ChatType = {}));
|
|
10
|
+
var DeleteMode;
|
|
8
11
|
(function (DeleteMode) {
|
|
9
12
|
DeleteMode["Broadcast"] = "broadcast";
|
|
10
13
|
DeleteMode["Internal"] = "internal";
|
|
11
|
-
})(DeleteMode || (DeleteMode = {}));
|
|
12
|
-
|
|
14
|
+
})(DeleteMode = exports.DeleteMode || (exports.DeleteMode = {}));
|
|
15
|
+
function cmdString(cmd) {
|
|
13
16
|
switch (cmd.type) {
|
|
14
17
|
case "showActiveUser":
|
|
15
18
|
return "/u";
|
|
@@ -29,8 +32,10 @@ export function cmdString(cmd) {
|
|
|
29
32
|
return `/_update item ${cmd.chatType}${cmd.chatId} ${cmd.chatItemId} json ${JSON.stringify(cmd.msgContent)}`;
|
|
30
33
|
case "apiDeleteChatItem":
|
|
31
34
|
return `/_delete item ${cmd.chatType}${cmd.chatId} ${cmd.chatItemId} ${cmd.deleteMode}`;
|
|
32
|
-
case "apiChatRead":
|
|
33
|
-
|
|
35
|
+
case "apiChatRead": {
|
|
36
|
+
const itemRange = cmd.itemRange ? ` from=${cmd.itemRange.fromItem} to=${cmd.itemRange.toItem}` : "";
|
|
37
|
+
return `/_read chat ${cmd.chatType}${cmd.chatId}${itemRange}`;
|
|
38
|
+
}
|
|
34
39
|
case "apiDeleteChat":
|
|
35
40
|
return `/_delete ${cmd.chatType}${cmd.chatId}`;
|
|
36
41
|
case "apiAcceptContact":
|
|
@@ -61,6 +66,7 @@ export function cmdString(cmd) {
|
|
|
61
66
|
return `/auto_accept ${cmd.enable ? "on" : "off"}`;
|
|
62
67
|
}
|
|
63
68
|
}
|
|
69
|
+
exports.cmdString = cmdString;
|
|
64
70
|
function paginationStr(cp) {
|
|
65
71
|
const base = "after" in cp ? ` after=${cp.after}` : "before" in cp ? ` before=${cp.before}` : "";
|
|
66
72
|
return base + ` count=${cp.count}`;
|
package/dist/command.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"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;QACxB,KAAK,mBAAmB;YACtB,OAAO,gBAAgB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAA;KACrD;AACH,CAAC;AArDD,8BAqDC;AAED,SAAS,aAAa,CAAC,EAAkB;IACvC,MAAM,IAAI,GAAG,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAChG,OAAO,IAAI,GAAG,UAAU,EAAE,CAAC,KAAK,EAAE,CAAA;AACpC,CAAC"}
|
package/dist/index-web.d.ts
CHANGED
package/dist/index-web.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatClient = void 0;
|
|
4
|
+
var client_1 = require("./client");
|
|
5
|
+
Object.defineProperty(exports, "ChatClient", { enumerable: true, get: function () { return client_1.ChatClient; } });
|
|
3
6
|
//# sourceMappingURL=index-web.js.map
|
package/dist/index-web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-web.js","sourceRoot":"","sources":["../src/index-web.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index-web.js","sourceRoot":"","sources":["../src/index-web.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AAA3B,oGAAA,UAAU,OAAA"}
|
package/dist/index.bundle.js
CHANGED
|
@@ -1,537 +1,11 @@
|
|
|
1
|
-
(function (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this.promises = [];
|
|
11
|
-
}
|
|
12
|
-
signal() {
|
|
13
|
-
this.permits += 1;
|
|
14
|
-
if (this.promises.length > 0)
|
|
15
|
-
this.promises.pop()();
|
|
16
|
-
}
|
|
17
|
-
async wait() {
|
|
18
|
-
if (this.permits === 0 || this.promises.length > 0) {
|
|
19
|
-
await new Promise((r) => this.promises.unshift(r));
|
|
20
|
-
}
|
|
21
|
-
this.permits -= 1;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const queueClosed = Symbol();
|
|
25
|
-
class ABQueueError extends Error {
|
|
26
|
-
}
|
|
27
|
-
class ABQueue {
|
|
28
|
-
constructor(maxSize) {
|
|
29
|
-
this.maxSize = maxSize;
|
|
30
|
-
this.queue = [];
|
|
31
|
-
this.enqClosed = false;
|
|
32
|
-
this.deqClosed = false;
|
|
33
|
-
this.enq = new Sem(0);
|
|
34
|
-
this.deq = new Sem(maxSize);
|
|
35
|
-
}
|
|
36
|
-
[Symbol.asyncIterator]() {
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
enqueue(x) {
|
|
40
|
-
return this._enqueue(x);
|
|
41
|
-
}
|
|
42
|
-
async _enqueue(x) {
|
|
43
|
-
if (this.enqClosed)
|
|
44
|
-
throw new ABQueueError("enqueue: queue closed");
|
|
45
|
-
await this.deq.wait();
|
|
46
|
-
this.queue.push(x);
|
|
47
|
-
this.enq.signal();
|
|
48
|
-
}
|
|
49
|
-
async dequeue() {
|
|
50
|
-
if (this.deqClosed)
|
|
51
|
-
throw new ABQueueError("dequeue: queue closed");
|
|
52
|
-
this.deq.signal();
|
|
53
|
-
await this.enq.wait();
|
|
54
|
-
const x = this.queue.shift();
|
|
55
|
-
if (x === queueClosed) {
|
|
56
|
-
this.deqClosed = true;
|
|
57
|
-
throw new ABQueueError("dequeue: queue closed");
|
|
58
|
-
}
|
|
59
|
-
return x;
|
|
60
|
-
}
|
|
61
|
-
async close() {
|
|
62
|
-
await this._enqueue(queueClosed);
|
|
63
|
-
this.enqClosed = true;
|
|
64
|
-
}
|
|
65
|
-
async next() {
|
|
66
|
-
if (this.deqClosed)
|
|
67
|
-
return { done: true };
|
|
68
|
-
try {
|
|
69
|
-
return { value: await this.dequeue() };
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
if (e instanceof ABQueueError)
|
|
73
|
-
return { done: true };
|
|
74
|
-
throw e;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
class TransportError extends Error {
|
|
80
|
-
}
|
|
81
|
-
class Transport {
|
|
82
|
-
constructor(qSize) {
|
|
83
|
-
this.queue = new ABQueue(qSize);
|
|
84
|
-
}
|
|
85
|
-
[Symbol.asyncIterator]() {
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
async read() {
|
|
89
|
-
return this.queue.dequeue();
|
|
90
|
-
}
|
|
91
|
-
async next() {
|
|
92
|
-
return this.queue.next();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
class WSTransport extends Transport {
|
|
96
|
-
constructor(sock, timeout, qSize) {
|
|
97
|
-
super(qSize);
|
|
98
|
-
this.sock = sock;
|
|
99
|
-
this.timeout = timeout;
|
|
100
|
-
}
|
|
101
|
-
static connect(url, timeout, qSize) {
|
|
102
|
-
const sock = new WebSocket(url);
|
|
103
|
-
const t = new WSTransport(sock, timeout, qSize);
|
|
104
|
-
sock.onmessage = async ({ data }) => await t.queue.enqueue(data);
|
|
105
|
-
sock.onclose = async () => await t.queue.close();
|
|
106
|
-
sock.onerror = () => sock.close();
|
|
107
|
-
return withTimeout(timeout, () => new Promise((r) => (sock.onopen = () => r(t))));
|
|
108
|
-
}
|
|
109
|
-
close() {
|
|
110
|
-
this.sock.close();
|
|
111
|
-
return Promise.resolve();
|
|
112
|
-
}
|
|
113
|
-
write(data) {
|
|
114
|
-
const buffered = this.sock.bufferedAmount;
|
|
115
|
-
this.sock.send(data);
|
|
116
|
-
return withTimeout(this.timeout, async () => {
|
|
117
|
-
while (this.sock.bufferedAmount > buffered)
|
|
118
|
-
await delay();
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
async readBinary(size) {
|
|
122
|
-
const data = await this.read();
|
|
123
|
-
if (typeof data == "string")
|
|
124
|
-
throw new TransportError("invalid text block: expected binary");
|
|
125
|
-
if (data.byteLength !== size)
|
|
126
|
-
throw new TransportError("invalid block size");
|
|
127
|
-
return data;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function withTimeout(ms, action) {
|
|
131
|
-
return Promise.race([
|
|
132
|
-
action(),
|
|
133
|
-
(async () => {
|
|
134
|
-
await delay(ms);
|
|
135
|
-
throw new Error("timeout");
|
|
136
|
-
})(),
|
|
137
|
-
]);
|
|
138
|
-
}
|
|
139
|
-
const localServer = {
|
|
140
|
-
host: "localhost",
|
|
141
|
-
port: "5225",
|
|
142
|
-
};
|
|
143
|
-
class ChatResponseError extends Error {
|
|
144
|
-
constructor(message, data) {
|
|
145
|
-
super(message);
|
|
146
|
-
this.message = message;
|
|
147
|
-
this.data = data;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
class ChatTransport extends Transport {
|
|
151
|
-
constructor(ws, timeout, qSize) {
|
|
152
|
-
super(qSize);
|
|
153
|
-
this.ws = ws;
|
|
154
|
-
this.timeout = timeout;
|
|
155
|
-
}
|
|
156
|
-
static async connect(srv, timeout, qSize) {
|
|
157
|
-
const uri = typeof srv == "string" ? srv : `ws://${srv.host}:${srv.port || "5225"}`;
|
|
158
|
-
const ws = await WSTransport.connect(uri, timeout, qSize);
|
|
159
|
-
const c = new ChatTransport(ws, timeout, qSize);
|
|
160
|
-
processWSQueue(c, ws).then(noop, noop);
|
|
161
|
-
return c;
|
|
162
|
-
}
|
|
163
|
-
async close() {
|
|
164
|
-
await this.ws.close();
|
|
165
|
-
}
|
|
166
|
-
async write(cmd) {
|
|
167
|
-
return this.ws.write(JSON.stringify(cmd));
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function noop() { }
|
|
171
|
-
async function processWSQueue(c, ws) {
|
|
172
|
-
var _a;
|
|
173
|
-
for await (const data of ws) {
|
|
174
|
-
const str = (data instanceof Promise ? await data : data);
|
|
175
|
-
if (typeof str != "string") {
|
|
176
|
-
await c.queue.enqueue(new ChatResponseError("websocket data is not a string"));
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
let resp;
|
|
180
|
-
try {
|
|
181
|
-
const json = JSON.parse(str);
|
|
182
|
-
if (typeof ((_a = json === null || json === void 0 ? void 0 : json.resp) === null || _a === void 0 ? void 0 : _a.type) == "string") {
|
|
183
|
-
resp = json;
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
resp = new ChatResponseError("invalid response format", str);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
catch (err) {
|
|
190
|
-
resp = new ChatResponseError(err.message, str);
|
|
191
|
-
}
|
|
192
|
-
await c.queue.enqueue(resp);
|
|
193
|
-
}
|
|
194
|
-
await c.queue.close();
|
|
195
|
-
}
|
|
196
|
-
function delay(ms) {
|
|
197
|
-
return new Promise((r) => setTimeout(r, ms));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
var ChatType;
|
|
201
|
-
(function (ChatType) {
|
|
202
|
-
ChatType["CTDirect"] = "@";
|
|
203
|
-
ChatType["CTGroup"] = "#";
|
|
204
|
-
ChatType["CTContactRequest"] = "<@";
|
|
205
|
-
})(ChatType || (ChatType = {}));
|
|
206
|
-
var DeleteMode;
|
|
207
|
-
(function (DeleteMode) {
|
|
208
|
-
DeleteMode["Broadcast"] = "broadcast";
|
|
209
|
-
DeleteMode["Internal"] = "internal";
|
|
210
|
-
})(DeleteMode || (DeleteMode = {}));
|
|
211
|
-
function cmdString(cmd) {
|
|
212
|
-
switch (cmd.type) {
|
|
213
|
-
case "showActiveUser":
|
|
214
|
-
return "/u";
|
|
215
|
-
case "createActiveUser":
|
|
216
|
-
return `/u ${JSON.stringify(cmd.profile)}`;
|
|
217
|
-
case "startChat":
|
|
218
|
-
return "/_start";
|
|
219
|
-
case "setFilesFolder":
|
|
220
|
-
return `/_files_folder ${cmd.filePath}`;
|
|
221
|
-
case "apiGetChats":
|
|
222
|
-
return "/_get chats";
|
|
223
|
-
case "apiGetChat":
|
|
224
|
-
return `/_get chat ${cmd.chatType}${cmd.chatId}${paginationStr(cmd.pagination)}`;
|
|
225
|
-
case "apiSendMessage":
|
|
226
|
-
return `/_send ${cmd.chatType}${cmd.chatId} json ${JSON.stringify(cmd.message)}`;
|
|
227
|
-
case "apiUpdateChatItem":
|
|
228
|
-
return `/_update item ${cmd.chatType}${cmd.chatId} ${cmd.chatItemId} json ${JSON.stringify(cmd.msgContent)}`;
|
|
229
|
-
case "apiDeleteChatItem":
|
|
230
|
-
return `/_delete item ${cmd.chatType}${cmd.chatId} ${cmd.chatItemId} ${cmd.deleteMode}`;
|
|
231
|
-
case "apiChatRead":
|
|
232
|
-
return `/_read chat ${cmd.chatType}${cmd.chatId} from=${cmd.fromItem} to=${cmd.toItem}`;
|
|
233
|
-
case "apiDeleteChat":
|
|
234
|
-
return `/_delete ${cmd.chatType}${cmd.chatId}`;
|
|
235
|
-
case "apiAcceptContact":
|
|
236
|
-
return `/_accept ${cmd.contactReqId}`;
|
|
237
|
-
case "apiRejectContact":
|
|
238
|
-
return `/_reject ${cmd.contactReqId}`;
|
|
239
|
-
case "apiUpdateProfile":
|
|
240
|
-
return `/_profile ${JSON.stringify(cmd.profile)}`;
|
|
241
|
-
case "apiParseMarkdown":
|
|
242
|
-
return `/_parse ${cmd.text}`;
|
|
243
|
-
case "getUserSMPServers":
|
|
244
|
-
return "/smp_servers";
|
|
245
|
-
case "setUserSMPServers":
|
|
246
|
-
return `/smp_servers ${cmd.servers.join(",") || "default"}`;
|
|
247
|
-
case "addContact":
|
|
248
|
-
return "/connect";
|
|
249
|
-
case "connect":
|
|
250
|
-
return `/connect ${cmd.connReq}`;
|
|
251
|
-
case "connectSimplex":
|
|
252
|
-
return "/simplex";
|
|
253
|
-
case "createMyAddress":
|
|
254
|
-
return "/address";
|
|
255
|
-
case "deleteMyAddress":
|
|
256
|
-
return "/delete_address";
|
|
257
|
-
case "showMyAddress":
|
|
258
|
-
return "/show_address";
|
|
259
|
-
case "addressAutoAccept":
|
|
260
|
-
return `/auto_accept ${cmd.enable ? "on" : "off"}`;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
function paginationStr(cp) {
|
|
264
|
-
const base = "after" in cp ? ` after=${cp.after}` : "before" in cp ? ` before=${cp.before}` : "";
|
|
265
|
-
return base + ` count=${cp.count}`;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
class ChatCommandError extends Error {
|
|
269
|
-
constructor(message, response) {
|
|
270
|
-
super(message);
|
|
271
|
-
this.message = message;
|
|
272
|
-
this.response = response;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
var ConnReqType;
|
|
276
|
-
(function (ConnReqType) {
|
|
277
|
-
ConnReqType["Invitation"] = "invitation";
|
|
278
|
-
ConnReqType["Contact"] = "contact";
|
|
279
|
-
})(ConnReqType || (ConnReqType = {}));
|
|
280
|
-
class ChatClient {
|
|
281
|
-
constructor(server, config, msgQ, client, transport) {
|
|
282
|
-
this.server = server;
|
|
283
|
-
this.config = config;
|
|
284
|
-
this.msgQ = msgQ;
|
|
285
|
-
this.client = client;
|
|
286
|
-
this.transport = transport;
|
|
287
|
-
this._connected = true;
|
|
288
|
-
this.clientCorrId = 0;
|
|
289
|
-
this.sentCommands = new Map();
|
|
290
|
-
}
|
|
291
|
-
static async create(server = localServer, cfg = ChatClient.defaultConfig) {
|
|
292
|
-
const transport = await ChatTransport.connect(server, cfg.tcpTimeout, cfg.qSize);
|
|
293
|
-
const msgQ = new ABQueue(cfg.qSize);
|
|
294
|
-
const client = runClient().then(noop, noop);
|
|
295
|
-
const c = new ChatClient(server, cfg, msgQ, client, transport);
|
|
296
|
-
return c;
|
|
297
|
-
async function runClient() {
|
|
298
|
-
for await (const t of transport) {
|
|
299
|
-
const apiResp = (t instanceof Promise ? await t : t);
|
|
300
|
-
if (apiResp instanceof ChatResponseError) {
|
|
301
|
-
console.log("chat response error: ", apiResp);
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
const { corrId, resp } = apiResp;
|
|
305
|
-
if (corrId) {
|
|
306
|
-
const req = c.sentCommands.get(corrId);
|
|
307
|
-
if (req) {
|
|
308
|
-
c.sentCommands.delete(corrId);
|
|
309
|
-
if (resp.type === "chatCmdError") {
|
|
310
|
-
req.reject(resp);
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
req.resolve(resp);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
// TODO send error to errQ?
|
|
318
|
-
console.log("no command sent for chat response: ", apiResp);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
await msgQ.enqueue(resp);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
c._connected = false;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
sendChatCmdStr(cmd) {
|
|
330
|
-
const corrId = `${++this.clientCorrId}`;
|
|
331
|
-
const t = { corrId, cmd };
|
|
332
|
-
this.transport.write(t).then(noop, noop);
|
|
333
|
-
return new Promise((resolve, reject) => this.sentCommands.set(corrId, { resolve, reject }));
|
|
334
|
-
}
|
|
335
|
-
sendChatCommand(command) {
|
|
336
|
-
return this.sendChatCmdStr(cmdString(command));
|
|
337
|
-
}
|
|
338
|
-
async disconnect() {
|
|
339
|
-
await this.transport.close();
|
|
340
|
-
await this.client;
|
|
341
|
-
}
|
|
342
|
-
async apiGetActiveUser() {
|
|
343
|
-
const r = await this.sendChatCommand({ type: "showActiveUser" });
|
|
344
|
-
switch (r.type) {
|
|
345
|
-
case "activeUser":
|
|
346
|
-
return r.user;
|
|
347
|
-
case "chatCmdError":
|
|
348
|
-
if (r.chatError.type === "error" && r.chatError.errorType.type === "noActiveUser")
|
|
349
|
-
return undefined;
|
|
350
|
-
throw new ChatCommandError("unexpected response error", r);
|
|
351
|
-
default:
|
|
352
|
-
throw new ChatCommandError("unexpected response", r);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
async apiCreateActiveUser(profile) {
|
|
356
|
-
const r = await this.sendChatCommand({ type: "createActiveUser", profile });
|
|
357
|
-
if (r.type === "activeUser")
|
|
358
|
-
return r.user;
|
|
359
|
-
throw new ChatCommandError("unexpected response", r);
|
|
360
|
-
}
|
|
361
|
-
async apiStartChat() {
|
|
362
|
-
const r = await this.sendChatCommand({ type: "startChat" });
|
|
363
|
-
if (r.type !== "chatStarted" && r.type !== "chatRunning") {
|
|
364
|
-
throw new ChatCommandError("error starting chat", r);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
async apiGetChats() {
|
|
368
|
-
const r = await this.sendChatCommand({ type: "apiGetChats" });
|
|
369
|
-
if (r.type === "apiChats")
|
|
370
|
-
return r.chats;
|
|
371
|
-
throw new ChatCommandError("error loading chats", r);
|
|
372
|
-
}
|
|
373
|
-
async apiGetChat(chatType, chatId, pagination = { count: 100 }) {
|
|
374
|
-
const r = await this.sendChatCommand({ type: "apiGetChat", chatType, chatId, pagination });
|
|
375
|
-
if (r.type === "apiChat")
|
|
376
|
-
return r.chat;
|
|
377
|
-
throw new ChatCommandError("error loading chat", r);
|
|
378
|
-
}
|
|
379
|
-
async apiSendMessage(chatType, chatId, message) {
|
|
380
|
-
const r = await this.sendChatCommand({ type: "apiSendMessage", chatType, chatId, message });
|
|
381
|
-
if (r.type === "newChatItem")
|
|
382
|
-
return r.chatItem;
|
|
383
|
-
throw new ChatCommandError("unexpected response", r);
|
|
384
|
-
}
|
|
385
|
-
apiSendTextMessage(chatType, chatId, text) {
|
|
386
|
-
return this.apiSendMessage(chatType, chatId, { msgContent: { type: "text", text } });
|
|
387
|
-
}
|
|
388
|
-
async apiUpdateChatItem(chatType, chatId, chatItemId, msgContent) {
|
|
389
|
-
const r = await this.sendChatCommand({ type: "apiUpdateChatItem", chatType, chatId, chatItemId, msgContent });
|
|
390
|
-
if (r.type === "chatItemUpdated")
|
|
391
|
-
return r.chatItem.chatItem;
|
|
392
|
-
throw new ChatCommandError("error updating chat item", r);
|
|
393
|
-
}
|
|
394
|
-
async apiDeleteChatItem(chatType, chatId, chatItemId, deleteMode) {
|
|
395
|
-
const r = await this.sendChatCommand({ type: "apiDeleteChatItem", chatType, chatId, chatItemId, deleteMode });
|
|
396
|
-
if (r.type === "chatItemDeleted")
|
|
397
|
-
return r.toChatItem.chatItem;
|
|
398
|
-
throw new ChatCommandError("error deleting chat item", r);
|
|
399
|
-
}
|
|
400
|
-
// func getUserSMPServers() throws -> [String] {
|
|
401
|
-
// let r = chatSendCmdSync(.getUserSMPServers)
|
|
402
|
-
// if case let .userSMPServers(smpServers) = r { return smpServers }
|
|
403
|
-
// throw r
|
|
404
|
-
// }
|
|
405
|
-
// func setUserSMPServers(smpServers: [String]) async throws {
|
|
406
|
-
// let r = await chatSendCmd(.setUserSMPServers(smpServers: smpServers))
|
|
407
|
-
// if case .cmdOk = r { return }
|
|
408
|
-
// throw r
|
|
409
|
-
// }
|
|
410
|
-
async apiCreateLink() {
|
|
411
|
-
const r = await this.sendChatCommand({ type: "addContact" });
|
|
412
|
-
if (r.type === "invitation")
|
|
413
|
-
return r.connReqInvitation;
|
|
414
|
-
throw new ChatCommandError("error creating link", r);
|
|
415
|
-
}
|
|
416
|
-
async apiConnect(connReq) {
|
|
417
|
-
const r = await this.sendChatCommand({ type: "connect", connReq });
|
|
418
|
-
switch (r.type) {
|
|
419
|
-
case "sentConfirmation":
|
|
420
|
-
return ConnReqType.Invitation;
|
|
421
|
-
case "sentInvitation":
|
|
422
|
-
return ConnReqType.Contact;
|
|
423
|
-
default:
|
|
424
|
-
throw new ChatCommandError("connection error", r);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
async apiDeleteChat(chatType, chatId) {
|
|
428
|
-
const r = await this.sendChatCommand({ type: "apiDeleteChat", chatType, chatId });
|
|
429
|
-
if (r.type !== "contactDeleted")
|
|
430
|
-
throw new ChatCommandError("error deleting chat", r);
|
|
431
|
-
}
|
|
432
|
-
async apiUpdateProfile(profile) {
|
|
433
|
-
const r = await this.sendChatCommand({ type: "apiUpdateProfile", profile });
|
|
434
|
-
switch (r.type) {
|
|
435
|
-
case "userProfileNoChange":
|
|
436
|
-
return undefined;
|
|
437
|
-
case "userProfileUpdated":
|
|
438
|
-
return r.toProfile;
|
|
439
|
-
default:
|
|
440
|
-
throw new ChatCommandError("error updating profile", r);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
// func apiParseMarkdown(text: String) throws -> [FormattedText]? {
|
|
444
|
-
// let r = chatSendCmdSync(.apiParseMarkdown(text: text))
|
|
445
|
-
// if case let .apiParsedMarkdown(formattedText) = r { return formattedText }
|
|
446
|
-
// throw r
|
|
447
|
-
// }
|
|
448
|
-
// func apiCreateUserAddress() async throws -> String {
|
|
449
|
-
// let r = await chatSendCmd(.createMyAddress)
|
|
450
|
-
// if case let .userContactLinkCreated(connReq) = r { return connReq }
|
|
451
|
-
// throw r
|
|
452
|
-
// }
|
|
453
|
-
// func apiDeleteUserAddress() async throws {
|
|
454
|
-
// let r = await chatSendCmd(.deleteMyAddress)
|
|
455
|
-
// if case .userContactLinkDeleted = r { return }
|
|
456
|
-
// throw r
|
|
457
|
-
// }
|
|
458
|
-
// func apiGetUserAddress() async throws -> String? {
|
|
459
|
-
// let r = await chatSendCmd(.showMyAddress)
|
|
460
|
-
// switch r {
|
|
461
|
-
// case let .userContactLink(connReq):
|
|
462
|
-
// return connReq
|
|
463
|
-
// case .chatCmdError(chatError: .errorStore(storeError: .userContactLinkNotFound)):
|
|
464
|
-
// return nil
|
|
465
|
-
// default: throw r
|
|
466
|
-
// }
|
|
467
|
-
// }
|
|
468
|
-
// func apiAcceptContactRequest(contactReqId: Int64) async throws -> Contact {
|
|
469
|
-
// let r = await chatSendCmd(.apiAcceptContact(contactReqId: contactReqId))
|
|
470
|
-
// if case let .acceptingContactRequest(contact) = r { return contact }
|
|
471
|
-
// throw r
|
|
472
|
-
// }
|
|
473
|
-
// func apiRejectContactRequest(contactReqId: Int64) async throws {
|
|
474
|
-
// let r = await chatSendCmd(.apiRejectContact(contactReqId: contactReqId))
|
|
475
|
-
// if case .contactRequestRejected = r { return }
|
|
476
|
-
// throw r
|
|
477
|
-
// }
|
|
478
|
-
// func apiChatRead(type: ChatType, id: Int64, itemRange: (Int64, Int64)) async throws {
|
|
479
|
-
// let r = await chatSendCmd(.apiChatRead(type: type, id: id, itemRange: itemRange))
|
|
480
|
-
// if case .cmdOk = r { return }
|
|
481
|
-
// throw r
|
|
482
|
-
// }
|
|
483
|
-
// func acceptContactRequest(_ contactRequest: UserContactRequest) async {
|
|
484
|
-
// do {
|
|
485
|
-
// let contact = try await apiAcceptContactRequest(contactReqId: contactRequest.apiId)
|
|
486
|
-
// let chat = Chat(chatInfo: ChatInfo.direct(contact: contact), chatItems: [])
|
|
487
|
-
// DispatchQueue.main.async { ChatModel.shared.replaceChat(contactRequest.id, chat) }
|
|
488
|
-
// } catch let error {
|
|
489
|
-
// logger.error("acceptContactRequest error: \(error.localizedDescription)")
|
|
490
|
-
// }
|
|
491
|
-
// }
|
|
492
|
-
// func rejectContactRequest(_ contactRequest: UserContactRequest) async {
|
|
493
|
-
// do {
|
|
494
|
-
// try await apiRejectContactRequest(contactReqId: contactRequest.apiId)
|
|
495
|
-
// DispatchQueue.main.async { ChatModel.shared.removeChat(contactRequest.id) }
|
|
496
|
-
// } catch let error {
|
|
497
|
-
// logger.error("rejectContactRequest: \(error.localizedDescription)")
|
|
498
|
-
// }
|
|
499
|
-
// }
|
|
500
|
-
// func markChatRead(_ chat: Chat) async {
|
|
501
|
-
// do {
|
|
502
|
-
// let minItemId = chat.chatStats.minUnreadItemId
|
|
503
|
-
// let itemRange = (minItemId, chat.chatItems.last?.id ?? minItemId)
|
|
504
|
-
// let cInfo = chat.chatInfo
|
|
505
|
-
// try await apiChatRead(type: cInfo.chatType, id: cInfo.apiId, itemRange: itemRange)
|
|
506
|
-
// DispatchQueue.main.async { ChatModel.shared.markChatItemsRead(cInfo) }
|
|
507
|
-
// } catch {
|
|
508
|
-
// logger.error("markChatRead apiChatRead error: \(error.localizedDescription)")
|
|
509
|
-
// }
|
|
510
|
-
// }
|
|
511
|
-
// func markChatItemRead(_ cInfo: ChatInfo, _ cItem: ChatItem) async {
|
|
512
|
-
// do {
|
|
513
|
-
// try await apiChatRead(type: cInfo.chatType, id: cInfo.apiId, itemRange: (cItem.id, cItem.id))
|
|
514
|
-
// DispatchQueue.main.async { ChatModel.shared.markChatItemRead(cInfo, cItem) }
|
|
515
|
-
// } catch {
|
|
516
|
-
// logger.error("markChatItemRead apiChatRead error: \(error.localizedDescription)")
|
|
517
|
-
// }
|
|
518
|
-
// }
|
|
519
|
-
// private async okChatCommand(command: ChatCommand): Promise<void> {
|
|
520
|
-
// const resp = await this.sendChatCommand(command)
|
|
521
|
-
// if (resp.type !== "cmdOk") throw new ChatCommandError("unexpected response", resp)
|
|
522
|
-
// }
|
|
523
|
-
get connected() {
|
|
524
|
-
return this._connected;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
ChatClient.defaultConfig = {
|
|
528
|
-
qSize: 16,
|
|
529
|
-
tcpTimeout: 4000,
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
exports.ABQueue = ABQueue;
|
|
533
|
-
exports.ChatClient = ChatClient;
|
|
534
|
-
|
|
535
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1
|
+
(function (factory) {
|
|
2
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
3
|
+
factory();
|
|
4
|
+
})((function () { 'use strict';
|
|
5
|
+
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ChatClient = void 0;
|
|
8
|
+
var client_1 = require("./client");
|
|
9
|
+
Object.defineProperty(exports, "ChatClient", { enumerable: true, get: function () { return client_1.ChatClient; } });
|
|
536
10
|
|
|
537
11
|
}));
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatClient = void 0;
|
|
4
|
+
require("./websocket");
|
|
5
|
+
var client_1 = require("./client");
|
|
6
|
+
Object.defineProperty(exports, "ChatClient", { enumerable: true, get: function () { return client_1.ChatClient; } });
|
|
3
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uBAAoB;AACpB,mCAAmC;AAA3B,oGAAA,UAAU,OAAA"}
|
package/dist/queue.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ABQueue = exports.ABQueueError = void 0;
|
|
1
4
|
class Sem {
|
|
2
5
|
constructor(permits) {
|
|
3
6
|
this.permits = permits;
|
|
@@ -16,9 +19,10 @@ class Sem {
|
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
const queueClosed = Symbol();
|
|
19
|
-
|
|
22
|
+
class ABQueueError extends Error {
|
|
20
23
|
}
|
|
21
|
-
|
|
24
|
+
exports.ABQueueError = ABQueueError;
|
|
25
|
+
class ABQueue {
|
|
22
26
|
constructor(maxSize) {
|
|
23
27
|
this.maxSize = maxSize;
|
|
24
28
|
this.queue = [];
|
|
@@ -69,4 +73,5 @@ export class ABQueue {
|
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
}
|
|
76
|
+
exports.ABQueue = ABQueue;
|
|
72
77
|
//# sourceMappingURL=queue.js.map
|
package/dist/queue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,MAAM,GAAG;IAGP,YAAoB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;QAFlB,aAAQ,GAA6B,EAAE,CAAA;IAElB,CAAC;IAEvC,MAAM;QACJ,IAAI,CAAC,OAAO,IAAI,CAAC,CAAA;QACjB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAiB,EAAE,CAAA;IACrE,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YAClD,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;SACnD;QACD,IAAI,CAAC,OAAO,IAAI,CAAC,CAAA;IACnB,CAAC;CACF;AAID,MAAM,WAAW,GAAG,MAAM,EAAE,CAAA;AAI5B,
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":";;;AAAA,MAAM,GAAG;IAGP,YAAoB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;QAFlB,aAAQ,GAA6B,EAAE,CAAA;IAElB,CAAC;IAEvC,MAAM;QACJ,IAAI,CAAC,OAAO,IAAI,CAAC,CAAA;QACjB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAiB,EAAE,CAAA;IACrE,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,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I,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;QACrB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAkB,CAAA;QAC5C,IAAI,CAAC,KAAK,WAAW,EAAE;YACrB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;YACrB,MAAM,IAAI,YAAY,CAAC,uBAAuB,CAAC,CAAA;SAChD;QACD,OAAO,CAAC,CAAA;IACV,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;QAChC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;IACvB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,CAAA;QACvC,IAAI;YACF,OAAO,EAAC,KAAK,EAAE,MAAM,IAAI,CAAC,OAAO,EAAE,EAAC,CAAA;SACrC;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,YAAY,YAAY;gBAAE,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,CAAA;YAClD,MAAM,CAAC,CAAA;SACR;IACH,CAAC;CACF;AArDD,0BAqDC"}
|
package/dist/response.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChatItemId, MsgContent, DeleteMode, Profile } from "./command";
|
|
2
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
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
4
|
interface CR {
|
|
@@ -192,19 +192,24 @@ export interface Chat {
|
|
|
192
192
|
chatStats: ChatStats;
|
|
193
193
|
}
|
|
194
194
|
export declare type ChatInfo = CInfoDirect | CInfoGroup | CInfoContactRequest;
|
|
195
|
+
export declare enum ChatInfoType {
|
|
196
|
+
Direct = "direct",
|
|
197
|
+
Group = "group",
|
|
198
|
+
ContactRequest = "contactRequest"
|
|
199
|
+
}
|
|
195
200
|
interface IChatInfo {
|
|
196
|
-
type:
|
|
201
|
+
type: ChatInfoType;
|
|
197
202
|
}
|
|
198
203
|
interface CInfoDirect extends IChatInfo {
|
|
199
|
-
type:
|
|
204
|
+
type: ChatInfoType.Direct;
|
|
200
205
|
contact: Contact;
|
|
201
206
|
}
|
|
202
207
|
interface CInfoGroup extends IChatInfo {
|
|
203
|
-
type:
|
|
208
|
+
type: ChatInfoType.Group;
|
|
204
209
|
groupInfo: GroupInfo;
|
|
205
210
|
}
|
|
206
211
|
interface CInfoContactRequest extends IChatInfo {
|
|
207
|
-
type:
|
|
212
|
+
type: ChatInfoType.ContactRequest;
|
|
208
213
|
contactRequest: UserContactRequest;
|
|
209
214
|
}
|
|
210
215
|
export interface Contact {
|
|
@@ -311,6 +316,7 @@ interface CIRcvFileInvitation extends ICIContent {
|
|
|
311
316
|
type: "rcvFileInvitation";
|
|
312
317
|
rcvFileTransfer: RcvFileTransfer;
|
|
313
318
|
}
|
|
319
|
+
export declare function ciContentText(content: CIContent): string | undefined;
|
|
314
320
|
interface RcvFileTransfer {
|
|
315
321
|
}
|
|
316
322
|
export interface ChatStats {
|
|
@@ -359,9 +365,11 @@ interface ChatErrorChat {
|
|
|
359
365
|
}
|
|
360
366
|
interface ChatErrorAgent {
|
|
361
367
|
type: "errorAgent";
|
|
368
|
+
agentError: AgentErrorType;
|
|
362
369
|
}
|
|
363
370
|
interface ChatErrorStore {
|
|
364
371
|
type: "errorStore";
|
|
372
|
+
storeError: StoreErrorType;
|
|
365
373
|
}
|
|
366
374
|
declare type ChatErrorType = CENoActiveUser | CEActiveUserExists;
|
|
367
375
|
interface CENoActiveUser {
|
|
@@ -375,5 +383,11 @@ interface ContactSubStatus {
|
|
|
375
383
|
interface PendingSubStatus {
|
|
376
384
|
}
|
|
377
385
|
interface AgentErrorType {
|
|
386
|
+
type: string;
|
|
387
|
+
[x: string]: any;
|
|
388
|
+
}
|
|
389
|
+
interface StoreErrorType {
|
|
390
|
+
type: string;
|
|
391
|
+
[x: string]: any;
|
|
378
392
|
}
|
|
379
393
|
export {};
|
package/dist/response.js
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ciContentText = exports.ChatInfoType = void 0;
|
|
4
|
+
var ChatInfoType;
|
|
5
|
+
(function (ChatInfoType) {
|
|
6
|
+
ChatInfoType["Direct"] = "direct";
|
|
7
|
+
ChatInfoType["Group"] = "group";
|
|
8
|
+
ChatInfoType["ContactRequest"] = "contactRequest";
|
|
9
|
+
})(ChatInfoType = exports.ChatInfoType || (exports.ChatInfoType = {}));
|
|
10
|
+
function ciContentText(content) {
|
|
11
|
+
switch (content.type) {
|
|
12
|
+
case "sndMsgContent":
|
|
13
|
+
return content.msgContent.text;
|
|
14
|
+
case "rcvMsgContent":
|
|
15
|
+
return content.msgContent.text;
|
|
16
|
+
default:
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ciContentText = ciContentText;
|
|
2
21
|
//# sourceMappingURL=response.js.map
|
package/dist/response.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":";;;AA6UA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,+BAAe,CAAA;IACf,iDAAiC,CAAA;AACnC,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAwJD,SAAgB,aAAa,CAAC,OAAkB;IAC9C,QAAQ,OAAO,CAAC,IAAI,EAAE;QACpB,KAAK,eAAe;YAClB,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAA;QAChC,KAAK,eAAe;YAClB,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAA;QAChC;YACE,OAAO,SAAS,CAAA;KACnB;AACH,CAAC;AATD,sCASC"}
|
package/dist/transport.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noop = exports.ChatTransport = exports.ChatResponseError = exports.localServer = exports.WSTransport = exports.Transport = exports.TransportError = void 0;
|
|
4
|
+
const queue_1 = require("./queue");
|
|
5
|
+
class TransportError extends Error {
|
|
3
6
|
}
|
|
4
|
-
|
|
7
|
+
exports.TransportError = TransportError;
|
|
8
|
+
class Transport {
|
|
5
9
|
constructor(qSize) {
|
|
6
|
-
this.queue = new ABQueue(qSize);
|
|
10
|
+
this.queue = new queue_1.ABQueue(qSize);
|
|
7
11
|
}
|
|
8
12
|
[Symbol.asyncIterator]() {
|
|
9
13
|
return this;
|
|
@@ -15,7 +19,8 @@ export class Transport {
|
|
|
15
19
|
return this.queue.next();
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
|
-
|
|
22
|
+
exports.Transport = Transport;
|
|
23
|
+
class WSTransport extends Transport {
|
|
19
24
|
constructor(sock, timeout, qSize) {
|
|
20
25
|
super(qSize);
|
|
21
26
|
this.sock = sock;
|
|
@@ -50,6 +55,7 @@ export class WSTransport extends Transport {
|
|
|
50
55
|
return data;
|
|
51
56
|
}
|
|
52
57
|
}
|
|
58
|
+
exports.WSTransport = WSTransport;
|
|
53
59
|
function withTimeout(ms, action) {
|
|
54
60
|
return Promise.race([
|
|
55
61
|
action(),
|
|
@@ -59,18 +65,19 @@ function withTimeout(ms, action) {
|
|
|
59
65
|
})(),
|
|
60
66
|
]);
|
|
61
67
|
}
|
|
62
|
-
|
|
68
|
+
exports.localServer = {
|
|
63
69
|
host: "localhost",
|
|
64
70
|
port: "5225",
|
|
65
71
|
};
|
|
66
|
-
|
|
72
|
+
class ChatResponseError extends Error {
|
|
67
73
|
constructor(message, data) {
|
|
68
74
|
super(message);
|
|
69
75
|
this.message = message;
|
|
70
76
|
this.data = data;
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
|
-
|
|
79
|
+
exports.ChatResponseError = ChatResponseError;
|
|
80
|
+
class ChatTransport extends Transport {
|
|
74
81
|
constructor(ws, timeout, qSize) {
|
|
75
82
|
super(qSize);
|
|
76
83
|
this.ws = ws;
|
|
@@ -90,7 +97,9 @@ export class ChatTransport extends Transport {
|
|
|
90
97
|
return this.ws.write(JSON.stringify(cmd));
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
|
-
|
|
100
|
+
exports.ChatTransport = ChatTransport;
|
|
101
|
+
function noop() { }
|
|
102
|
+
exports.noop = noop;
|
|
94
103
|
async function processWSQueue(c, ws) {
|
|
95
104
|
var _a;
|
|
96
105
|
for await (const data of ws) {
|
package/dist/transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AAGzC,MAAa,cAAe,SAAQ,KAAK;CAAG;AAA5C,wCAA4C;AAE5C,MAAsB,SAAS;IAG7B,YAAsB,KAAa;QACjC,IAAI,CAAC,KAAK,GAAG,IAAI,eAAO,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;IAED,CAAC,MAAM,CAAC,aAAa,CAAC;QACpB,OAAO,IAAI,CAAA;IACb,CAAC;IAMD,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAA;IAC7B,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;IAC1B,CAAC;CACF;AAtBD,8BAsBC;AAID,MAAa,WAAY,SAAQ,SAAyB;IACxD,YAAqC,IAAe,EAAW,OAAe,EAAE,KAAa;QAC3F,KAAK,CAAC,KAAK,CAAC,CAAA;QADuB,SAAI,GAAJ,IAAI,CAAW;QAAW,YAAO,GAAP,OAAO,CAAQ;IAE9E,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,GAAW,EAAE,OAAe,EAAE,K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,IAAI,GAAG,IAAI,iBAAiB,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAA;aAC7D;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,IAAI,iBAAiB,CAAE,GAAa,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;SAC1D;QACD,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;KAC5B;IACD,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;AACvB,CAAC;AAED,SAAS,KAAK,CAAC,EAAW;IACxB,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAC9C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simplex-chat",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "SimpleX Chat client",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"prettier": "^2.6.2",
|
|
48
48
|
"rollup": "^2.72.1",
|
|
49
49
|
"ts-jest": "^28.0.2",
|
|
50
|
+
"ts-node": "^10.7.0",
|
|
50
51
|
"typescript": "^4.6.3"
|
|
51
52
|
},
|
|
52
53
|
"husky": {
|