@freesignal/socketio 0.1.7 → 0.2.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/dist/base.d.ts CHANGED
@@ -1,21 +1,15 @@
1
- import { Database, LocalStorage, Crypto, KeyExchangeDataBundle } from "@freesignal/interfaces";
2
- import { Datagram, PrivateIdentityKey, UserId } from "@freesignal/protocol";
3
- import { ExportedKeySession } from "@freesignal/protocol/double-ratchet";
4
- import { BootstrapRequest, FreeSignalNode } from "@freesignal/protocol/node";
1
+ import { Datagram, UserId } from "@freesignal/protocol";
2
+ import { FreeSignalNode, FreeSignalNodeState } from "@freesignal/protocol/node";
5
3
  export declare enum TransportEvent {
6
4
  MESSAGE = "transport:message",
7
5
  HANDSHAKE = "transport:handshake"
8
6
  }
7
+ export interface FreeSignalSocketioState extends FreeSignalNodeState {
8
+ outbox: Array<[string, Uint8Array[]]>;
9
+ }
9
10
  export declare class FreeSignalSocketio extends FreeSignalNode {
10
- protected readonly outbox: LocalStorage<string, Uint8Array[]>;
11
- constructor(storage: Database<{
12
- sessions: LocalStorage<string, ExportedKeySession>;
13
- keyExchange: LocalStorage<string, Crypto.KeyPair>;
14
- users: LocalStorage<string, string>;
15
- bundles: LocalStorage<string, KeyExchangeDataBundle>;
16
- bootstraps: LocalStorage<string, BootstrapRequest>;
17
- outbox: LocalStorage<string, Uint8Array[]>;
18
- }>, privateIdentityKey?: PrivateIdentityKey);
11
+ protected readonly outbox: Map<string, Uint8Array[]>;
12
+ constructor(opts?: Partial<FreeSignalSocketioState>);
19
13
  protected addToOutbox(userId: string | UserId, datagram: Datagram | Uint8Array): Promise<void>;
20
14
  protected flushOutbox(): Promise<void>;
21
15
  onClose: () => void;
package/dist/base.js CHANGED
@@ -16,11 +16,11 @@ export var TransportEvent;
16
16
  TransportEvent["HANDSHAKE"] = "transport:handshake";
17
17
  })(TransportEvent || (TransportEvent = {}));
18
18
  export class FreeSignalSocketio extends FreeSignalNode {
19
- constructor(storage, privateIdentityKey) {
20
- super(storage, privateIdentityKey);
19
+ constructor(opts) {
20
+ super(opts);
21
21
  this.onClose = () => { };
22
22
  this.onError = () => { };
23
- this.outbox = storage.outbox;
23
+ this.outbox = new Map(opts === null || opts === void 0 ? void 0 : opts.outbox);
24
24
  }
25
25
  addToOutbox(userId, datagram) {
26
26
  return __awaiter(this, void 0, void 0, function* () {
package/dist/client.d.ts CHANGED
@@ -1,20 +1,12 @@
1
- import { Database, LocalStorage, Crypto, KeyExchangeDataBundle } from "@freesignal/interfaces";
2
- import { Datagram, PrivateIdentityKey, UserId } from "@freesignal/protocol";
3
- import { ExportedKeySession, KeySession } from "@freesignal/protocol/double-ratchet";
1
+ import { Datagram, UserId } from "@freesignal/protocol";
2
+ import { KeySession } from "@freesignal/protocol/double-ratchet";
4
3
  import { BootstrapRequest } from "@freesignal/protocol/node";
5
4
  import { EventCallback } from "easyemitter.ts";
6
- import { FreeSignalSocketio } from "./base.js";
5
+ import { FreeSignalSocketio, FreeSignalSocketioState } from "./base.js";
7
6
  export declare class FreeSignalClient extends FreeSignalSocketio {
8
7
  private _serverId?;
9
8
  private socket?;
10
- constructor(storage: Database<{
11
- sessions: LocalStorage<string, ExportedKeySession>;
12
- keyExchange: LocalStorage<string, Crypto.KeyPair>;
13
- users: LocalStorage<string, string>;
14
- bundles: LocalStorage<string, KeyExchangeDataBundle>;
15
- bootstraps: LocalStorage<string, BootstrapRequest>;
16
- outbox: LocalStorage<string, Uint8Array[]>;
17
- }>, privateIdentityKey?: PrivateIdentityKey);
9
+ constructor(opts?: Partial<FreeSignalSocketioState>);
18
10
  get connected(): boolean;
19
11
  get serverId(): UserId | undefined;
20
12
  protected sendHandler: EventCallback<{
package/dist/client.js CHANGED
@@ -11,8 +11,8 @@ import { UserId } from "@freesignal/protocol";
11
11
  import { io } from "socket.io-client";
12
12
  import { FreeSignalSocketio, TransportEvent } from "./base.js";
13
13
  export class FreeSignalClient extends FreeSignalSocketio {
14
- constructor(storage, privateIdentityKey) {
15
- super(storage, privateIdentityKey);
14
+ constructor(opts) {
15
+ super(opts);
16
16
  this.sendHandler = (eventData) => {
17
17
  const { session, datagram, userId } = eventData;
18
18
  if (!userId && !session)
package/dist/run.js CHANGED
@@ -1,4 +1,3 @@
1
- import { AsyncMap } from "@freesignal/protocol";
2
1
  import { FreeSignalServer } from "./server.js";
3
- const server = new FreeSignalServer({ keyExchange: new AsyncMap(), sessions: new AsyncMap(), users: new AsyncMap(), bundles: new AsyncMap(), bootstraps: new AsyncMap(), outbox: new AsyncMap() }).listen();
2
+ const server = new FreeSignalServer().listen();
4
3
  console.log("Freesignal Server started!");
package/dist/server.d.ts CHANGED
@@ -16,24 +16,15 @@
16
16
  * You should have received a copy of the GNU General Public License
17
17
  * along with this program. If not, see <https://www.gnu.org/licenses/>
18
18
  */
19
- import { Database, LocalStorage, Crypto, KeyExchangeDataBundle } from "@freesignal/interfaces";
20
- import { Datagram, PrivateIdentityKey, UserId } from "@freesignal/protocol";
21
- import { ExportedKeySession, KeySession } from "@freesignal/protocol/double-ratchet";
22
- import { BootstrapRequest } from "@freesignal/protocol/node";
19
+ import { Datagram, UserId } from "@freesignal/protocol";
20
+ import { KeySession } from "@freesignal/protocol/double-ratchet";
23
21
  import { EventCallback } from "easyemitter.ts";
24
22
  import { type Server as HttpServer } from "http";
25
- import { FreeSignalSocketio } from "./base.js";
23
+ import { FreeSignalSocketio, FreeSignalSocketioState } from "./base.js";
26
24
  export declare class FreeSignalServer extends FreeSignalSocketio {
27
25
  private wss?;
28
26
  private readonly connections;
29
- constructor(storage: Database<{
30
- sessions: LocalStorage<string, ExportedKeySession>;
31
- keyExchange: LocalStorage<string, Crypto.KeyPair>;
32
- users: LocalStorage<string, string>;
33
- bundles: LocalStorage<string, KeyExchangeDataBundle>;
34
- bootstraps: LocalStorage<string, BootstrapRequest>;
35
- outbox: LocalStorage<string, Uint8Array[]>;
36
- }>, privateIdentityKey?: PrivateIdentityKey);
27
+ constructor(opts?: Partial<FreeSignalSocketioState>);
37
28
  protected sendHandler: EventCallback<{
38
29
  session?: KeySession;
39
30
  datagram?: Datagram;
package/dist/server.js CHANGED
@@ -16,20 +16,11 @@
16
16
  * You should have received a copy of the GNU General Public License
17
17
  * along with this program. If not, see <https://www.gnu.org/licenses/>
18
18
  */
19
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
20
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
- return new (P || (P = Promise))(function (resolve, reject) {
22
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
23
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
24
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
25
- step((generator = generator.apply(thisArg, _arguments || [])).next());
26
- });
27
- };
28
19
  import { Server } from 'socket.io';
29
20
  import { FreeSignalSocketio, TransportEvent } from "./base.js";
30
21
  export class FreeSignalServer extends FreeSignalSocketio {
31
- constructor(storage, privateIdentityKey) {
32
- super(storage, privateIdentityKey);
22
+ constructor(opts) {
23
+ super(opts);
33
24
  this.connections = new Map();
34
25
  this.sendHandler = (eventData) => {
35
26
  const { session, datagram, userId } = eventData;
@@ -56,7 +47,7 @@ export class FreeSignalServer extends FreeSignalSocketio {
56
47
  origin: (origin, callback) => callback(null, origin)
57
48
  }
58
49
  });
59
- this.wss.on('connection', (socket) => __awaiter(this, void 0, void 0, function* () {
50
+ this.wss.on('connection', (socket) => {
60
51
  const userId = socket.handshake.auth.userId;
61
52
  if (!userId) {
62
53
  socket.disconnect();
@@ -67,13 +58,14 @@ export class FreeSignalServer extends FreeSignalSocketio {
67
58
  socket.on(TransportEvent.MESSAGE, (data) => this.open(data));
68
59
  socket.on('disconnect', () => this.connections.delete(userId));
69
60
  socket.emit(TransportEvent.HANDSHAKE, this.userId.toString());
70
- if (!(yield this.sessions.has(userId))) {
71
- this.sendBootstrap(userId);
61
+ const sessionTag = this.users.get(userId);
62
+ if (sessionTag && this.sessions.has(sessionTag)) {
63
+ this.sendHandshake(userId);
72
64
  }
73
65
  else {
74
- this.sendHandshake(userId);
66
+ this.sendBootstrap(userId);
75
67
  }
76
- }));
68
+ });
77
69
  return this;
78
70
  }
79
71
  close() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freesignal/socketio",
3
- "version": "0.1.7",
3
+ "version": "0.2.1",
4
4
  "description": "Socket.io trasnport package for FreeSignal protocol",
5
5
  "homepage": "https://github.com/christianbraghette/freesignal-socketio#readme",
6
6
  "bugs": {
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@freesignal/interfaces": "^0.3.1",
40
- "@freesignal/protocol": "^0.8.0",
40
+ "@freesignal/protocol": "^0.9.0",
41
41
  "@freesignal/utils": "^1.5.1",
42
42
  "socket.io": "^4.8.1",
43
43
  "socket.io-client": "^4.8.1"