Selaa lähdekoodia

fix ts errors

afrokick 6 vuotta sitten
vanhempi
commit
5797076f12
6 muutettua tiedostoa jossa 24 lisäystä ja 20 poistoa
  1. 5 4
      index.d.ts
  2. 1 1
      lib/adapter.ts
  3. 4 2
      lib/dataconnection.ts
  4. 11 8
      lib/mediaconnection.ts
  5. 1 3
      lib/peer.ts
  6. 2 2
      lib/util.ts

+ 5 - 4
index.d.ts

@@ -160,24 +160,25 @@ declare namespace Peer {
     label: string;
     label: string;
     metadata: any;
     metadata: any;
     open: boolean;
     open: boolean;
-    peerConnection: any;
+    peerConnection: RTCPeerConnection;
     peer: string;
     peer: string;
     reliable: boolean;
     reliable: boolean;
     serialization: string;
     serialization: string;
     type: string;
     type: string;
-    buffSize: number;
+    bufferSize: number;
   }
   }
 
 
   interface MediaConnection {
   interface MediaConnection {
-    answer(stream?: any): void;
+    answer(stream?: MediaStream): void;
     close(): void;
     close(): void;
     on(event: string, cb: () => void): void;
     on(event: string, cb: () => void): void;
-    on(event: "stream", cb: (stream: any) => void): void;
+    on(event: "stream", cb: (stream: MediaStream) => void): void;
     on(event: "close", cb: () => void): void;
     on(event: "close", cb: () => void): void;
     on(event: "error", cb: (err: any) => void): void;
     on(event: "error", cb: (err: any) => void): void;
     off(event: string, fn: Function, once?: boolean): void;
     off(event: string, fn: Function, once?: boolean): void;
     open: boolean;
     open: boolean;
     metadata: any;
     metadata: any;
+    peerConnection: RTCPeerConnection;
     peer: string;
     peer: string;
     type: string;
     type: string;
   }
   }

+ 1 - 1
lib/adapter.ts

@@ -1,4 +1,4 @@
-import webrtc from "webrtc-adapter";
+import "webrtc-adapter";
 
 
 export const RTCSessionDescription =
 export const RTCSessionDescription =
   // @ts-ignore
   // @ts-ignore

+ 4 - 2
lib/dataconnection.ts

@@ -34,10 +34,12 @@ export class DataConnection extends BaseConnection {
   private _dc: RTCDataChannel;
   private _dc: RTCDataChannel;
   private _reliable: Reliable;
   private _reliable: Reliable;
 
 
-  get dataChannel() {
+  get dataChannel(): RTCDataChannel {
     return this._dc;
     return this._dc;
   }
   }
 
 
+  get bufferSize(): number { return this._bufferSize; }
+
   constructor(peerId: string, provider: Peer, options: any) {
   constructor(peerId: string, provider: Peer, options: any) {
     super(peerId, provider, options);
     super(peerId, provider, options);
 
 
@@ -91,7 +93,7 @@ export class DataConnection extends BaseConnection {
         this._handleDataMessage(e);
         this._handleDataMessage(e);
       };
       };
     }
     }
-    this.dataChannel.onclose = (e) => {
+    this.dataChannel.onclose = () => {
       util.log("DataChannel closed for:", this.peer);
       util.log("DataChannel closed for:", this.peer);
       this.close();
       this.close();
     };
     };

+ 11 - 8
lib/mediaconnection.ts

@@ -11,24 +11,27 @@ import { ServerMessage } from "./servermessage";
 export class MediaConnection extends BaseConnection {
 export class MediaConnection extends BaseConnection {
   private static readonly ID_PREFIX = "mc_";
   private static readonly ID_PREFIX = "mc_";
 
 
-  private localStream: MediaStream;
-  private remoteStream: MediaStream;
+  private _localStream: MediaStream;
+  private _remoteStream: MediaStream;
 
 
   get type() {
   get type() {
     return ConnectionType.Media;
     return ConnectionType.Media;
   }
   }
 
 
+  get localStream(): MediaStream { return this._localStream; }
+  get remoteStream(): MediaStream { return this._remoteStream; }
+
   constructor(peerId: string, provider: Peer, options: any) {
   constructor(peerId: string, provider: Peer, options: any) {
     super(peerId, provider, options);
     super(peerId, provider, options);
 
 
-    this.localStream = this.options._stream;
+    this._localStream = this.options._stream;
     this.connectionId =
     this.connectionId =
       this.options.connectionId ||
       this.options.connectionId ||
       MediaConnection.ID_PREFIX + util.randomToken();
       MediaConnection.ID_PREFIX + util.randomToken();
 
 
-    if (this.localStream) {
+    if (this._localStream) {
       Negotiator.startConnection(this, {
       Negotiator.startConnection(this, {
-        _stream: this.localStream,
+        _stream: this._localStream,
         originator: true
         originator: true
       });
       });
     }
     }
@@ -37,7 +40,7 @@ export class MediaConnection extends BaseConnection {
   addStream(remoteStream) {
   addStream(remoteStream) {
     util.log("Receiving stream", remoteStream);
     util.log("Receiving stream", remoteStream);
 
 
-    this.remoteStream = remoteStream;
+    this._remoteStream = remoteStream;
     super.emit(ConnectionEventType.Stream, remoteStream); // Should we call this `open`?
     super.emit(ConnectionEventType.Stream, remoteStream); // Should we call this `open`?
   }
   }
 
 
@@ -61,7 +64,7 @@ export class MediaConnection extends BaseConnection {
   }
   }
 
 
   answer(stream: MediaStream): void {
   answer(stream: MediaStream): void {
-    if (this.localStream) {
+    if (this._localStream) {
       util.warn(
       util.warn(
         "Local stream already exists on this MediaConnection. Are you answering a call twice?"
         "Local stream already exists on this MediaConnection. Are you answering a call twice?"
       );
       );
@@ -70,7 +73,7 @@ export class MediaConnection extends BaseConnection {
 
 
     this.options._payload._stream = stream;
     this.options._payload._stream = stream;
 
 
-    this.localStream = stream;
+    this._localStream = stream;
     Negotiator.startConnection(this, this.options._payload);
     Negotiator.startConnection(this, this.options._payload);
     // Retrieve lost messages stored because PeerConnection not set up.
     // Retrieve lost messages stored because PeerConnection not set up.
     const messages = this.provider._getMessages(this.connectionId);
     const messages = this.provider._getMessages(this.connectionId);

+ 1 - 3
lib/peer.ts

@@ -92,10 +92,8 @@ export class Peer extends EventEmitter {
       options = id;
       options = id;
       id = undefined;
       id = undefined;
     } else if (id) {
     } else if (id) {
-      // Ensure id is a string
       id = id.toString();
       id = id.toString();
     }
     }
-    //
 
 
     // Configurize options
     // Configurize options
     options = {
     options = {
@@ -542,7 +540,7 @@ export class Peer extends EventEmitter {
    * the cloud server, email team@peerjs.com to get the functionality enabled for
    * the cloud server, email team@peerjs.com to get the functionality enabled for
    * your key.
    * your key.
    */
    */
-  listAllPeers(cb = (arg: any[]) => { }): void {
+  listAllPeers(cb = (_: any[]) => { }): void {
     this._api.listAllPeers()
     this._api.listAllPeers()
       .then(peers => cb(peers))
       .then(peers => cb(peers))
       .catch(error => this._abort(PeerErrorType.ServerError, error));
       .catch(error => this._abort(PeerErrorType.ServerError, error));

+ 2 - 2
lib/util.ts

@@ -232,8 +232,8 @@ export class util {
     err ? console.error.apply(console, copy) : console.log.apply(console, copy);
     err ? console.error.apply(console, copy) : console.log.apply(console, copy);
   }
   }
 
 
-  static warn(...rest): void { }
-  static error(...rest): void { }
+  static warn(..._): void { }
+  static error(..._): void { }
 
 
   // Binary stuff
   // Binary stuff