Эх сурвалжийг харах

add pingInterval option to Peer

afrokick 5 жил өмнө
parent
commit
6f36785a1c
2 өөрчлөгдсөн 4 нэмэгдсэн , 3 устгасан
  1. 2 0
      lib/peer.ts
  2. 2 3
      lib/socket.ts

+ 2 - 0
lib/peer.ts

@@ -25,6 +25,7 @@ class PeerOptions implements PeerJSOption {
   token?: string;
   config?: any;
   secure?: boolean;
+  pingInterval?: number;
   logFunction?: (logLevel: LogLevel, ...rest) => void;
 }
 
@@ -172,6 +173,7 @@ export class Peer extends EventEmitter {
       this._options.port,
       this._options.path,
       this._options.key,
+      this._options.pingInterval
     );
 
     this.socket.on(SocketEventType.Message, data => {

+ 2 - 3
lib/socket.ts

@@ -7,8 +7,6 @@ import { SocketEventType, ServerMessageType } from "./enums";
  * possible connection for peers.
  */
 export class Socket extends EventEmitter {
-  private readonly WEB_SOCKET_PING_INTERVAL = 20000;//ms
-
   private _disconnected = false;
   private _id: string;
   private _messagesQueue: Array<any> = [];
@@ -22,6 +20,7 @@ export class Socket extends EventEmitter {
     port: number,
     path: string,
     key: string,
+    private readonly pingInterval: number = 5000,
   ) {
     super();
 
@@ -83,7 +82,7 @@ export class Socket extends EventEmitter {
   }
 
   private _scheduleHeartbeat(): void {
-    this._wsPingTimer = setTimeout(() => { this._sendHeartbeat() }, this.WEB_SOCKET_PING_INTERVAL);
+    this._wsPingTimer = setTimeout(() => { this._sendHeartbeat() }, this.pingInterval);
   }
 
   private _sendHeartbeat(): void {