From 1cf7c176d5dca2b0ec2317010719f96b4faa5e22 Mon Sep 17 00:00:00 2001 From: skoshx Date: Sun, 24 Jul 2022 17:57:55 +0300 Subject: [PATCH 1/3] feat: add protocol support This commit adds support for defining which WebSocket protocol a Peer instance should use. This makes it possible to for instance use versioning for Peer servers, and much more. --- lib/peer.ts | 1 + lib/socket.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/peer.ts b/lib/peer.ts index 37771bbca..468c7304a 100644 --- a/lib/peer.ts +++ b/lib/peer.ts @@ -28,6 +28,7 @@ class PeerOptions implements PeerJSOption { config?: any; secure?: boolean; pingInterval?: number; + protocol?: string | string[]; referrerPolicy?: ReferrerPolicy; logFunction?: (logLevel: LogLevel, ...rest: any[]) => void; } diff --git a/lib/socket.ts b/lib/socket.ts index e47cb5f25..52d7260c2 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -22,6 +22,7 @@ export class Socket extends EventEmitter { path: string, key: string, private readonly pingInterval: number = 5000, + private readonly protocol: string | string[] | undefined = undefined, ) { super(); @@ -39,7 +40,7 @@ export class Socket extends EventEmitter { return; } - this._socket = new WebSocket(wsUrl + "&version=" + version); + this._socket = new WebSocket(wsUrl + "&version=" + version, this.protocol); this._disconnected = false; this._socket.onmessage = (event) => { From ae6cbd7ff5b3d6495fd4903721ed37cc211a352d Mon Sep 17 00:00:00 2001 From: skoshx Date: Sun, 24 Jul 2022 18:01:30 +0300 Subject: [PATCH 2/3] style: formatting --- lib/peer.ts | 2 +- lib/socket.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/peer.ts b/lib/peer.ts index 468c7304a..c32ccc0f3 100644 --- a/lib/peer.ts +++ b/lib/peer.ts @@ -28,7 +28,7 @@ class PeerOptions implements PeerJSOption { config?: any; secure?: boolean; pingInterval?: number; - protocol?: string | string[]; + protocol?: string | string[]; referrerPolicy?: ReferrerPolicy; logFunction?: (logLevel: LogLevel, ...rest: any[]) => void; } diff --git a/lib/socket.ts b/lib/socket.ts index 52d7260c2..c7d27af92 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -22,7 +22,7 @@ export class Socket extends EventEmitter { path: string, key: string, private readonly pingInterval: number = 5000, - private readonly protocol: string | string[] | undefined = undefined, + private readonly protocol: string | string[] | undefined = undefined, ) { super(); From 8ac271623c23147a490f980fd2d909a4e53c3a2f Mon Sep 17 00:00:00 2001 From: skoshx Date: Sun, 24 Jul 2022 22:03:48 +0300 Subject: [PATCH 3/3] fix: pass protocol to socket --- lib/peer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/peer.ts b/lib/peer.ts index c32ccc0f3..b75b09ea7 100644 --- a/lib/peer.ts +++ b/lib/peer.ts @@ -241,6 +241,7 @@ export class Peer extends EventEmitter { this._options.path!, this._options.key!, this._options.pingInterval, + this._options.protocol, ); socket.on(SocketEventType.Message, (data: ServerMessage) => {