浏览代码

Merge pull request #505 from afrokick/refactoring/format

format code with standart
afrokick 6 年之前
父节点
当前提交
946e74f77b
共有 3 个文件被更改,包括 26 次插入26 次删除
  1. 8 8
      lib/dataconnection.ts
  2. 8 8
      lib/negotiator.ts
  3. 10 10
      lib/util.ts

+ 8 - 8
lib/dataconnection.ts

@@ -72,7 +72,7 @@ export class DataConnection extends BaseConnection {
 
     const self = this;
 
-    this.dataChannel.onopen = function() {
+    this.dataChannel.onopen = function () {
       util.log("Data channel connection success");
       self._open = true;
       self.emit(ConnectionEventType.Open);
@@ -84,15 +84,15 @@ export class DataConnection extends BaseConnection {
     }
 
     if (this._reliable) {
-      this._reliable.onmessage = function(msg) {
+      this._reliable.onmessage = function (msg) {
         self.emit(ConnectionEventType.Data, msg);
       };
     } else {
-      this.dataChannel.onmessage = function(e) {
+      this.dataChannel.onmessage = function (e) {
         self._handleDataMessage(e);
       };
     }
-    this.dataChannel.onclose = function(e) {
+    this.dataChannel.onclose = function (e) {
       util.log("DataChannel closed for:", self.peer);
       self.close();
     };
@@ -111,7 +111,7 @@ export class DataConnection extends BaseConnection {
         const self = this;
 
         // Datatype should never be blob
-        util.blobToArrayBuffer(data, function(ab) {
+        util.blobToArrayBuffer(data, function (ab) {
           data = util.unpack(ab);
           self.emit(ConnectionEventType.Data, data);
         });
@@ -213,13 +213,13 @@ export class DataConnection extends BaseConnection {
 
       // DataChannel currently only supports strings.
       if (!util.supports.sctp) {
-        util.blobToBinaryString(blob, function(str) {
+        util.blobToBinaryString(blob, function (str) {
           self._bufferedSend(str);
         });
       } else if (!util.supports.binaryBlob) {
         // We only do this if we really need to (e.g. blobs are not supported),
         // because this conversion is costly.
-        util.blobToArrayBuffer(blob, function(ab) {
+        util.blobToArrayBuffer(blob, function (ab) {
           self._bufferedSend(ab);
         });
       } else {
@@ -246,7 +246,7 @@ export class DataConnection extends BaseConnection {
 
       const self = this;
 
-      setTimeout(function() {
+      setTimeout(function () {
         // Try again.
         self._buffering = false;
         self._tryBuffer();

+ 8 - 8
lib/negotiator.ts

@@ -66,7 +66,7 @@ class Negotiator {
     if (!this.pcs[connection.type]) {
       util.error(
         connection.type +
-          " is not a valid connection type. Maybe you overrode the `type` property somewhere."
+        " is not a valid connection type. Maybe you overrode the `type` property somewhere."
       );
     }
 
@@ -129,7 +129,7 @@ class Negotiator {
     // ICE CANDIDATES.
     util.log("Listening for ICE candidates.");
 
-    peerConnection.onicecandidate = function(evt) {
+    peerConnection.onicecandidate = function (evt) {
       if (evt.candidate) {
         util.log("Received ICE candidates for:", peerId);
         provider.socket.send({
@@ -144,12 +144,12 @@ class Negotiator {
       }
     };
 
-    peerConnection.oniceconnectionstatechange = function() {
+    peerConnection.oniceconnectionstatechange = function () {
       switch (peerConnection.iceConnectionState) {
         case "failed":
           util.log(
             "iceConnectionState is disconnected, closing connections to " +
-              peerId
+            peerId
           );
           connection.emit(
             ConnectionEventType.Error,
@@ -160,7 +160,7 @@ class Negotiator {
         case "disconnected":
           util.log(
             "iceConnectionState is disconnected, closing connections to " +
-              peerId
+            peerId
           );
           break;
         case "completed":
@@ -177,7 +177,7 @@ class Negotiator {
     util.log("Listening for data channel");
     // Fired between offer and answer, so options should already be saved
     // in the options hash.
-    peerConnection.ondatachannel = function(evt) {
+    peerConnection.ondatachannel = function (evt) {
       util.log("Received data channel");
 
       const dataChannel = evt.channel;
@@ -191,7 +191,7 @@ class Negotiator {
     // MEDIACONNECTION.
     util.log("Listening for remote stream");
     const self = this;
-    peerConnection.ontrack = function(evt) {
+    peerConnection.ontrack = function (evt) {
       util.log("Received remote stream");
 
       const stream = evt.streams[0];
@@ -399,7 +399,7 @@ class Negotiator {
   ): void {
     util.log(
       `add stream ${stream.id} to media connection ${
-        mediaConnection.connectionId
+      mediaConnection.connectionId
       }`
     );
 

+ 10 - 10
lib/util.ts

@@ -20,7 +20,7 @@ export enum DebugLevel {
 }
 
 export class util {
-  static noop(): void {}
+  static noop(): void { }
 
   static readonly CLOUD_HOST = "0.peerjs.com";
   static readonly CLOUD_PORT = 443;
@@ -65,7 +65,7 @@ export class util {
   }
 
   private static _printWith(prefix) {
-    return function() {
+    return function () {
       const copy = Array.prototype.slice.call(arguments);
       copy.unshift(prefix);
       util._print.apply(util, copy);
@@ -92,7 +92,7 @@ export class util {
   static readonly defaultConfig = DEFAULT_CONFIG;
 
   // Returns the current browser.
-  static readonly browser: string = (function(global) {
+  static readonly browser: string = (function (global) {
     // @ts-ignore
     if (global.mozRTCPeerConnection) {
       return "Firefox";
@@ -110,7 +110,7 @@ export class util {
   })(window);
 
   // Lists which features are supported
-  static readonly supports = (function() {
+  static readonly supports = (function () {
     if (typeof RTCPeerConnection === "undefined") {
       return {};
     }
@@ -147,7 +147,7 @@ export class util {
       try {
         dc.binaryType = "blob";
         binaryBlob = true;
-      } catch (e) {}
+      } catch (e) { }
 
       // Reliable test.
       // Unfortunately Chrome is a bit unreliable about whether or not they
@@ -159,7 +159,7 @@ export class util {
           {}
         );
         sctp = reliableDC.reliable;
-      } catch (e) {}
+      } catch (e) { }
       reliablePC.close();
     }
 
@@ -252,8 +252,8 @@ export class util {
     err ? console.error.apply(console, copy) : console.log.apply(console, copy);
   }
 
-  static warn(...rest): void {}
-  static error(...rest): void {}
+  static warn(...rest): void { }
+  static error(...rest): void { }
 
   static setZeroTimeout = (global => {
     const timeouts = [];
@@ -328,7 +328,7 @@ export class util {
   static blobToArrayBuffer(blob: Blob, cb: (arg: any) => void): void {
     const fr = new FileReader();
 
-    fr.onload = function(evt) {
+    fr.onload = function (evt) {
       // @ts-ignore
       cb(evt.target.result);
     };
@@ -339,7 +339,7 @@ export class util {
   static blobToBinaryString(blob: Blob, cb: (arg: any) => void): void {
     const fr = new FileReader();
 
-    fr.onload = function(evt) {
+    fr.onload = function (evt) {
       // @ts-ignore
       cb(evt.target.result);
     };