@thalesrc/hermes 5.3.1 → 5.3.3
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.
|
@@ -5,7 +5,6 @@ import { Message } from '../message.interface';
|
|
|
5
5
|
import { GET_NEW_ID, RESPONSES$, SEND } from '../selectors';
|
|
6
6
|
declare const PORT: unique symbol;
|
|
7
7
|
export declare class ChromeMessageClient extends MessageClient {
|
|
8
|
-
private static readonly idHelper;
|
|
9
8
|
private static readonly connections;
|
|
10
9
|
[RESPONSES$]: Observable<MessageResponse>;
|
|
11
10
|
private [PORT];
|
package/chrome/message-client.js
CHANGED
|
@@ -3,7 +3,8 @@ import { share } from 'rxjs/operators';
|
|
|
3
3
|
import { MessageClient } from '../message-client';
|
|
4
4
|
import { GET_NEW_ID, RESPONSES$, SEND } from '../selectors';
|
|
5
5
|
import { DEFAULT_CONNECTION_NAME } from './default-connection-name';
|
|
6
|
-
|
|
6
|
+
const RANDOM_ID_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
7
|
+
const RANDOM_ID_CHARS_LENGTH = RANDOM_ID_CHARS.length;
|
|
7
8
|
const PORT = Symbol('Port');
|
|
8
9
|
export class ChromeMessageClient extends MessageClient {
|
|
9
10
|
constructor(name = DEFAULT_CONNECTION_NAME) {
|
|
@@ -24,8 +25,11 @@ export class ChromeMessageClient extends MessageClient {
|
|
|
24
25
|
this[PORT].postMessage(message);
|
|
25
26
|
}
|
|
26
27
|
[GET_NEW_ID]() {
|
|
27
|
-
|
|
28
|
+
let result = '' + Date.now();
|
|
29
|
+
for (var i = 0; i < 10; i++) {
|
|
30
|
+
result += RANDOM_ID_CHARS.charAt(Math.floor(Math.random() * RANDOM_ID_CHARS_LENGTH));
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
|
-
ChromeMessageClient.idHelper = new UniqueMessageIdHelper();
|
|
31
35
|
ChromeMessageClient.connections = {};
|
package/package.json
CHANGED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export class UniqueMessageIdHelper {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.lastId = Number.MIN_SAFE_INTEGER;
|
|
4
|
-
this.lap = 0;
|
|
5
|
-
chrome.runtime.onMessage.addListener((message) => {
|
|
6
|
-
if (!message || !(message instanceof Object) || message.to !== UniqueMessageIdHelper.PORT_ID) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const { type, lastId, lap } = message;
|
|
10
|
-
switch (type) {
|
|
11
|
-
case 'newId':
|
|
12
|
-
this.updateLastId(lastId, lap);
|
|
13
|
-
break;
|
|
14
|
-
case 'postMeLastIds':
|
|
15
|
-
chrome.runtime.sendMessage({ lap: this.lap, lastId: this.lastId, type: 'newId', to: UniqueMessageIdHelper.PORT_ID });
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
chrome.runtime.sendMessage({ type: 'postMeLastIds', to: UniqueMessageIdHelper.PORT_ID });
|
|
20
|
-
}
|
|
21
|
-
getId() {
|
|
22
|
-
if (this.lastId >= Number.MAX_SAFE_INTEGER) {
|
|
23
|
-
this.lastId = Number.MIN_SAFE_INTEGER;
|
|
24
|
-
this.lap = this.lap + 1;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
this.lastId = this.lastId + 1;
|
|
28
|
-
}
|
|
29
|
-
chrome.runtime.sendMessage({ lap: this.lap, lastId: this.lastId, type: 'newId', to: UniqueMessageIdHelper.PORT_ID });
|
|
30
|
-
return '*'.repeat(this.lap) + this.lastId;
|
|
31
|
-
}
|
|
32
|
-
updateLastId(id, lap) {
|
|
33
|
-
if (this.lastId < id) {
|
|
34
|
-
this.lastId = id;
|
|
35
|
-
}
|
|
36
|
-
if (this.lap < lap) {
|
|
37
|
-
this.lap = lap;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
UniqueMessageIdHelper.PORT_ID = '__hermes_unique_message_id_port__';
|