@freesignal/socketio 0.1.3 → 0.1.4
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/dist/base.d.ts +4 -0
- package/dist/base.js +6 -0
- package/dist/client.js +4 -4
- package/dist/server.js +4 -4
- package/package.json +1 -1
package/dist/base.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { Database, LocalStorage, Crypto, KeyExchangeDataBundle } from "@freesign
|
|
|
2
2
|
import { Datagram, PrivateIdentityKey, UserId } from "@freesignal/protocol";
|
|
3
3
|
import { ExportedKeySession } from "@freesignal/protocol/double-ratchet";
|
|
4
4
|
import { BootstrapRequest, FreeSignalNode } from "@freesignal/protocol/node";
|
|
5
|
+
export declare enum TransportEvent {
|
|
6
|
+
MESSAGE = "transport:message",
|
|
7
|
+
HANDSHAKE = "transport:handshake"
|
|
8
|
+
}
|
|
5
9
|
export declare class FreeSignalSocketio extends FreeSignalNode {
|
|
6
10
|
protected readonly outbox: LocalStorage<string, Uint8Array[]>;
|
|
7
11
|
constructor(storage: Database<{
|
package/dist/base.js
CHANGED
|
@@ -9,6 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { Datagram, UserId } from "@freesignal/protocol";
|
|
11
11
|
import { FreeSignalNode } from "@freesignal/protocol/node";
|
|
12
|
+
const TransportEventPrefix = "transport:";
|
|
13
|
+
export var TransportEvent;
|
|
14
|
+
(function (TransportEvent) {
|
|
15
|
+
TransportEvent["MESSAGE"] = "transport:message";
|
|
16
|
+
TransportEvent["HANDSHAKE"] = "transport:handshake";
|
|
17
|
+
})(TransportEvent || (TransportEvent = {}));
|
|
12
18
|
export class FreeSignalSocketio extends FreeSignalNode {
|
|
13
19
|
constructor(storage, privateIdentityKey) {
|
|
14
20
|
super(storage, privateIdentityKey);
|
package/dist/client.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { UserId } from "@freesignal/protocol";
|
|
11
11
|
import { io } from "socket.io-client";
|
|
12
|
-
import { FreeSignalSocketio } from "./base.js";
|
|
12
|
+
import { FreeSignalSocketio, TransportEvent } from "./base.js";
|
|
13
13
|
export class FreeSignalClient extends FreeSignalSocketio {
|
|
14
14
|
constructor(storage, privateIdentityKey) {
|
|
15
15
|
super(storage, privateIdentityKey);
|
|
@@ -25,7 +25,7 @@ export class FreeSignalClient extends FreeSignalSocketio {
|
|
|
25
25
|
else if (!this.socket || !this.socket.connected)
|
|
26
26
|
this.addToOutbox(receiverId, datagram);
|
|
27
27
|
else
|
|
28
|
-
this.socket.
|
|
28
|
+
this.socket.emit(TransportEvent.MESSAGE, datagram.toBytes());
|
|
29
29
|
};
|
|
30
30
|
this.emitter.on('send', this.sendHandler);
|
|
31
31
|
}
|
|
@@ -44,13 +44,13 @@ export class FreeSignalClient extends FreeSignalSocketio {
|
|
|
44
44
|
userId: this.userId.toString()
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
this.socket.on(
|
|
47
|
+
this.socket.on(TransportEvent.HANDSHAKE, (userId) => __awaiter(this, void 0, void 0, function* () {
|
|
48
48
|
this._serverId = userId;
|
|
49
49
|
yield this.waitHandshaked(userId);
|
|
50
50
|
yield this.flushOutbox();
|
|
51
51
|
resolve();
|
|
52
52
|
}));
|
|
53
|
-
this.socket.on(
|
|
53
|
+
this.socket.on(TransportEvent.MESSAGE, (data) => { this.open(data); });
|
|
54
54
|
this.socket.on('disconnect', () => {
|
|
55
55
|
this.onClose();
|
|
56
56
|
this.socket = undefined;
|
package/dist/server.js
CHANGED
|
@@ -26,7 +26,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
import { Server } from 'socket.io';
|
|
29
|
-
import { FreeSignalSocketio } from "./base.js";
|
|
29
|
+
import { FreeSignalSocketio, TransportEvent } from "./base.js";
|
|
30
30
|
export class FreeSignalServer extends FreeSignalSocketio {
|
|
31
31
|
constructor(storage, privateIdentityKey) {
|
|
32
32
|
super(storage, privateIdentityKey);
|
|
@@ -44,7 +44,7 @@ export class FreeSignalServer extends FreeSignalSocketio {
|
|
|
44
44
|
if (!socket.connected)
|
|
45
45
|
this.addToOutbox(receiverId, datagram);
|
|
46
46
|
else
|
|
47
|
-
socket.
|
|
47
|
+
socket.emit(TransportEvent.MESSAGE, datagram.toBytes());
|
|
48
48
|
};
|
|
49
49
|
this.emitter.on('send', this.sendHandler);
|
|
50
50
|
this.emitter.on('bootstrap', ({ request }) => request === null || request === void 0 ? void 0 : request.accept());
|
|
@@ -69,9 +69,9 @@ export class FreeSignalServer extends FreeSignalSocketio {
|
|
|
69
69
|
}
|
|
70
70
|
console.debug("Client connected: ", userId);
|
|
71
71
|
this.connections.set(userId, socket);
|
|
72
|
-
socket.on(
|
|
72
|
+
socket.on(TransportEvent.MESSAGE, (data) => this.open(data));
|
|
73
73
|
socket.on('disconnect', () => this.connections.delete(userId));
|
|
74
|
-
socket.emit(
|
|
74
|
+
socket.emit(TransportEvent.HANDSHAKE, this.userId.toString());
|
|
75
75
|
if (!(yield this.sessions.has(userId)))
|
|
76
76
|
this.sendBootstrap(userId);
|
|
77
77
|
else
|
package/package.json
CHANGED