@wireapp/core 31.3.6 → 32.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/package.json +3 -3
- package/src/main/Account.d.ts +12 -7
- package/src/main/Account.js +30 -7
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"./src/main/cryptography/AssetCryptography/crypto.node": "./src/main/cryptography/AssetCryptography/crypto.browser.js"
|
|
4
4
|
},
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@wireapp/api-client": "^20.6.
|
|
6
|
+
"@wireapp/api-client": "^20.6.5",
|
|
7
7
|
"@wireapp/commons": "^4.4.6",
|
|
8
8
|
"@wireapp/core-crypto": "0.5.2",
|
|
9
9
|
"@wireapp/cryptobox": "12.8.0",
|
|
@@ -81,6 +81,6 @@
|
|
|
81
81
|
"test": "jest",
|
|
82
82
|
"watch": "tsc ---watch"
|
|
83
83
|
},
|
|
84
|
-
"version": "
|
|
85
|
-
"gitHead": "
|
|
84
|
+
"version": "32.0.1",
|
|
85
|
+
"gitHead": "6fe9b9fc73ef4d777bfa4e3a37e78d28a49ae099"
|
|
86
86
|
}
|
package/src/main/Account.d.ts
CHANGED
|
@@ -21,13 +21,22 @@ import { TeamService } from './team/';
|
|
|
21
21
|
import { UserService } from './user/';
|
|
22
22
|
import { AccountService } from './account/';
|
|
23
23
|
import { LinkPreviewService } from './linkPreview';
|
|
24
|
-
import { WEBSOCKET_STATE } from '@wireapp/api-client/src/tcp/ReconnectingWebsocket';
|
|
25
24
|
import { MLSService } from './mls';
|
|
26
25
|
import { MLSCallbacks, MLSConfig } from './mls/types';
|
|
27
26
|
export declare type ProcessedEventPayload = HandledEventPayload;
|
|
28
27
|
declare enum TOPIC {
|
|
29
28
|
ERROR = "Account.TOPIC.ERROR"
|
|
30
29
|
}
|
|
30
|
+
export declare enum ConnectionState {
|
|
31
|
+
/** The websocket is closed and notifications stream is not being processed */
|
|
32
|
+
CLOSED = "closed",
|
|
33
|
+
/** The websocket is being opened */
|
|
34
|
+
CONNECTING = "connecting",
|
|
35
|
+
/** The websocket is open but locked and notifications stream is being processed */
|
|
36
|
+
PROCESSING_NOTIFICATIONS = "processing_notifications",
|
|
37
|
+
/** The websocket is open and message will go through and notifications stream is fully processed */
|
|
38
|
+
LIVE = "live"
|
|
39
|
+
}
|
|
31
40
|
export interface Account {
|
|
32
41
|
on(event: PayloadBundleType.ASSET, listener: (payload: OtrMessage.FileAssetMessage | OtrMessage.ImageAssetMessage) => void): this;
|
|
33
42
|
on(event: PayloadBundleType.BUTTON_ACTION, listener: (payload: OtrMessage.ButtonActionMessage) => void): this;
|
|
@@ -172,7 +181,7 @@ export declare class Account<T = any> extends EventEmitter {
|
|
|
172
181
|
* @param callbacks callbacks that will be called to handle different events
|
|
173
182
|
* @returns close a function that will disconnect from the websocket
|
|
174
183
|
*/
|
|
175
|
-
listen({ onEvent,
|
|
184
|
+
listen({ onEvent, onConnectionStateChanged, onNotificationStreamProgress, onMissedNotifications, dryRun, }?: {
|
|
176
185
|
/**
|
|
177
186
|
* Called when a new event arrives from backend
|
|
178
187
|
* @param payload the payload of the event. Contains the raw event received and the decrypted data (if event was encrypted)
|
|
@@ -186,14 +195,10 @@ export declare class Account<T = any> extends EventEmitter {
|
|
|
186
195
|
done: number;
|
|
187
196
|
total: number;
|
|
188
197
|
}) => void;
|
|
189
|
-
/**
|
|
190
|
-
* called when the connection to the websocket is established and the notification stream has been processed
|
|
191
|
-
*/
|
|
192
|
-
onConnected?: () => void;
|
|
193
198
|
/**
|
|
194
199
|
* called when the connection stateh with the backend has changed
|
|
195
200
|
*/
|
|
196
|
-
onConnectionStateChanged?: (state:
|
|
201
|
+
onConnectionStateChanged?: (state: ConnectionState) => void;
|
|
197
202
|
/**
|
|
198
203
|
* called when we detect lost notification from backend.
|
|
199
204
|
* When a client doesn't log in for a while (28 days, as of now) notifications that are older than 28 days will be deleted from backend.
|
package/src/main/Account.js
CHANGED
|
@@ -51,7 +51,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
51
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.Account = void 0;
|
|
54
|
+
exports.Account = exports.ConnectionState = void 0;
|
|
55
55
|
const http_status_codes_1 = require("http-status-codes");
|
|
56
56
|
const api_client_1 = require("@wireapp/api-client");
|
|
57
57
|
const auth_1 = require("@wireapp/api-client/src/auth/");
|
|
@@ -74,6 +74,7 @@ const team_1 = require("./team/");
|
|
|
74
74
|
const user_1 = require("./user/");
|
|
75
75
|
const account_1 = require("./account/");
|
|
76
76
|
const linkPreview_1 = require("./linkPreview");
|
|
77
|
+
const ReconnectingWebsocket_1 = require("@wireapp/api-client/src/tcp/ReconnectingWebsocket");
|
|
77
78
|
const encryptedStore_1 = require("./util/encryptedStore");
|
|
78
79
|
const bazinga64_1 = require("bazinga64");
|
|
79
80
|
const mls_1 = require("./mls");
|
|
@@ -82,6 +83,17 @@ var TOPIC;
|
|
|
82
83
|
(function (TOPIC) {
|
|
83
84
|
TOPIC["ERROR"] = "Account.TOPIC.ERROR";
|
|
84
85
|
})(TOPIC || (TOPIC = {}));
|
|
86
|
+
var ConnectionState;
|
|
87
|
+
(function (ConnectionState) {
|
|
88
|
+
/** The websocket is closed and notifications stream is not being processed */
|
|
89
|
+
ConnectionState["CLOSED"] = "closed";
|
|
90
|
+
/** The websocket is being opened */
|
|
91
|
+
ConnectionState["CONNECTING"] = "connecting";
|
|
92
|
+
/** The websocket is open but locked and notifications stream is being processed */
|
|
93
|
+
ConnectionState["PROCESSING_NOTIFICATIONS"] = "processing_notifications";
|
|
94
|
+
/** The websocket is open and message will go through and notifications stream is fully processed */
|
|
95
|
+
ConnectionState["LIVE"] = "live";
|
|
96
|
+
})(ConnectionState = exports.ConnectionState || (exports.ConnectionState = {}));
|
|
85
97
|
const coreDefaultClient = {
|
|
86
98
|
classification: client_1.ClientClassification.DESKTOP,
|
|
87
99
|
cookieLabel: 'default',
|
|
@@ -365,7 +377,7 @@ class Account extends events_1.EventEmitter {
|
|
|
365
377
|
* @param callbacks callbacks that will be called to handle different events
|
|
366
378
|
* @returns close a function that will disconnect from the websocket
|
|
367
379
|
*/
|
|
368
|
-
async listen({ onEvent = () => { },
|
|
380
|
+
async listen({ onEvent = () => { }, onConnectionStateChanged = () => { }, onNotificationStreamProgress = () => { }, onMissedNotifications = () => { }, dryRun = false, } = {}) {
|
|
369
381
|
if (!this.apiClient.context) {
|
|
370
382
|
throw new Error('Context is not set - please login first');
|
|
371
383
|
}
|
|
@@ -408,9 +420,19 @@ class Account extends events_1.EventEmitter {
|
|
|
408
420
|
};
|
|
409
421
|
this.apiClient.transport.ws.removeAllListeners(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE);
|
|
410
422
|
this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE, notification => handleNotification(notification, conversation_1.PayloadBundleSource.WEBSOCKET));
|
|
411
|
-
this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_STATE_CHANGE,
|
|
412
|
-
|
|
423
|
+
this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_STATE_CHANGE, wsState => {
|
|
424
|
+
const mapping = {
|
|
425
|
+
[ReconnectingWebsocket_1.WEBSOCKET_STATE.CLOSED]: ConnectionState.CLOSED,
|
|
426
|
+
[ReconnectingWebsocket_1.WEBSOCKET_STATE.CONNECTING]: ConnectionState.CONNECTING,
|
|
427
|
+
};
|
|
428
|
+
const connectionState = mapping[wsState];
|
|
429
|
+
if (connectionState) {
|
|
430
|
+
onConnectionStateChanged(connectionState);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
const processNotificationStream = async (abortHandler) => {
|
|
413
434
|
// Lock websocket in order to buffer any message that arrives while we handle the notification stream
|
|
435
|
+
onConnectionStateChanged(ConnectionState.PROCESSING_NOTIFICATIONS);
|
|
414
436
|
this.apiClient.transport.ws.lock();
|
|
415
437
|
await this.service.notification.handleNotificationStream(async (notification, source, progress) => {
|
|
416
438
|
await handleNotification(notification, source);
|
|
@@ -421,12 +443,13 @@ class Account extends events_1.EventEmitter {
|
|
|
421
443
|
// We need to wait for the notification stream to be fully handled before releasing the message sending queue.
|
|
422
444
|
// This is due to the nature of how message are encrypted, any change in mls epoch needs to happen before we start encrypting any kind of messages
|
|
423
445
|
(0, messageSender_1.resumeMessageSending)();
|
|
424
|
-
|
|
446
|
+
onConnectionStateChanged(ConnectionState.LIVE);
|
|
425
447
|
};
|
|
426
|
-
|
|
448
|
+
this.apiClient.connect(processNotificationStream);
|
|
427
449
|
return () => {
|
|
428
|
-
this.apiClient.transport.ws.removeAllListeners();
|
|
429
450
|
this.apiClient.disconnect();
|
|
451
|
+
onConnectionStateChanged(ConnectionState.CLOSED);
|
|
452
|
+
this.apiClient.transport.ws.removeAllListeners();
|
|
430
453
|
};
|
|
431
454
|
}
|
|
432
455
|
generateDbName(context) {
|