afrokick 6 anos atrás
pai
commit
a7844e79ee
4 arquivos alterados com 24 adições e 4 exclusões
  1. 1 1
      index.d.ts
  2. 3 3
      lib/peer.ts
  3. 14 0
      test/peer.ts
  4. 6 0
      tsconfig.json

+ 1 - 1
index.d.ts

@@ -13,7 +13,7 @@ declare class Peer {
    *     If no ID is given, one will be generated by the brokering server.
    * @param options for specifying details about PeerServer
    */
-  constructor(id: string, options?: Peer.PeerJSOption);
+  constructor(id?: string, options?: Peer.PeerJSOption);
 
   /**
    * A peer can connect to other peers and listen for connections.

+ 3 - 3
lib/peer.ts

@@ -8,7 +8,6 @@ import {
   PeerErrorType,
   PeerEventType,
   SocketEventType,
-  SerializationType,
   ServerMessageType
 } from "./enums";
 import { BaseConnection } from "./baseconnection";
@@ -85,7 +84,7 @@ export class Peer extends EventEmitter {
     return this._disconnected;
   }
 
-  constructor(id: any, options?: PeerOptions) {
+  constructor(id?: any, options?: PeerOptions) {
     super();
 
     // Deal with overloading
@@ -320,7 +319,8 @@ export class Peer extends EventEmitter {
   }
 
   /** Retrieve messages from lost message store */
-  private _getMessages(connectionId: string): ServerMessage[] {
+  //TODO Change it to private
+  public _getMessages(connectionId: string): ServerMessage[] {
     const messages = this._lostMessages.get(connectionId);
 
     if (messages) {

+ 14 - 0
test/peer.ts

@@ -0,0 +1,14 @@
+import { expect } from "chai";
+import { Peer } from "../lib/peer";
+
+describe("Peer", function () {
+    describe("after construct without parameters", function () {
+        it("shouldn't contains any connection", function () {
+            const peer = new Peer();
+            expect(peer.connections).to.deep.eq({});
+            expect(peer.id).to.be.undefined;
+            expect(peer.disconnected).to.be.false;
+            expect(peer.destroyed).to.be.false;
+        });
+    });
+});

+ 6 - 0
tsconfig.json

@@ -0,0 +1,6 @@
+{
+    "compilerOptions": {
+        "target": "es6",
+        "downlevelIteration": true
+    }
+}