Преглед на файлове

docs: inline documentation (#1040)

This PR
- removes the outdated `docs/` folder.
- moves its contents to JSDoc-style comments

This was a quick & dirty copy-paste job. Documentation will need a lot
more work.
Jonas Gloning преди 2 години
родител
ревизия
61c61354bd
променени са 19 файла, в които са добавени 272 реда и са изтрити 2067 реда
  1. 0 552
      docs/api.json
  2. 0 4
      docs/api.md
  3. 0 13
      docs/build.js
  4. 0 393
      docs/css/docs.css
  5. 0 753
      docs/index.html
  6. 0 79
      docs/js/docs.js
  7. 0 3
      docs/js/jquery.min.js
  8. 0 21
      docs/package.json
  9. 0 6
      docs/readme.md
  10. 0 212
      docs/template.html
  11. 20 0
      lib/baseconnection.ts
  12. 32 3
      lib/dataconnection.ts
  13. 42 0
      lib/enums.ts
  14. 6 4
      lib/exports.ts
  15. 12 0
      lib/logger.ts
  16. 23 3
      lib/mediaconnection.ts
  17. 24 0
      lib/optionInterfaces.ts
  18. 73 19
      lib/peer.ts
  19. 40 2
      lib/util.ts

+ 0 - 552
docs/api.json

@@ -1,552 +0,0 @@
-[
-  {
-    "name": "Peer",
-    "type": "constructor",
-    "snippet": "const peer = new Peer([id], [options]);",
-    "description": "A peer can connect to other peers and listen for connections.",
-    "children": [
-      {
-        "name": "id",
-        "optional": true,
-        "type": "string",
-        "description": "Other peers can connect to this peer using the provided ID. If no ID is given, one will be generated by the brokering server. The ID must start and end with an alphanumeric character (lower or upper case character or a digit). In the middle of the ID spaces, dashes (-) and underscores (_) are allowed.<span class='warn'>It's not recommended that you use this ID to identify peers, as it's meant to be used for brokering connections only. You're recommended to set the <a href='#peerconnect-options'><code>metadata</code></a> option to send other identifying information.</span>"
-      },
-      {
-        "name": "options",
-        "optional": true,
-        "type": "object",
-        "children": [
-          {
-            "name": "key",
-            "type": "string",
-            "description": "API key for the cloud PeerServer. This is not used for servers other than <code>0.peerjs.com</code>.<span class='warn'>PeerServer cloud runs on port 443. Please ensure it is not blocked or consider running your own PeerServer instead.</span>"
-          },
-          {
-            "name": "host",
-            "type": "string",
-            "description": "Server host. Defaults to <code>0.peerjs.com</code>. Also accepts <code>'/'</code> to signify relative hostname."
-          },
-          {
-            "name": "port",
-            "type": "number",
-            "description": "Server port. Defaults to <code>443</code>."
-          },
-          {
-            "name": "pingInterval",
-            "type": "number",
-            "description": "Ping interval in ms. Defaults to <code>5000</code>."
-          },
-          {
-            "name": "path",
-            "type": "string",
-            "description": "The path where your self-hosted PeerServer is running. Defaults to <code>'/'</code>."
-          },
-          {
-            "name": "secure",
-            "type": "boolean",
-            "description": "<code>true</code> if you're using SSL.<span class='tip'>Note that our cloud-hosted server and assets may not support SSL.</span>"
-          },
-          {
-            "name": "config",
-            "type": "object",
-            "description": "Configuration hash passed to RTCPeerConnection. This hash contains any custom ICE/TURN server configuration. Defaults to <code>{ 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' }, { 'urls': 'turn:0.peerjs.com:3478', username: 'peerjs', credential: 'peerjsp' }], 'sdpSemantics': 'unified-plan' }</code>"
-          },
-          {
-            "name": "debug",
-            "type": "number",
-            "description": "Prints log messages depending on the debug level passed in. Defaults to <code>0</code>.",
-            "children": [
-              {
-                "name": 0,
-                "description": "Prints no logs."
-              },
-              {
-                "name": 1,
-                "description": "Prints only errors."
-              },
-              {
-                "name": 2,
-                "description": "Prints errors and warnings."
-              },
-              {
-                "name": 3,
-                "description": "Prints all logs."
-              }
-            ]
-          }
-        ]
-      }
-    ]
-  },
-  {
-    "name": "peer.connect",
-    "type": "method",
-    "snippet": "const <a href='#dataconnection'>dataConnection</a> = peer.connect(id, [options]);",
-    "description": "Connects to the remote peer specified by <code>id</code> and returns a data connection. Be sure to listen on the <a href='#peeron-error'><code>error</code></a> event in case the connection fails.",
-    "children": [
-      {
-        "name": "id",
-        "type": "string",
-        "description": "The brokering ID of the remote peer (their <a href='#peerid'><code>peer.id</code></a>)."
-      },
-      {
-        "name": "options",
-        "optional": true,
-        "type": "object",
-        "children": [
-          {
-            "name": "label",
-            "type": "string",
-            "description": "A unique label by which you want to identify this data connection. If left unspecified, a label will be generated at random. Can be accessed with <a href='#dataconnection-label'><code>dataConnection.label</code></a>."
-          },
-          {
-            "name": "metadata",
-            "description": "Metadata associated with the connection, passed in by whoever initiated the connection. Can be accessed with <a href='#dataconnection-metadata'><code>dataConnection.metadata</code></a>. Can be any serializable type."
-          },
-          {
-            "name": "serialization",
-            "type": "string",
-            "description": "Can be <code>binary</code> (default), <code>binary-utf8</code>, <code>json</code>, or <code>none</code>. Can be accessed with <a href='#dataconnection-serialization'><code>dataConnection.serialization</code></a>.<span class='tip'><code>binary-utf8</code> will take a performance hit because of the way UTF8 strings are packed into binary format.</span>"
-          },
-          {
-            "name": "reliable",
-            "type": "boolean",
-            "description": "Whether the underlying data channels should be reliable (e.g. for large file transfers) or not (e.g. for gaming or streaming). Defaults to <code>false</code>.<span class='warn'>Setting reliable to true will use a shim for incompatible browsers (Chrome 30 and below only) and thus may not offer full performance.</span>"
-          }
-        ]
-      }
-    ]
-  },
-  {
-    "name": "peer.call",
-    "type": "method",
-    "snippet": "const <a href='#mediaconnection'>mediaConnection</a> = peer.call(id, stream, [options]);",
-    "description": "Calls the remote peer specified by <code>id</code> and returns a media connection. Be sure to listen on the <a href='#peeron-error'><code>error</code></a> event in case the connection fails.",
-    "children": [
-      {
-        "name": "id",
-        "type": "string",
-        "description": "The brokering ID of the remote peer (their <a href='#peerid'><code>peer.id</code></a>)."
-      },
-      {
-        "name": "stream",
-        "type": "MediaStream",
-        "description": "The caller's media stream"
-      },
-      {
-        "name": "options",
-        "optional": true,
-        "type": "object",
-        "children": [
-          {
-            "name": "metadata",
-            "description": "Metadata associated with the connection, passed in by whoever initiated the connection. Can be accessed with <a href='#mediaconnection-metadata'><code>mediaConnection.metadata</code></a>. Can be any serializable type."
-          },
-          {
-            "name": "sdpTransform",
-            "type": "method",
-            "description": "Function which runs before create offer to modify sdp offer message."
-          }
-        ]
-      }
-    ]
-  },
-  {
-    "name": "peer.on",
-    "type": "method",
-    "snippet": "peer.on(event, callback);",
-    "description": "Set listeners for peer events.",
-    "children": [
-      {
-        "name": "'open'",
-        "type": "event",
-        "snippet": "peer.on('open', function(id) { ... });",
-        "description": "Emitted when a connection to the PeerServer is established. You may use the peer before this is emitted, but messages to the server will be queued. <code>id</code> is the brokering ID of the peer (which was either provided in the constructor or assigned by the server).<span class='tip'>You should not wait for this event before connecting to other peers if connection speed is important.</span>"
-      },
-      {
-        "name": "'connection'",
-        "type": "event",
-        "snippet": "peer.on('connection', function(<a href='#dataconnection'>dataConnection</a>) { ... });",
-        "description": "Emitted when a new data connection is established from a remote peer."
-      },
-      {
-        "name": "'call'",
-        "type": "event",
-        "snippet": "peer.on('call', function(<a href='#mediaconnection'>mediaConnection</a>) { ... });",
-        "description": "Emitted when a remote peer attempts to call you. The emitted <code>mediaConnection</code> is not yet active; you must first answer the call (<a href='#mediaconnection-answer'><code>mediaConnection.answer([stream]);</code></a>). Then, you can listen for the <a href='#mediaconnection-on'><code>stream</code></a> event."
-      },
-      {
-        "name": "'close'",
-        "type": "event",
-        "snippet": "peer.on('close', function() { ... });",
-        "description": "Emitted when the peer is <a href='#peerdestroy'>destroyed</a> and can no longer accept or create any new connections. At this time, the peer's connections will all be closed. <span class='tip'>To be extra certain that peers clean up correctly, we recommend calling <code>peer.destroy()</code> on a peer when it is no longer needed.</span>"
-      },
-      {
-        "name": "'disconnected'",
-        "type": "event",
-        "snippet": "peer.on('disconnected', function() { ... });",
-        "description": "Emitted when the peer is disconnected from the signalling server, either <a href='#peerdisconnect'>manually</a> or because the connection to the signalling server was lost. When a peer is disconnected, its existing connections will stay alive, but the peer cannot accept or create any new connections. You can reconnect to the server by calling <a href='#peerreconnect'><code>peer.reconnect()</code></a>."
-      },
-      {
-        "name": "'error'",
-        "type": "event",
-        "snippet": "peer.on('error', function(err) { ... });",
-        "description": "Errors on the peer are <strong>almost always fatal</strong> and will destroy the peer. Errors from the underlying socket and PeerConnections are forwarded here.<br><br>These come in the following <code>err.type</code> flavors:",
-        "children": [
-          {
-            "name": "'browser-incompatible'",
-            "type": "Error",
-            "tags": [
-              "fatal"
-            ],
-            "description": "The client's browser does not support some or all WebRTC features that you are trying to use."
-          },
-          {
-            "name": "'disconnected'",
-            "type": "Error",
-            "description": "You've already disconnected this peer from the server and can no longer make any new connections on it."
-          },
-          {
-            "name": "'invalid-id'",
-            "type": "Error",
-            "tags": [
-              "fatal"
-            ],
-            "description": "The ID passed into the Peer constructor contains illegal characters."
-          },
-          {
-            "name": "'invalid-key'",
-            "type": "Error",
-            "tags": [
-              "fatal"
-            ],
-            "description": "The API key passed into the Peer constructor contains illegal characters or is not in the system (cloud server only)."
-          },
-          {
-            "name": "'network'",
-            "type": "Error",
-            "description": "Lost or cannot establish a connection to the signalling server."
-          },
-          {
-            "name": "'peer-unavailable'",
-            "type": "Error",
-            "description": "The peer you're trying to connect to does not exist."
-          },
-          {
-            "name": "'ssl-unavailable'",
-            "type": "Error",
-            "tags": [
-              "fatal"
-            ],
-            "description": "PeerJS is being used securely, but the cloud server does not support SSL. Use a custom PeerServer."
-          },
-          {
-            "name": "'server-error'",
-            "type": "Error",
-            "tags": [
-              "fatal"
-            ],
-            "description": "Unable to reach the server."
-          },
-          {
-            "name": "'socket-error'",
-            "type": "Error",
-            "tags": [
-              "fatal"
-            ],
-            "description": "An error from the underlying socket."
-          },
-          {
-            "name": "'socket-closed'",
-            "type": "Error",
-            "tags": [
-              "fatal"
-            ],
-            "description": "The underlying socket closed unexpectedly."
-          },
-          {
-            "name": "'unavailable-id'",
-            "type": "Error",
-            "tags": [
-              "sometimes fatal"
-            ],
-            "description": "The ID passed into the Peer constructor is already taken.<span class='warn'>This error is not fatal if your peer has open peer-to-peer connections. This can happen if you attempt to <a href='#peerreconnect'>reconnect</a> a peer that has been <a href='#peerdisconnect'>disconnected from the server</a>, but its old ID has now been taken.</span>"
-          },
-          {
-            "name": "'webrtc'",
-            "type": "Error",
-            "description": "Native WebRTC errors."
-          }
-        ]
-      }
-    ]
-  },
-  {
-    "name": "peer.disconnect",
-    "type": "method",
-    "snippet": "peer.disconnect();",
-    "description": "Close the connection to the server, leaving all existing data and media connections intact. <a href='#peerdisconnected'><code>peer.disconnected</code></a> will be set to <code>true</code> and the <a href='#peeron-disconnected'><code>disconnected</code></a> event will fire.<span class='warn'>This cannot be undone; the respective peer object will no longer be able to create or receive any connections and its ID will be forfeited on the (cloud) server.</span>"
-  },
-  {
-    "name": "peer.reconnect",
-    "type": "method",
-    "snippet": "peer.reconnect();",
-    "description": "Attempt to reconnect to the server with the peer's old ID. Only <a href='#peerdisconnect'>disconnected peers</a> can be reconnected. Destroyed peers cannot be reconnected. If the connection fails (as an example, if the peer's old ID is now taken), the peer's existing connections will not close, but any associated errors events will fire."
-  },
-  {
-    "name": "peer.destroy",
-    "type": "method",
-    "snippet": "peer.destroy();",
-    "description": "Close the connection to the server and terminate all existing connections. <a href='#peerdestroyed'><code>peer.destroyed</code></a> will be set to <code>true</code>.<span class='warn'>This cannot be undone; the respective peer object will no longer be able to create or receive any connections, its ID will be forfeited on the (cloud) server, and all of its data and media connections will be closed.</span>"
-  },
-  {
-    "name": "peer.id",
-    "type": "string",
-    "description": "The brokering ID of this peer. If no ID was specified in <a href='#peer'>the constructor</a>, this will be <code>undefined</code> until the <a href='#peeron-open'><code>open</code></a> event is emitted."
-  },
-  {
-    "name": "peer.connections",
-    "type": "object",
-    "description": "A hash of all connections associated with this peer, keyed by the remote peer's ID.<span class='tip'>We recommend keeping track of connections yourself rather than relying on this hash.</span>"
-  },
-  {
-    "name": "peer.disconnected",
-    "type": "boolean",
-    "description": "<code>false</code> if there is an active connection to the PeerServer."
-  },
-  {
-    "name": "peer.destroyed",
-    "type": "boolean",
-    "description": "<code>true</code> if this peer and all of its connections can no longer be used."
-  },
-  {
-    "name": "DataConnection",
-    "type": "class",
-    "description": "Wraps WebRTC's DataChannel. To get one, use <a href='#peerconnect'><code>peer.connect</code></a> or listen for the <a href='#peeron-connect'><code>connect</code></a> event.",
-    "children": [
-      {
-        "name": ".send",
-        "type": "method",
-        "snippet": "dataConnection.send(data);",
-        "description": "<code>data</code> is serialized by BinaryPack by default and sent to the remote peer.",
-        "children": {
-          "name": "data",
-          "description": "You can send any type of data, including objects, strings, and blobs."
-        }
-      },
-      {
-        "name": ".close",
-        "type": "method",
-        "snippet": "dataConnection.close();",
-        "description": "Closes the data connection gracefully, cleaning up underlying DataChannels and PeerConnections."
-      },
-      {
-        "name": ".on",
-        "type": "method",
-        "snippet": "dataConnection.on(event, callback);",
-        "description": "Set listeners for data connection events.",
-        "children": [
-          {
-            "name": "'data'",
-            "type": "event",
-            "snippet": "dataConnection.on('data', function(data) { ... });",
-            "description": "Emitted when data is received from the remote peer."
-          },
-          {
-            "name": "'open'",
-            "type": "event",
-            "snippet": "dataConnection.on('open', function() { ... });",
-            "description": "Emitted when the connection is established and ready-to-use."
-          },
-          {
-            "name": "'close'",
-            "type": "event",
-            "snippet": "dataConnection.on('close', function() { ... });",
-            "description": "Emitted when either you or the remote peer closes the data connection.<span class='warn'>Firefox does not yet support this event.</span>"
-          },
-          {
-            "name": "'error'",
-            "type": "event",
-            "snippet": "dataConnection.on('error', function(err) { ... });"
-          }
-        ]
-      },
-      {
-        "name": ".dataChannel",
-        "type": "object",
-        "description": "A reference to the RTCDataChannel object associated with the connection."
-      },
-      {
-        "name": ".label",
-        "type": "string",
-        "description": "The optional label passed in or assigned by PeerJS when the connection was initiated."
-      },
-      {
-        "name": ".metadata",
-        "description": "Any type of metadata associated with the connection, passed in by whoever initiated the connection."
-      },
-      {
-        "name": ".open",
-        "type": "boolean",
-        "description": "This is true if the connection is open and ready for read/write."
-      },
-      {
-        "name": ".peerConnection",
-        "type": "object",
-        "description": "A reference to the RTCPeerConnection object associated with the connection."
-      },
-      {
-        "name": ".peer",
-        "type": "string",
-        "description": "The ID of the peer on the other end of this connection."
-      },
-      {
-        "name": ".reliable",
-        "type": "boolean",
-        "description": "Whether the underlying data channels are reliable; defined when the connection was initiated."
-      },
-      {
-        "name": ".serialization",
-        "type": "string",
-        "description": "The serialization format of the data sent over the connection. Can be <code>binary</code> (default), <code>binary-utf8</code>, <code>json</code>, or <code>none</code>."
-      },
-      {
-        "name": ".type",
-        "type": "string",
-        "description": "For data connections, this is always <code>'data'</code>."
-      },
-      {
-        "name": ".bufferSize",
-        "type": "number",
-        "description": "The number of messages queued to be sent once the browser buffer is no longer full."
-      }
-    ]
-  },
-  {
-    "name": "MediaConnection",
-    "type": "class",
-    "description": "Wraps WebRTC's media streams. To get one, use <a href='#peercall'><code>peer.call</code></a> or listen for the <a href='#peeron-call'><code>call</code></a> event.",
-    "children": [
-      {
-        "name": ".answer",
-        "type": "method",
-        "snippet": "mediaConnection.answer([stream],[options]);",
-        "description": "When receiving a <a href='#peeron-call'><code>call</code></a> event on a peer, you can call <code>.answer</code> on the media connection provided by the callback to accept the call and optionally send your own media stream.",
-        "children": [
-          {
-            "name": "stream",
-            "optional": true,
-            "type": "MediaStream",
-            "description": "A WebRTC media stream from <a href='https://developer.mozilla.org/en-US/docs/Web/API/Navigator.getUserMedia'><code>getUserMedia</code></a>."
-          },
-          {
-            "name": "options",
-            "optional": true,
-            "type": "object",
-            "children": [
-              {
-                "name": "sdpTransform",
-                "type": "method",
-                "description": "Function which runs before create answer to modify sdp answer message."
-              }
-            ]
-          }
-        ]
-      },
-      {
-        "name": ".close",
-        "type": "method",
-        "snippet": "mediaConnection.close();",
-        "description": "Closes the media connection."
-      },
-      {
-        "name": ".on",
-        "type": "method",
-        "snippet": "mediaConnection.on(event, callback);",
-        "description": "Set listeners for media connection events.",
-        "children": [
-          {
-            "name": "'stream'",
-            "type": "event",
-            "snippet": "mediaConnection.on('stream', function(stream) { ... });",
-            "description": "Emitted when a remote peer adds a <code>stream</code>."
-          },
-          {
-            "name": "'close'",
-            "type": "event",
-            "snippet": "mediaConnection.on('close', function() { ... });",
-            "description": "Emitted when either you or the remote peer closes the media connection. <span class='warn'>Firefox does not yet support this event.</span>"
-          },
-          {
-            "name": "'error'",
-            "type": "event",
-            "snippet": "mediaConnection.on('error', function(err) { ... });"
-          }
-        ]
-      },
-      {
-        "name": ".open",
-        "type": "boolean",
-        "description": "Whether the media connection is active (e.g. your call has been answered). You can check this if you want to set a maximum wait time for a one-sided call."
-      },
-      {
-        "name": ".metadata",
-        "description": "Any type of metadata associated with the connection, passed in by whoever initiated the connection."
-      },
-      {
-        "name": ".peer",
-        "type": "string",
-        "description": "The ID of the peer on the other end of this connection."
-      },
-      {
-        "name": ".type",
-        "type": "string",
-        "description": "For media connections, this is always <code>'media'</code>."
-      }
-    ]
-  },
-  {
-    "name": "util",
-    "type": "object",
-    "tags": [
-      "utility"
-    ],
-    "description": "Provides a variety of helpful utilities.<span class='warn'>Only the utilities documented here are guaranteed to be present on <code>util</code>. Undocumented utilities can be removed without warning. We don't consider these to be 'breaking changes.'</span>",
-    "children": [
-      {
-        "name": ".browser",
-        "type": "string",
-        "snippet": "if (util.browser === 'firefox') { /* OK to peer with Firefox peers. */ }",
-        "description": "The current browser. This property can be useful in determining whether or not two peers can connect. For example, as of now data connections are not yet interoperable between major browsers. <code>util.browser</code> can currently have the values <code>'firefox'</code>, <code>'chrome'</code>, <code>'safari'</code>, <code>'edge'</code>, <code>'Not a supported browser.'</code>, or <code>'Not a browser.'</code> (unknown WebRTC-compatible agent)."
-      },
-      {
-        "name": ".supports",
-        "type": "object",
-        "snippet": "if (util.supports.data) { /* OK to start a data connection. */ }",
-        "description": "A hash of WebRTC features mapped to booleans that correspond to whether the feature is supported by the current browser.<span class='warn'>Only the properties documented here are guaranteed to be present on <code>util.supports</code>.</span>",
-        "children": [
-          {
-            "name": ".audioVideo",
-            "type": "boolean",
-            "description": "True if the current browser supports media streams and PeerConnection."
-          },
-          {
-            "name": ".data",
-            "type": "boolean",
-            "description": "True if the current browser supports DataChannel and PeerConnection."
-          },
-          {
-            "name": ".binary",
-            "type": "boolean",
-            "description": "True if the current browser supports binary DataChannels."
-          },
-          {
-            "name": ".reliable",
-            "type": "boolean",
-            "description": "True if the current browser supports reliable DataChannels."
-          }
-        ]
-      }
-    ]
-  }
-]

+ 0 - 4
docs/api.md

@@ -1,4 +0,0 @@
-# PeerJS API Reference
-
-We've moved! <a href="https://peerjs.com/docs.html#api">Check out our new API
-reference.</a>

+ 0 - 13
docs/build.js

@@ -1,13 +0,0 @@
-const fs = require('fs');
-const handlebars = require('handlebars');
-const reference = require('reference');
-
-const file = fs.readFileSync('./api.json');
-
-const template = handlebars.compile(
-  fs.readFileSync('./template.html', { encoding: 'utf8' })
-);
-fs.writeFileSync(
-  './index.html',
-  template({ html: reference(file, { anchor: true }) })
-);

+ 0 - 393
docs/css/docs.css

@@ -1,393 +0,0 @@
-html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,th,var,optgroup{font-style:inherit;font-weight:inherit;}del,ins{text-decoration:none;}li{list-style:none;}caption,th{text-align:left;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:baseline;}sub{vertical-align:baseline;}legend{color:#000;}input,button,textarea,select,optgroup,option{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;}input,button,textarea,select{font-size:100%;}
-a {outline: none;} /* Gets rid of Firefox's dotted borders */
-a img {border: none;} /* Gets rid of IE's blue borders */
-
-
-body, html {
-  font-size: 14px;
-  line-height: 24px;
-  font-family: "Lato", Helvetica, sans-serif;
-  color: #454545;
-}
-
-header.right, header.left {
-  cursor: pointer;
-  z-index: 100;
-  position: fixed;
-  top: 0;
-  height: 35px;
-  box-sizing: border-box;
-  -moz-box-sizing: border-box;
-}
-
-header.left {
-  border-bottom: 1px solid rgba(0,0,0,0.1);
-  border-right: 4px solid rgba(0,0,0,0.1);
-  background-color: #50484e;
-  text-align: right;
-  left: 0;
-  width: 47%;
-}
-header.right {
-  border-bottom: 1px solid rgba(0,0,0,0.1);
-  border-left: 4px solid rgba(0,0,0,0.1);
-  background-color: #eee;
-  text-align: left;
-  right: 0;
-  width: 53%;
-}
-
-.left h2, .right h2 {
-  color: #E2A62E;
-  letter-spacing: 1px;
-  text-transform: uppercase;
-  font-size: 14px;
-  margin: 0;
-  padding: 6px 10px;
-  text-shadow: 0 -1px 0 rgba(0,0,0,0.2);
-}
-
-.right h2 {
-  color: #5a5157;
-  text-shadow: 0 -1px 0 #fff;
-}
-
-.left .icon {
-  color: #E2A62E;
-  cursor: pointer;
-  font-family: monospace;
-  font-size: 20px;
-  display: inline-block;
-  margin-left: 5px;
-}
-
-.icon.show {
-  display: none;
-}
-
-
-.api, .start {
-  position: absolute;
-  top: 0px;
-  bottom: 0px;
-  overflow-y: scroll;
-  overflow-x: hidden;
-  box-sizing: border-box;
-  -moz-box-sizing: border-box;
-  transition: left 300ms;
-}
-
-.api.fullscreen {
-  width: 100%;
-}
-
-.start.full {
-  left: 30px;
-  width: auto;
-}
-
-/** hiding */
-.api.hidden {
-  left: -370px;
-  width: 400px;
-  overflow: hidden;
-}
-
-.api.hidden > div {
-  opacity: 0.6;
-}
-
-.start {
-  background-color: #fcfcfc;
-  width: 53%;
-  right: 0px;
-  top: 35px;
-  text-shadow: 0px -1px 0 #fff;
-  border-top: 1px solid #fff;
-  z-index: 99;
-  color: #645b61;
-}
-
-.start h1 {
-  margin: 0;
-  background-color: #fff;
-  font-size: 40px;
-  line-height: 40px;
-  padding: 30px 20px;
-  border-bottom: 1px solid #eee;
-  color: #5a5157;
-  border-left: 4px solid #ddd;
-}
-
-/** Code stylings */
-section.start pre {
-  font-family: Consolas, Inconsolata, 'Bitstream Vera Sans Mono', Menlo, Monaco, 'Andale Mono', 'Courier New', monospace;
-  font-size: 12px;
-  background-color: #474045;
-  border-left: 4px solid #40393e;
-  padding: 15px 30px 15px 40px;
-  color: #e7e0e5;
-  text-shadow: 0 -1px 0 rgba(0,0,0,0.1);
-  max-width: 100%;
-  overflow: auto;
-}
-/** /code */
-
-h1 a {
-  color: #5a5157;
-  text-decoration: none;
-  transition: color 300ms;
-}
-
-h1 a:hover {
-  color: #745e6d;
-}
-
-h1 .title {
-  color: #fff;
-  display: inline-block;
-  font-size: 15px;
-  text-transform: uppercase;
-  font-variant: small-caps;
-  background-color: #E2A62E;
-  padding: 2px 4px;
-  line-height: 15px;
-  border-radius: 2px;
-  border: 2px solid rgba(0,0,0,0.2);
-  text-shadow: 0 -1px 0 rgba(0,0,0,0.2);
-}
-
-.start > p, .start > div {
-  padding: 5px 30px 5px 40px;
-  border-left: 4px solid #ddd;
-}
-
-.start p.red {
-  color: #8F4537;
-}
-
-.start h2, .start h3, .start h4 {
-  color: #5a5157;
-  padding: 12px 25px 5px 25px;
-  margin: 0;
-  font-size: 20px;
-  border-left: 4px solid #ccc;
-}
-
-.start h3 {
-  font-size: 15px;
-  padding: 12px 25px 5px 25px;
-  border-bottom: 1px solid #eee;
-}
-
-a {
-  font-weight: 600;
-  color: #1295D8;
-  text-decoration: none;
-  transition: color 200ms;
-}
-a:hover {
-  color: #33a2dc;
-}
-
-
-.api {
-  color: #f5eff3;
-  font-weight: 300;
-  top: 35px;
-  left: 0px;
-  width: 47%;
-  border-right: 4px solid #474046;
-  border-top: 1px solid rgba(255,255,255,0.1);
-  background-color: #5a5157;
-  text-shadow: 0px -1px 0 #474045;
-  z-index: 100;
-}
-
-.child {
-  padding: 10px 0 10px 15px;
-}
-
-.bracket {
-  font-weight: 800;
-  display: inline-block;
-  margin: 0 2px;
-  color: rgba(255,255,255,0.2);
-}
-
-.toplevel {
-  border-bottom: 1px solid rgba(0,0,0,0.1);
-  padding: 30px 35px;
-}
-
-.api:not(:first-child) {
-  border-top: 1px solid rgba(255,255,255,0.1);
-}
-
-.toplevel > .children > .child {
-  padding-right: 5px;
-}
-
-.children {
-  border-left: 1px solid rgba(0,0,0,0.1);
-}
-
-.beta_030 .children {
-  border-left: 1px solid rgba(233, 97, 81, 0.5);
-}
-
-.api div p {
-  margin: 0 0 5px 0;
-}
-
-.child:hover {
-  background-color: #635960;
-}
-
-/** Label stylings */
-.tag {
-  display: inline-block;
-  background-color: #454545;
-  border-radius: 2px;
-  color: rgba(255,255,255,0.8);
-  line-height: 11px;
-  padding: 1px 2px;
-  margin-left: 5px;
-  font-size: 9px;
-  letter-spacing: 1px;
-  font-weight: 600;
-  font-family: "Lato", Helvetica, sans-serif;
-  text-transform: uppercase;
-  border: 1px solid rgba(0,0,0,0.4);
-  text-shadow: 0px -1px 0px rgba(0,0,0,0.2);
-}
-
-.tag.type {
-  background-color: #757E2B;
-}
-
-.tag.beta_030 {
-  background-color: #E96151;
-}
-
-.tag.method, .tag.function {
-  background-color: #E2A62E;
-}
-
-.tag.class, .tag.constructor, .tag.utility {
-  background-color: #468F81;
-}
-
-.tag.error {
-  background-color: #8F4537;
-}
-
-.tag.event {
-  background-color: #1295D8;
-}
-
-.toplevel > .name {
-  font-size: 20px;
-}
-
-/** /Label stylings */
-
-.api .snippet {
-  color: #a2949d;
-  border-left: 1px solid #40393e;
-  border-top: 1px solid #40393e;
-  border-right: 1px solid #6b666a;
-  border-bottom: 1px solid #6b666a;
-  text-shadow: 0 -1px 0 #393438;
-  font-size: 12px;
-  font-family: Consolas, Inconsolata, 'Bitstream Vera Sans Mono', Menlo, Monaco, 'Andale Mono', 'Courier New', monospace;
-  font-weight: 400;
-  display: inline-block;
-  background-color: #474045;
-  padding: 3px 8px;
-  margin: 5px 0 0 10px;
-}
-
-/* We want to be able to use the names as an anchor. */
-.api .name {
-  font-weight: 600;
-  display: inline-block;
-  margin-bottom: 5px;
-}
-
-.name a {
-  cursor: pointer;
-  color: #fff;
-  text-decoration: none;
-  transition: color 300ms;
-}
-
-.name a:hover {
-  color: #e7e0e5;
-}
-/* /name */
-
-.tip, .warn {
-  opacity: 0.9;
-  display: block;
-  background-color: #d1c7be;
-  font-size: 13px;
-  line-height: 18px;
-  border-radius: 2px;
-  padding: 5px 8px;
-  border: 2px solid rgba(0,0,0,0.2);
-  margin: 8px 8px 0 0;
-}
-
-.warn {
-  background-color: #8F4537;
-}
-.tip {
-  color: #544e4a;
-  text-shadow: 0px -1px 0px rgba(255,255,255,0.2);
-  font-weight: 600;
-}
-
-#peer-options-debug .child {
-  padding: 0 15px;
-}
-
-#peer-options-debug .child .description {
-  display: inline-block;
-  margin-left: 10px;
-}
-
-.start code, .api code {
-  font-family: Consolas, Inconsolata, 'Bitstream Vera Sans Mono', Menlo, Monaco, 'Andale Mono', 'Courier New', monospace;
-  border-radius: 2px;
-  border: 1px solid rgba(255,255,255,0.2);
-  background: rgba(255,255,255,0.1);
-  font-size: 12px;
-  padding: 2px;
-}
-
-.start code {
-  background-color: #f6eee8;
-  border: 1px solid #d1c7be;
-}
-
-.start > .two-col {
-  padding-left: 0;
-  padding-right: 0;
-}
-.two-col .col{
-  float: left;
-  width: 50%;
-}
-
-.two-col .col.col-header {
-  font-weight: 600;
-  box-sizing: border-box;
-  -moz-box-sizing: border-box;
-  padding-left: 20px;
-  padding-right: 20px;
-}
-
-.clear {
-  clear: both;
-}

+ 0 - 753
docs/index.html

@@ -1,753 +0,0 @@
-<head>
-  <title>PeerJS Documentation</title>
-  <meta name="viewport" content="width=device-width, maximum-scale=1">
-  <link href='https://fonts.googleapis.com/css?family=Lato:300,400,700,900' rel='stylesheet' type='text/css'>
-  <link href="/css/docs.css" rel="stylesheet" type="text/css">
-  <script type="text/javascript" src="/js/jquery.min.js"></script>
-  <script type="text/javascript" src="/js/docs.js"></script>
-</head>
-
-<body>
-  <section class="start">
-    <h1>
-      <a href="/">PeerJS</a>
-      <span class="title">docs</span>
-    </h1>
-    <p>
-      <br>PeerJS simplifies peer-to-peer data, video, and audio calls.</p>
-    <p>This guide will show you the basic concepts of the PeerJS API.</p>
-    <h2>Setup</h2>
-    <h3>1. Include the Javascript client</h3>
-    <p>Add the PeerJS client library to your webpage.</p>
-    <pre>&lt;script src="https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js"&gt;&lt;/script&gt;</pre>
-    <p>If you prefer, you can host it yourself:
-      <a download href="https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js">peerjs.min.js</a>, or
-      <a href="https://github.com/peers/peerjs">fork us on Github</a>.</p>
-    <h3>2. Create the Peer object</h3>
-    <p>The Peer object is where we create and receive connections.</p>
-    <pre>var peer = new Peer();</pre>
-    <p>PeerJS uses PeerServer for session
-      metadata and candidate signaling. You can also
-      <a href="https://github.com/peers/peerjs-server">run your own PeerServer</a> if you don't like the cloud.</p>
-    <p>We're now ready to start making connections!</p>
-
-    <h2>Usage</h2>
-    <p>Every Peer object is assigned a random, unique ID when it's created.</p>
-    <pre>peer.on('open', function(id) {
-  console.log('My peer ID is: ' + id);
-});</pre>
-    <p>When we want to connect to another peer, we'll need to know their peer id. You're in charge of communicating the
-      peer
-      IDs between users of your site. Optionally, you can pass in your own IDs to the
-      <a href="#peer">
-        <code>Peer</code> constructor
-      </a>.</p>
-
-    <p>Read the
-      <a href="#peer">Peer API reference</a> for complete information on its
-      <a href="#peer-options">options</a>, methods,
-      <a href="#peeron">events</a>, and
-      <a href="#peeron-error">error handling</a>.</p>
-
-    <h3>Data connections</h3>
-    <p>Start a data connection by calling
-      <code>peer.connect</code> with the peer ID of the destination peer. Anytime another peer attempts to connect to
-      your peer ID, you'll receive
-      a
-      <code>connection</code> event. </p>
-    <div class="two-col">
-      <div class="col col-header">Start connection</div>
-      <div class="col col-header">Receive connection</div>
-      <div class="col">
-        <pre>var conn = peer.connect('dest-peer-id');</pre>
-      </div>
-      <div class="col">
-        <pre>peer.on('connection', function(conn) { ... });</pre>
-      </div>
-      <div class="clear"></div>
-    </div>
-    <p>
-      <code>peer.connect</code> and the callback of the
-      <code>connection</code> event will both provide a
-      <code>DataConnection</code> object. This object will allow you to send and receive data:</p>
-    <pre>conn.on('open', function() {
-  // Receive messages
-  conn.on('data', function(data) {
-    console.log('Received', data);
-  });
-
-  // Send messages
-  conn.send('Hello!');
-});</pre>
-    <p>Read the
-      <a href="#dataconnection">DataConnection API reference</a> for complete details on its methods and events.</p>
-    <h3>Video/audio calls</h3>
-    <p>Call another peer by calling
-      <code>peer.call</code> with the peer ID of the destination peer. When a peer calls you, the
-      <code>call</code> event is emitted.</p>
-    <p>Unlike data connections, when receiving a
-      <code>call</code> event, the call must be answered or no connection is established.</p>
-    <div class="two-col">
-      <div class="col col-header">Start call</div>
-      <div class="col col-header">Answer call</div>
-      <div class="col">
-        <pre>// Call a peer, providing our mediaStream
-var call = peer.call('dest-peer-id',
-  mediaStream);
-
-</pre>
-      </div>
-      <div class="col">
-        <pre>peer.on('call', function(call) {
-  // Answer the call, providing our mediaStream
-  call.answer(mediaStream);
-});</pre>
-      </div>
-      <div class="clear"></div>
-    </div>
-    <p>When calling or answering a call, a MediaStream should be provided. The MediaStream represents the local video
-      (webcam)
-      or audio stream and can be obtained with some (browser-specific) version of
-      <a href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator.getUserMedia">
-        <code>navigator.getUserMedia</code>
-      </a>. When answering a call, the MediaStream is optional and if none is provided then a one-way call is
-      established.
-      Once the call is established, its
-      <code>open</code> property is set to true.</p>
-    <p>
-      <code>peer.call</code> and the callback of the
-      <code>call</code> event provide a MediaConnection object. The MediaConnection object itself emits a
-      <code>stream</code> event whose callback includes the video/audio stream of the other peer.</p>
-    <pre>call.on('stream', function(stream) {
-  // `stream` is the MediaStream of the remote peer.
-  // Here you'd add it to an HTML video/canvas element.
-});</pre>
-    <p>Read the
-      <a href="#mediaconnection">MediaConnection API reference</a> for complete details on its methods and events.</p>
-
-    <h2>Common questions</h2>
-
-    <h3>What kind of data can I send?</h3>
-
-    <p>PeerJS has the
-      <a href="https://github.com/binaryjs/js-binarypack">BinaryPack</a>
-      serialization format built-in. This means you can send any JSON type as well as binary Blobs and ArrayBuffers.
-      Simply send
-      arbitrary data and you'll get it out the other side:</p>
-    <pre>
-conn.send({
-  strings: 'hi!',
-  numbers: 150,
-  arrays: [1,2,3],
-  evenBinary: new Blob([1,2,3]),
-  andMore: {bool: true}
-});</pre>
-
-    <h3>Are there any caveats?</h3>
-
-    <p>A small percentage of users are behind symmetric NATs. When two symmetric NAT users try to connect to each other,
-      NAT
-      traversal is impossible and no connection can be made. A workaround is to proxy through the connection through a
-      TURN
-      server. The PeerServer cloud service provides a free TURN server. This will allow your PeerJS app to work
-      seamlessly for this situation</p>
-    <h3>How do I use a TURN server?</h3>
-    <p>When creating your Peer object, pass in the ICE servers as the config key of the options hash.</p>
-    <pre>
-var peer = new Peer({
-  config: {'iceServers': [
-    { url: 'stun:stun.l.google.com:19302' },
-    { url: 'turn:homeo@turn.bistri.com:80', credential: 'homeo' }
-  ]} /* Sample servers, please use appropriate ones */
-});
-</pre>
-    <h3>What if my peer has not yet connected to the server when I attempt to connect to it?</h3>
-
-    <p>When you try to connect to a peer, PeerServer will hold a connection offer for up to 5 seconds before rejecting
-      it. This
-      is useful if you want to reconnect to a peer as it disconnects and reconnects rapidly between web pages.</p>
-
-    <h3>Why am I unable to connect?</h3>
-    <p>You could be behind a symmetric NAT, in which case you'll need to set up a TURN server.</p>
-    <p>Another possible issue is your network blocking port 443, which the PeerServer cloud runs on. In this you must
-      use your
-      own PeerServer running on an appropriate port instead of the cloud service.</p>
-
-    <h3>What about latency/bandwidth?</h3>
-
-    <p>Data sent between the two peers do not touch any other servers, so the connection speed is limited only by the
-      upload
-      and download rates of the two peers. This also means you don't have the additional latency of an intermediary
-      server.</p>
-    <p>The latency to establish a connection can be split into two components: the brokering of data and the
-      identification
-      of clients. PeerJS has been designed to minimize the time you spend in these two areas. For brokering, data is
-      sent
-      through an XHR streaming request before a WebSocket connection is established, then through WebSockets. For client
-      identification, we provide you the ability to pass in your own peer IDs, thus eliminating the RTT for retrieving
-      an
-      ID from the server.</p>
-
-    <h3>More questions?</h3>
-    <p>
-      <a href="https://t.me/joinchat/ENhPuhTvhm8WlIxTjQf7Og">Discuss PeerJS on our Telegram channel.</a>
-      <br>
-      <br>
-    </p>
-  </section>
-
-  <header class="left">
-    <h2>API Reference
-      <a class="hide icon">&laquo;</a>
-      <a class="show icon">&raquo;</a>
-    </h2>
-  </header>
-  <header class="right">
-    <h2>Getting Started</h2>
-  </header>
-
-  <section class="api">
-    <div class="toplevel " id="peer"><span class="name"><a href="#peer">Peer</a><span
-          class="tag type constructor">constructor</span><span class="snippet">const peer = new Peer([id],
-          [options]);</span></span>
-      <p class="description">A peer can connect to other peers and listen for connections.</p>
-      <div class="children">
-        <div class="child " id="peer-id"><span class="name"><a href="#peer-id"><span class="optional"><span
-                  class="bracket">[</span>id<span class="bracket">]</span></span></a><span
-              class="tag type string">string</span></span>
-          <p class="description">Other peers can connect to this peer using the provided ID. If no ID is given, one will
-            be generated by the brokering server. The ID must start and end with an alphanumeric character (lower or
-            upper case character or a digit). In the middle of the ID spaces, dashes (-) and underscores (_) are
-            allowed.<span class='warn'>It's not recommended that you use this ID to identify peers, as it's meant to be
-              used for brokering connections only. You're recommended to set the <a
-                href='#peerconnect-options'><code>metadata</code></a> option to send other identifying
-              information.</span></p>
-        </div>
-        <div class="child " id="peer-options"><span class="name"><a href="#peer-options"><span class="optional"><span
-                  class="bracket">[</span>options<span class="bracket">]</span></span></a><span
-              class="tag type object">object</span></span>
-          <div class="children">
-            <div class="child " id="peer-options-key"><span class="name"><a href="#peer-options-key">key</a><span
-                  class="tag type string">string</span></span>
-              <p class="description">API key for the cloud PeerServer. This is not used for servers other than
-                <code>0.peerjs.com</code>.<span class='warn'>PeerServer cloud runs on port 443. Please ensure it is not
-                  blocked or consider running your own PeerServer instead.</span></p>
-            </div>
-            <div class="child " id="peer-options-host"><span class="name"><a href="#peer-options-host">host</a><span
-                  class="tag type string">string</span></span>
-              <p class="description">Server host. Defaults to <code>0.peerjs.com</code>. Also accepts <code>'/'</code>
-                to signify relative hostname.</p>
-            </div>
-            <div class="child " id="peer-options-port"><span class="name"><a href="#peer-options-port">port</a><span
-                  class="tag type number">number</span></span>
-              <p class="description">Server port. Defaults to <code>443</code>.</p>
-            </div>
-            <div class="child " id="peer-options-pinginterval"><span class="name"><a
-                  href="#peer-options-pinginterval">pingInterval</a><span class="tag type number">number</span></span>
-              <p class="description">Ping interval in ms. Defaults to <code>5000</code>.</p>
-            </div>
-            <div class="child " id="peer-options-path"><span class="name"><a href="#peer-options-path">path</a><span
-                  class="tag type string">string</span></span>
-              <p class="description">The path where your self-hosted PeerServer is running. Defaults to
-                <code>'/'</code>.</p>
-            </div>
-            <div class="child " id="peer-options-secure"><span class="name"><a
-                  href="#peer-options-secure">secure</a><span class="tag type boolean">boolean</span></span>
-              <p class="description"><code>true</code> if you're using SSL.<span class='tip'>Note that our cloud-hosted
-                  server and assets may not support SSL.</span></p>
-            </div>
-            <div class="child " id="peer-options-config"><span class="name"><a
-                  href="#peer-options-config">config</a><span class="tag type object">object</span></span>
-              <p class="description">Configuration hash passed to RTCPeerConnection. This hash contains any custom
-                ICE/TURN server configuration. Defaults to
-                <code>{ 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' }, { 'urls': 'turn:0.peerjs.com:3478', username: 'peerjs', credential: 'peerjsp' }], 'sdpSemantics': 'unified-plan' }</code>
-              </p>
-            </div>
-            <div class="child " id="peer-options-debug"><span class="name"><a href="#peer-options-debug">debug</a><span
-                  class="tag type number">number</span></span>
-              <p class="description">Prints log messages depending on the debug level passed in. Defaults to
-                <code>0</code>.</p>
-              <div class="children">
-                <div class="child " id="peer-options-debug-0"><span class="name"><a
-                      href="#peer-options-debug-0">0</a></span>
-                  <p class="description">Prints no logs.</p>
-                </div>
-                <div class="child " id="peer-options-debug-1"><span class="name"><a
-                      href="#peer-options-debug-1">1</a></span>
-                  <p class="description">Prints only errors.</p>
-                </div>
-                <div class="child " id="peer-options-debug-2"><span class="name"><a
-                      href="#peer-options-debug-2">2</a></span>
-                  <p class="description">Prints errors and warnings.</p>
-                </div>
-                <div class="child " id="peer-options-debug-3"><span class="name"><a
-                      href="#peer-options-debug-3">3</a></span>
-                  <p class="description">Prints all logs.</p>
-                </div>
-              </div>
-            </div>
-          </div>
-        </div>
-      </div>
-    </div>
-    <div class="toplevel " id="peerconnect"><span class="name"><a href="#peerconnect">peer.connect</a><span
-          class="tag type method">method</span><span class="snippet">const <a href='#dataconnection'>dataConnection</a>
-          = peer.connect(id, [options]);</span></span>
-      <p class="description">Connects to the remote peer specified by <code>id</code> and returns a data connection. Be
-        sure to listen on the <a href='#peeron-error'><code>error</code></a> event in case the connection fails.</p>
-      <div class="children">
-        <div class="child " id="peerconnect-id"><span class="name"><a href="#peerconnect-id">id</a><span
-              class="tag type string">string</span></span>
-          <p class="description">The brokering ID of the remote peer (their <a href='#peerid'><code>peer.id</code></a>).
-          </p>
-        </div>
-        <div class="child " id="peerconnect-options"><span class="name"><a href="#peerconnect-options"><span
-                class="optional"><span class="bracket">[</span>options<span class="bracket">]</span></span></a><span
-              class="tag type object">object</span></span>
-          <div class="children">
-            <div class="child " id="peerconnect-options-label"><span class="name"><a
-                  href="#peerconnect-options-label">label</a><span class="tag type string">string</span></span>
-              <p class="description">A unique label by which you want to identify this data connection. If left
-                unspecified, a label will be generated at random. Can be accessed with <a
-                  href='#dataconnection-label'><code>dataConnection.label</code></a>.</p>
-            </div>
-            <div class="child " id="peerconnect-options-metadata"><span class="name"><a
-                  href="#peerconnect-options-metadata">metadata</a></span>
-              <p class="description">Metadata associated with the connection, passed in by whoever initiated the
-                connection. Can be accessed with <a
-                  href='#dataconnection-metadata'><code>dataConnection.metadata</code></a>. Can be any serializable
-                type.</p>
-            </div>
-            <div class="child " id="peerconnect-options-serialization"><span class="name"><a
-                  href="#peerconnect-options-serialization">serialization</a><span
-                  class="tag type string">string</span></span>
-              <p class="description">Can be <code>binary</code> (default), <code>binary-utf8</code>, <code>json</code>,
-                or <code>none</code>. Can be accessed with <a
-                  href='#dataconnection-serialization'><code>dataConnection.serialization</code></a>.<span
-                  class='tip'><code>binary-utf8</code> will take a performance hit because of the way UTF8 strings are
-                  packed into binary format.</span></p>
-            </div>
-            <div class="child " id="peerconnect-options-reliable"><span class="name"><a
-                  href="#peerconnect-options-reliable">reliable</a><span class="tag type boolean">boolean</span></span>
-              <p class="description">Whether the underlying data channels should be reliable (e.g. for large file
-                transfers) or not (e.g. for gaming or streaming). Defaults to <code>false</code>.<span
-                  class='warn'>Setting reliable to true will use a shim for incompatible browsers (Chrome 30 and below
-                  only) and thus may not offer full performance.</span></p>
-            </div>
-          </div>
-        </div>
-      </div>
-    </div>
-    <div class="toplevel " id="peercall"><span class="name"><a href="#peercall">peer.call</a><span
-          class="tag type method">method</span><span class="snippet">const <a
-            href='#mediaconnection'>mediaConnection</a> = peer.call(id, stream, [options]);</span></span>
-      <p class="description">Calls the remote peer specified by <code>id</code> and returns a media connection. Be sure
-        to listen on the <a href='#peeron-error'><code>error</code></a> event in case the connection fails.</p>
-      <div class="children">
-        <div class="child " id="peercall-id"><span class="name"><a href="#peercall-id">id</a><span
-              class="tag type string">string</span></span>
-          <p class="description">The brokering ID of the remote peer (their <a href='#peerid'><code>peer.id</code></a>).
-          </p>
-        </div>
-        <div class="child " id="peercall-stream"><span class="name"><a href="#peercall-stream">stream</a><span
-              class="tag type MediaStream">MediaStream</span></span>
-          <p class="description">The caller's media stream</p>
-        </div>
-        <div class="child " id="peercall-options"><span class="name"><a href="#peercall-options"><span
-                class="optional"><span class="bracket">[</span>options<span class="bracket">]</span></span></a><span
-              class="tag type object">object</span></span>
-          <div class="children">
-            <div class="child " id="peercall-options-metadata"><span class="name"><a
-                  href="#peercall-options-metadata">metadata</a></span>
-              <p class="description">Metadata associated with the connection, passed in by whoever initiated the
-                connection. Can be accessed with <a
-                  href='#mediaconnection-metadata'><code>mediaConnection.metadata</code></a>. Can be any serializable
-                type.</p>
-            </div>
-            <div class="child " id="peercall-options-sdptransform"><span class="name"><a
-                  href="#peercall-options-sdptransform">sdpTransform</a><span
-                  class="tag type method">method</span></span>
-              <p class="description">Function which runs before create offer to modify sdp offer message.</p>
-            </div>
-          </div>
-        </div>
-      </div>
-    </div>
-    <div class="toplevel " id="peeron"><span class="name"><a href="#peeron">peer.on</a><span
-          class="tag type method">method</span><span class="snippet">peer.on(event, callback);</span></span>
-      <p class="description">Set listeners for peer events.</p>
-      <div class="children">
-        <div class="child " id="peeron-open"><span class="name"><a href="#peeron-open">'open'</a><span
-              class="tag type event">event</span><span class="snippet">peer.on('open', function(id) { ...
-              });</span></span>
-          <p class="description">Emitted when a connection to the PeerServer is established. You may use the peer before
-            this is emitted, but messages to the server will be queued. <code>id</code> is the brokering ID of the peer
-            (which was either provided in the constructor or assigned by the server).<span class='tip'>You should not
-              wait for this event before connecting to other peers if connection speed is important.</span></p>
-        </div>
-        <div class="child " id="peeron-connection"><span class="name"><a href="#peeron-connection">'connection'</a><span
-              class="tag type event">event</span><span class="snippet">peer.on('connection', function(<a
-                href='#dataconnection'>dataConnection</a>) { ... });</span></span>
-          <p class="description">Emitted when a new data connection is established from a remote peer.</p>
-        </div>
-        <div class="child " id="peeron-call"><span class="name"><a href="#peeron-call">'call'</a><span
-              class="tag type event">event</span><span class="snippet">peer.on('call', function(<a
-                href='#mediaconnection'>mediaConnection</a>) { ... });</span></span>
-          <p class="description">Emitted when a remote peer attempts to call you. The emitted
-            <code>mediaConnection</code> is not yet active; you must first answer the call (<a
-              href='#mediaconnection-answer'><code>mediaConnection.answer([stream]);</code></a>). Then, you can listen
-            for the <a href='#mediaconnection-on'><code>stream</code></a> event.</p>
-        </div>
-        <div class="child " id="peeron-close"><span class="name"><a href="#peeron-close">'close'</a><span
-              class="tag type event">event</span><span class="snippet">peer.on('close', function() { ...
-              });</span></span>
-          <p class="description">Emitted when the peer is <a href='#peerdestroy'>destroyed</a> and can no longer accept
-            or create any new connections. At this time, the peer's connections will all be closed. <span class='tip'>To
-              be extra certain that peers clean up correctly, we recommend calling <code>peer.destroy()</code> on a peer
-              when it is no longer needed.</span></p>
-        </div>
-        <div class="child " id="peeron-disconnected"><span class="name"><a
-              href="#peeron-disconnected">'disconnected'</a><span class="tag type event">event</span><span
-              class="snippet">peer.on('disconnected', function() { ... });</span></span>
-          <p class="description">Emitted when the peer is disconnected from the signalling server, either <a
-              href='#peerdisconnect'>manually</a> or because the connection to the signalling server was lost. When a
-            peer is disconnected, its existing connections will stay alive, but the peer cannot accept or create any new
-            connections. You can reconnect to the server by calling <a
-              href='#peerreconnect'><code>peer.reconnect()</code></a>.</p>
-        </div>
-        <div class="child " id="peeron-error"><span class="name"><a href="#peeron-error">'error'</a><span
-              class="tag type event">event</span><span class="snippet">peer.on('error', function(err) { ...
-              });</span></span>
-          <p class="description">Errors on the peer are <strong>almost always fatal</strong> and will destroy the peer.
-            Errors from the underlying socket and PeerConnections are forwarded here.<br><br>These come in the following
-            <code>err.type</code> flavors:</p>
-          <div class="children">
-            <div class="child fatal " id="peeron-error-browser-incompatible"><span class="name"><a
-                  href="#peeron-error-browser-incompatible">'browser-incompatible'</a><span
-                  class="tag type Error">Error</span><span class="tag fatal">fatal</span></span>
-              <p class="description">The client's browser does not support some or all WebRTC features that you are
-                trying to use.</p>
-            </div>
-            <div class="child " id="peeron-error-disconnected"><span class="name"><a
-                  href="#peeron-error-disconnected">'disconnected'</a><span class="tag type Error">Error</span></span>
-              <p class="description">You've already disconnected this peer from the server and can no longer make any
-                new connections on it.</p>
-            </div>
-            <div class="child fatal " id="peeron-error-invalid-id"><span class="name"><a
-                  href="#peeron-error-invalid-id">'invalid-id'</a><span class="tag type Error">Error</span><span
-                  class="tag fatal">fatal</span></span>
-              <p class="description">The ID passed into the Peer constructor contains illegal characters.</p>
-            </div>
-            <div class="child fatal " id="peeron-error-invalid-key"><span class="name"><a
-                  href="#peeron-error-invalid-key">'invalid-key'</a><span class="tag type Error">Error</span><span
-                  class="tag fatal">fatal</span></span>
-              <p class="description">The API key passed into the Peer constructor contains illegal characters or is not
-                in the system (cloud server only).</p>
-            </div>
-            <div class="child " id="peeron-error-network"><span class="name"><a
-                  href="#peeron-error-network">'network'</a><span class="tag type Error">Error</span></span>
-              <p class="description">Lost or cannot establish a connection to the signalling server.</p>
-            </div>
-            <div class="child " id="peeron-error-peer-unavailable"><span class="name"><a
-                  href="#peeron-error-peer-unavailable">'peer-unavailable'</a><span
-                  class="tag type Error">Error</span></span>
-              <p class="description">The peer you're trying to connect to does not exist.</p>
-            </div>
-            <div class="child fatal " id="peeron-error-ssl-unavailable"><span class="name"><a
-                  href="#peeron-error-ssl-unavailable">'ssl-unavailable'</a><span
-                  class="tag type Error">Error</span><span class="tag fatal">fatal</span></span>
-              <p class="description">PeerJS is being used securely, but the cloud server does not support SSL. Use a
-                custom PeerServer.</p>
-            </div>
-            <div class="child fatal " id="peeron-error-server-error"><span class="name"><a
-                  href="#peeron-error-server-error">'server-error'</a><span class="tag type Error">Error</span><span
-                  class="tag fatal">fatal</span></span>
-              <p class="description">Unable to reach the server.</p>
-            </div>
-            <div class="child fatal " id="peeron-error-socket-error"><span class="name"><a
-                  href="#peeron-error-socket-error">'socket-error'</a><span class="tag type Error">Error</span><span
-                  class="tag fatal">fatal</span></span>
-              <p class="description">An error from the underlying socket.</p>
-            </div>
-            <div class="child fatal " id="peeron-error-socket-closed"><span class="name"><a
-                  href="#peeron-error-socket-closed">'socket-closed'</a><span class="tag type Error">Error</span><span
-                  class="tag fatal">fatal</span></span>
-              <p class="description">The underlying socket closed unexpectedly.</p>
-            </div>
-            <div class="child sometimes_fatal " id="peeron-error-unavailable-id"><span class="name"><a
-                  href="#peeron-error-unavailable-id">'unavailable-id'</a><span class="tag type Error">Error</span><span
-                  class="tag sometimes_fatal">sometimes fatal</span></span>
-              <p class="description">The ID passed into the Peer constructor is already taken.<span class='warn'>This
-                  error is not fatal if your peer has open peer-to-peer connections. This can happen if you attempt to
-                  <a href='#peerreconnect'>reconnect</a> a peer that has been <a href='#peerdisconnect'>disconnected
-                    from the server</a>, but its old ID has now been taken.</span></p>
-            </div>
-            <div class="child " id="peeron-error-webrtc"><span class="name"><a
-                  href="#peeron-error-webrtc">'webrtc'</a><span class="tag type Error">Error</span></span>
-              <p class="description">Native WebRTC errors.</p>
-            </div>
-          </div>
-        </div>
-      </div>
-    </div>
-    <div class="toplevel " id="peerdisconnect"><span class="name"><a href="#peerdisconnect">peer.disconnect</a><span
-          class="tag type method">method</span><span class="snippet">peer.disconnect();</span></span>
-      <p class="description">Close the connection to the server, leaving all existing data and media connections intact.
-        <a href='#peerdisconnected'><code>peer.disconnected</code></a> will be set to <code>true</code> and the <a
-          href='#peeron-disconnected'><code>disconnected</code></a> event will fire.<span class='warn'>This cannot be
-          undone; the respective peer object will no longer be able to create or receive any connections and its ID will
-          be forfeited on the (cloud) server.</span></p>
-    </div>
-    <div class="toplevel " id="peerreconnect"><span class="name"><a href="#peerreconnect">peer.reconnect</a><span
-          class="tag type method">method</span><span class="snippet">peer.reconnect();</span></span>
-      <p class="description">Attempt to reconnect to the server with the peer's old ID. Only <a
-          href='#peerdisconnect'>disconnected peers</a> can be reconnected. Destroyed peers cannot be reconnected. If
-        the connection fails (as an example, if the peer's old ID is now taken), the peer's existing connections will
-        not close, but any associated errors events will fire.</p>
-    </div>
-    <div class="toplevel " id="peerdestroy"><span class="name"><a href="#peerdestroy">peer.destroy</a><span
-          class="tag type method">method</span><span class="snippet">peer.destroy();</span></span>
-      <p class="description">Close the connection to the server and terminate all existing connections. <a
-          href='#peerdestroyed'><code>peer.destroyed</code></a> will be set to <code>true</code>.<span class='warn'>This
-          cannot be undone; the respective peer object will no longer be able to create or receive any connections, its
-          ID will be forfeited on the (cloud) server, and all of its data and media connections will be closed.</span>
-      </p>
-    </div>
-    <div class="toplevel " id="peerid"><span class="name"><a href="#peerid">peer.id</a><span
-          class="tag type string">string</span></span>
-      <p class="description">The brokering ID of this peer. If no ID was specified in <a href='#peer'>the
-          constructor</a>, this will be <code>undefined</code> until the <a href='#peeron-open'><code>open</code></a>
-        event is emitted.</p>
-    </div>
-    <div class="toplevel " id="peerconnections"><span class="name"><a href="#peerconnections">peer.connections</a><span
-          class="tag type object">object</span></span>
-      <p class="description">A hash of all connections associated with this peer, keyed by the remote peer's ID.<span
-          class='tip'>We recommend keeping track of connections yourself rather than relying on this hash.</span></p>
-    </div>
-    <div class="toplevel " id="peerdisconnected"><span class="name"><a
-          href="#peerdisconnected">peer.disconnected</a><span class="tag type boolean">boolean</span></span>
-      <p class="description"><code>false</code> if there is an active connection to the PeerServer.</p>
-    </div>
-    <div class="toplevel " id="peerdestroyed"><span class="name"><a href="#peerdestroyed">peer.destroyed</a><span
-          class="tag type boolean">boolean</span></span>
-      <p class="description"><code>true</code> if this peer and all of its connections can no longer be used.</p>
-    </div>
-    <div class="toplevel " id="dataconnection"><span class="name"><a href="#dataconnection">DataConnection</a><span
-          class="tag type class">class</span></span>
-      <p class="description">Wraps WebRTC's DataChannel. To get one, use <a
-          href='#peerconnect'><code>peer.connect</code></a> or listen for the <a
-          href='#peeron-connect'><code>connect</code></a> event.</p>
-      <div class="children">
-        <div class="child " id="dataconnection-send"><span class="name"><a href="#dataconnection-send">.send</a><span
-              class="tag type method">method</span><span class="snippet">dataConnection.send(data);</span></span>
-          <p class="description"><code>data</code> is serialized by BinaryPack by default and sent to the remote peer.
-          </p>
-          <div class="children">
-            <div class="child " id="dataconnection-send-data"><span class="name"><a
-                  href="#dataconnection-send-data">data</a></span>
-              <p class="description">You can send any type of data, including objects, strings, and blobs.</p>
-            </div>
-          </div>
-        </div>
-        <div class="child " id="dataconnection-close"><span class="name"><a href="#dataconnection-close">.close</a><span
-              class="tag type method">method</span><span class="snippet">dataConnection.close();</span></span>
-          <p class="description">Closes the data connection gracefully, cleaning up underlying DataChannels and
-            PeerConnections.</p>
-        </div>
-        <div class="child " id="dataconnection-on"><span class="name"><a href="#dataconnection-on">.on</a><span
-              class="tag type method">method</span><span class="snippet">dataConnection.on(event,
-              callback);</span></span>
-          <p class="description">Set listeners for data connection events.</p>
-          <div class="children">
-            <div class="child " id="dataconnection-on-data"><span class="name"><a
-                  href="#dataconnection-on-data">'data'</a><span class="tag type event">event</span><span
-                  class="snippet">dataConnection.on('data', function(data) { ... });</span></span>
-              <p class="description">Emitted when data is received from the remote peer.</p>
-            </div>
-            <div class="child " id="dataconnection-on-open"><span class="name"><a
-                  href="#dataconnection-on-open">'open'</a><span class="tag type event">event</span><span
-                  class="snippet">dataConnection.on('open', function() { ... });</span></span>
-              <p class="description">Emitted when the connection is established and ready-to-use.</p>
-            </div>
-            <div class="child " id="dataconnection-on-close"><span class="name"><a
-                  href="#dataconnection-on-close">'close'</a><span class="tag type event">event</span><span
-                  class="snippet">dataConnection.on('close', function() { ... });</span></span>
-              <p class="description">Emitted when either you or the remote peer closes the data connection.<span
-                  class='warn'>Firefox does not yet support this event.</span></p>
-            </div>
-            <div class="child " id="dataconnection-on-error"><span class="name"><a
-                  href="#dataconnection-on-error">'error'</a><span class="tag type event">event</span><span
-                  class="snippet">dataConnection.on('error', function(err) { ... });</span></span></div>
-          </div>
-        </div>
-        <div class="child " id="dataconnection-datachannel"><span class="name"><a
-              href="#dataconnection-datachannel">.dataChannel</a><span class="tag type object">object</span></span>
-          <p class="description">A reference to the RTCDataChannel object associated with the connection.</p>
-        </div>
-        <div class="child " id="dataconnection-label"><span class="name"><a href="#dataconnection-label">.label</a><span
-              class="tag type string">string</span></span>
-          <p class="description">The optional label passed in or assigned by PeerJS when the connection was initiated.
-          </p>
-        </div>
-        <div class="child " id="dataconnection-metadata"><span class="name"><a
-              href="#dataconnection-metadata">.metadata</a></span>
-          <p class="description">Any type of metadata associated with the connection, passed in by whoever initiated the
-            connection.</p>
-        </div>
-        <div class="child " id="dataconnection-open"><span class="name"><a href="#dataconnection-open">.open</a><span
-              class="tag type boolean">boolean</span></span>
-          <p class="description">This is true if the connection is open and ready for read/write.</p>
-        </div>
-        <div class="child " id="dataconnection-peerconnection"><span class="name"><a
-              href="#dataconnection-peerconnection">.peerConnection</a><span
-              class="tag type object">object</span></span>
-          <p class="description">A reference to the RTCPeerConnection object associated with the connection.</p>
-        </div>
-        <div class="child " id="dataconnection-peer"><span class="name"><a href="#dataconnection-peer">.peer</a><span
-              class="tag type string">string</span></span>
-          <p class="description">The ID of the peer on the other end of this connection.</p>
-        </div>
-        <div class="child " id="dataconnection-reliable"><span class="name"><a
-              href="#dataconnection-reliable">.reliable</a><span class="tag type boolean">boolean</span></span>
-          <p class="description">Whether the underlying data channels are reliable; defined when the connection was
-            initiated.</p>
-        </div>
-        <div class="child " id="dataconnection-serialization"><span class="name"><a
-              href="#dataconnection-serialization">.serialization</a><span class="tag type string">string</span></span>
-          <p class="description">The serialization format of the data sent over the connection. Can be
-            <code>binary</code> (default), <code>binary-utf8</code>, <code>json</code>, or <code>none</code>.</p>
-        </div>
-        <div class="child " id="dataconnection-type"><span class="name"><a href="#dataconnection-type">.type</a><span
-              class="tag type string">string</span></span>
-          <p class="description">For data connections, this is always <code>'data'</code>.</p>
-        </div>
-        <div class="child " id="dataconnection-buffersize"><span class="name"><a
-              href="#dataconnection-buffersize">.bufferSize</a><span class="tag type number">number</span></span>
-          <p class="description">The number of messages queued to be sent once the browser buffer is no longer full.</p>
-        </div>
-      </div>
-    </div>
-    <div class="toplevel " id="mediaconnection"><span class="name"><a href="#mediaconnection">MediaConnection</a><span
-          class="tag type class">class</span></span>
-      <p class="description">Wraps WebRTC's media streams. To get one, use <a
-          href='#peercall'><code>peer.call</code></a> or listen for the <a href='#peeron-call'><code>call</code></a>
-        event.</p>
-      <div class="children">
-        <div class="child " id="mediaconnection-answer"><span class="name"><a
-              href="#mediaconnection-answer">.answer</a><span class="tag type method">method</span><span
-              class="snippet">mediaConnection.answer([stream],[options]);</span></span>
-          <p class="description">When receiving a <a href='#peeron-call'><code>call</code></a> event on a peer, you can
-            call <code>.answer</code> on the media connection provided by the callback to accept the call and optionally
-            send your own media stream.</p>
-          <div class="children">
-            <div class="child " id="mediaconnection-answer-stream"><span class="name"><a
-                  href="#mediaconnection-answer-stream"><span class="optional"><span class="bracket">[</span>stream<span
-                      class="bracket">]</span></span></a><span class="tag type MediaStream">MediaStream</span></span>
-              <p class="description">A WebRTC media stream from <a
-                  href='https://developer.mozilla.org/en-US/docs/Web/API/Navigator.getUserMedia'><code>getUserMedia</code></a>.
-              </p>
-            </div>
-            <div class="child " id="mediaconnection-answer-options"><span class="name"><a
-                  href="#mediaconnection-answer-options"><span class="optional"><span
-                      class="bracket">[</span>options<span class="bracket">]</span></span></a><span
-                  class="tag type object">object</span></span>
-              <div class="children">
-                <div class="child " id="mediaconnection-answer-options-sdptransform"><span class="name"><a
-                      href="#mediaconnection-answer-options-sdptransform">sdpTransform</a><span
-                      class="tag type method">method</span></span>
-                  <p class="description">Function which runs before create answer to modify sdp answer message.</p>
-                </div>
-              </div>
-            </div>
-          </div>
-        </div>
-        <div class="child " id="mediaconnection-close"><span class="name"><a
-              href="#mediaconnection-close">.close</a><span class="tag type method">method</span><span
-              class="snippet">mediaConnection.close();</span></span>
-          <p class="description">Closes the media connection.</p>
-        </div>
-        <div class="child " id="mediaconnection-on"><span class="name"><a href="#mediaconnection-on">.on</a><span
-              class="tag type method">method</span><span class="snippet">mediaConnection.on(event,
-              callback);</span></span>
-          <p class="description">Set listeners for media connection events.</p>
-          <div class="children">
-            <div class="child " id="mediaconnection-on-stream"><span class="name"><a
-                  href="#mediaconnection-on-stream">'stream'</a><span class="tag type event">event</span><span
-                  class="snippet">mediaConnection.on('stream', function(stream) { ... });</span></span>
-              <p class="description">Emitted when a remote peer adds a <code>stream</code>.</p>
-            </div>
-            <div class="child " id="mediaconnection-on-close"><span class="name"><a
-                  href="#mediaconnection-on-close">'close'</a><span class="tag type event">event</span><span
-                  class="snippet">mediaConnection.on('close', function() { ... });</span></span>
-              <p class="description">Emitted when either you or the remote peer closes the media connection. <span
-                  class='warn'>Firefox does not yet support this event.</span></p>
-            </div>
-            <div class="child " id="mediaconnection-on-error"><span class="name"><a
-                  href="#mediaconnection-on-error">'error'</a><span class="tag type event">event</span><span
-                  class="snippet">mediaConnection.on('error', function(err) { ... });</span></span></div>
-          </div>
-        </div>
-        <div class="child " id="mediaconnection-open"><span class="name"><a href="#mediaconnection-open">.open</a><span
-              class="tag type boolean">boolean</span></span>
-          <p class="description">Whether the media connection is active (e.g. your call has been answered). You can
-            check this if you want to set a maximum wait time for a one-sided call.</p>
-        </div>
-        <div class="child " id="mediaconnection-metadata"><span class="name"><a
-              href="#mediaconnection-metadata">.metadata</a></span>
-          <p class="description">Any type of metadata associated with the connection, passed in by whoever initiated the
-            connection.</p>
-        </div>
-        <div class="child " id="mediaconnection-peer"><span class="name"><a href="#mediaconnection-peer">.peer</a><span
-              class="tag type string">string</span></span>
-          <p class="description">The ID of the peer on the other end of this connection.</p>
-        </div>
-        <div class="child " id="mediaconnection-type"><span class="name"><a href="#mediaconnection-type">.type</a><span
-              class="tag type string">string</span></span>
-          <p class="description">For media connections, this is always <code>'media'</code>.</p>
-        </div>
-      </div>
-    </div>
-    <div class="toplevel utility " id="util"><span class="name"><a href="#util">util</a><span
-          class="tag type object">object</span><span class="tag utility">utility</span></span>
-      <p class="description">Provides a variety of helpful utilities.<span class='warn'>Only the utilities documented
-          here are guaranteed to be present on <code>util</code>. Undocumented utilities can be removed without warning.
-          We don't consider these to be 'breaking changes.'</span></p>
-      <div class="children">
-        <div class="child " id="util-browser"><span class="name"><a href="#util-browser">.browser</a><span
-              class="tag type string">string</span><span class="snippet">if (util.browser === 'Firefox') { /* OK to peer
-              with Firefox peers. */ }</span></span>
-          <p class="description">The current browser. This property can be useful in determining whether or not two
-            peers can connect. For example, as of now data connections are not yet interoperable between major browsers.
-            <code>util.browser</code> can currently have the values 'Firefox', 'Chrome', 'Unsupported', or 'Supported'
-            (unknown WebRTC-compatible browser).</p>
-        </div>
-        <div class="child " id="util-supports"><span class="name"><a href="#util-supports">.supports</a><span
-              class="tag type object">object</span><span class="snippet">if (util.supports.data) { /* OK to start a data
-              connection. */ }</span></span>
-          <p class="description">A hash of WebRTC features mapped to booleans that correspond to whether the feature is
-            supported by the current browser.<span class='warn'>Only the properties documented here are guaranteed to be
-              present on <code>util.supports</code>.</span></p>
-          <div class="children">
-            <div class="child " id="util-supports-audiovideo"><span class="name"><a
-                  href="#util-supports-audiovideo">.audioVideo</a><span class="tag type boolean">boolean</span></span>
-              <p class="description">True if the current browser supports media streams and PeerConnection.</p>
-            </div>
-            <div class="child " id="util-supports-data"><span class="name"><a href="#util-supports-data">.data</a><span
-                  class="tag type boolean">boolean</span></span>
-              <p class="description">True if the current browser supports DataChannel and PeerConnection.</p>
-            </div>
-            <div class="child " id="util-supports-binary"><span class="name"><a
-                  href="#util-supports-binary">.binary</a><span class="tag type boolean">boolean</span></span>
-              <p class="description">True if the current browser supports binary DataChannels.</p>
-            </div>
-            <div class="child " id="util-supports-reliable"><span class="name"><a
-                  href="#util-supports-reliable">.reliable</a><span class="tag type boolean">boolean</span></span>
-              <p class="description">True if the current browser supports reliable DataChannels.</p>
-            </div>
-          </div>
-        </div>
-      </div>
-    </div>
-  </section>
-
-</body>

+ 0 - 79
docs/js/docs.js

@@ -1,79 +0,0 @@
-$(document).ready(function() {
-  var $api = $('.api');
-  var $start = $('.start');
-  var $show = $('.left .show');
-  var $hide = $('.left .hide');
-  var width = $(window).width();
-  var height = $(window).height();
-  var THRESHOLD = 700;
-
-  init();
-
-  $(window).on('resize', function() {
-    width = $(window).width();
-    height = $(window).height();
-
-    init();
-  });
-
-  var hash = window.location.hash;
-  if (hash === '#start' && width < THRESHOLD) {
-    hideAPI();
-  }
-
-
-  function init() {
-    if (width < THRESHOLD) {
-      $api.addClass('fullscreen');
-      $start.addClass('full');
-      $show.hide();
-      $hide.hide();
-    } else {
-      $start.removeClass('full');
-      $api.removeClass('fullscreen');
-      $show.show();
-      $hide.show();
-    }
-
-    if ($api.attr('class').indexOf('hidden') === -1) {
-      showAPI();
-    } else {
-      hideAPI();
-    }
-  }
-
-  function hideAPI() {
-    $api.addClass('hidden');
-    if (width >= THRESHOLD) {
-      $start.addClass('full');
-      $hide.hide();
-      $show.show();
-    }
-  }
-
-  function showAPI() {
-    if (width >= THRESHOLD) {
-      $start.removeClass('full');
-      $show.hide();
-      $hide.show();
-    }
-    $api.removeClass('hidden');
-  }
-
-  $('body').on('click', '.left', function() {
-    if ($api.attr('class').indexOf('hidden') !== -1) {
-      showAPI();
-    } else if ($api.attr('class').indexOf('fullscreen') === -1) {
-      // Now the headers are only links.
-      hideAPI();
-    }
-  });
-  $('body').on('click', '.right', function() {
-    hideAPI();
-  });
-  $('body').on('click', 'a', function() {
-    if ($(this).attr('href').indexOf('#') === 0) {
-      showAPI();
-    }
-  });
-});

Файловите разлики са ограничени, защото са твърде много
+ 0 - 3
docs/js/jquery.min.js


+ 0 - 21
docs/package.json

@@ -1,21 +0,0 @@
-{
-  "name": "docs",
-  "version": "0.0.0",
-  "description": "**Due to browsers' incomplete support of the WebRTC DataChannel specification, many features of PeerJS have caveats.\r [View the status page for full details](http://peerjs.com/status).**",
-  "main": "build.js",
-  "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1",
-    "build": "node build.js"
-  },
-  "repository": "",
-  "author": "",
-  "license": "BSD",
-  "readmeFilename": "readme.md",
-  "dependencies": {
-    "reference": "^0.1.1",
-    "handlebars": ">=4.0.0"
-  },
-  "devDependencies": {
-    "standard": "^12.0.1"
-  }
-}

+ 0 - 6
docs/readme.md

@@ -1,6 +0,0 @@
-## PeerJS Documentation
-
-We've moved! <a href="https://peerjs.com/docs.html">Check out our new
-documentation.</a>
-
-### [Discuss PeerJS on our Telegram Channel](https://t.me/joinchat/ENhPuhTvhm8WlIxTjQf7Og)

+ 0 - 212
docs/template.html

@@ -1,212 +0,0 @@
-<head>
-  <title>PeerJS Documentation</title>
-  <meta name="viewport" content="width=device-width, maximum-scale=1">
-  <link href='https://fonts.googleapis.com/css?family=Lato:300,400,700,900' rel='stylesheet' type='text/css'>
-  <link href="/css/docs.css" rel="stylesheet" type="text/css">
-  <script type="text/javascript" src="/js/jquery.min.js"></script>
-  <script type="text/javascript" src="/js/docs.js"></script>
-</head>
-
-<body>
-  <section class="start">
-    <h1>
-      <a href="/">PeerJS</a>
-      <span class="title">docs</span>
-    </h1>
-    <p>
-      <br>PeerJS simplifies peer-to-peer data, video, and audio calls.</p>
-    <p>This guide will show you the basic concepts of the PeerJS API.</p>
-    <h2>Setup</h2>
-    <h3>1. Include the Javascript client</h3>
-    <p>Add the PeerJS client library to your webpage.</p>
-    <pre>&lt;script src="https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js"&gt;&lt;/script&gt;</pre>
-    <p>If you prefer, you can host it yourself:
-      <a download href="https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js">peerjs.min.js</a>, or
-      <a href="https://github.com/peers/peerjs">fork us on Github</a>.</p>
-    <h3>2. Create the Peer object</h3>
-    <p>The Peer object is where we create and receive connections.</p>
-    <pre>var peer = new Peer();</pre>
-    <p>PeerJS uses PeerServer for session
-      metadata and candidate signaling. You can also
-      <a href="https://github.com/peers/peerjs-server">run your own PeerServer</a> if you don't like the cloud.</p>
-    <p>We're now ready to start making connections!</p>
-
-    <h2>Usage</h2>
-    <p>Every Peer object is assigned a random, unique ID when it's created.</p>
-    <pre>peer.on('open', function(id) {
-  console.log('My peer ID is: ' + id);
-});</pre>
-    <p>When we want to connect to another peer, we'll need to know their peer id. You're in charge of communicating the
-      peer
-      IDs between users of your site. Optionally, you can pass in your own IDs to the
-      <a href="#peer">
-        <code>Peer</code> constructor
-      </a>.</p>
-
-    <p>Read the
-      <a href="#peer">Peer API reference</a> for complete information on its
-      <a href="#peer-options">options</a>, methods,
-      <a href="#peeron">events</a>, and
-      <a href="#peeron-error">error handling</a>.</p>
-
-    <h3>Data connections</h3>
-    <p>Start a data connection by calling
-      <code>peer.connect</code> with the peer ID of the destination peer. Anytime another peer attempts to connect to
-      your peer ID, you'll receive
-      a
-      <code>connection</code> event. </p>
-    <div class="two-col">
-      <div class="col col-header">Start connection</div>
-      <div class="col col-header">Receive connection</div>
-      <div class="col">
-        <pre>var conn = peer.connect('dest-peer-id');</pre>
-      </div>
-      <div class="col">
-        <pre>peer.on('connection', function(conn) { ... });</pre>
-      </div>
-      <div class="clear"></div>
-    </div>
-    <p>
-      <code>peer.connect</code> and the callback of the
-      <code>connection</code> event will both provide a
-      <code>DataConnection</code> object. This object will allow you to send and receive data:</p>
-    <pre>conn.on('open', function() {
-  // Receive messages
-  conn.on('data', function(data) {
-    console.log('Received', data);
-  });
-
-  // Send messages
-  conn.send('Hello!');
-});</pre>
-    <p>Read the
-      <a href="#dataconnection">DataConnection API reference</a> for complete details on its methods and events.</p>
-    <h3>Video/audio calls</h3>
-    <p>Call another peer by calling
-      <code>peer.call</code> with the peer ID of the destination peer. When a peer calls you, the
-      <code>call</code> event is emitted.</p>
-    <p>Unlike data connections, when receiving a
-      <code>call</code> event, the call must be answered or no connection is established.</p>
-    <div class="two-col">
-      <div class="col col-header">Start call</div>
-      <div class="col col-header">Answer call</div>
-      <div class="col">
-        <pre>// Call a peer, providing our mediaStream
-var call = peer.call('dest-peer-id',
-  mediaStream);
-
-</pre>
-      </div>
-      <div class="col">
-        <pre>peer.on('call', function(call) {
-  // Answer the call, providing our mediaStream
-  call.answer(mediaStream);
-});</pre>
-      </div>
-      <div class="clear"></div>
-    </div>
-    <p>When calling or answering a call, a MediaStream should be provided. The MediaStream represents the local video
-      (webcam)
-      or audio stream and can be obtained with some (browser-specific) version of
-      <a href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator.getUserMedia">
-        <code>navigator.getUserMedia</code>
-      </a>. When answering a call, the MediaStream is optional and if none is provided then a one-way call is
-      established.
-      Once the call is established, its
-      <code>open</code> property is set to true.</p>
-    <p>
-      <code>peer.call</code> and the callback of the
-      <code>call</code> event provide a MediaConnection object. The MediaConnection object itself emits a
-      <code>stream</code> event whose callback includes the video/audio stream of the other peer.</p>
-    <pre>call.on('stream', function(stream) {
-  // `stream` is the MediaStream of the remote peer.
-  // Here you'd add it to an HTML video/canvas element.
-});</pre>
-    <p>Read the
-      <a href="#mediaconnection">MediaConnection API reference</a> for complete details on its methods and events.</p>
-
-    <h2>Common questions</h2>
-
-    <h3>What kind of data can I send?</h3>
-
-    <p>PeerJS has the
-      <a href="https://github.com/binaryjs/js-binarypack">BinaryPack</a>
-      serialization format built-in. This means you can send any JSON type as well as binary Blobs and ArrayBuffers.
-      Simply send
-      arbitrary data and you'll get it out the other side:</p>
-    <pre>
-conn.send({
-  strings: 'hi!',
-  numbers: 150,
-  arrays: [1,2,3],
-  evenBinary: new Blob([1,2,3]),
-  andMore: {bool: true}
-});</pre>
-
-    <h3>Are there any caveats?</h3>
-
-    <p>A small percentage of users are behind symmetric NATs. When two symmetric NAT users try to connect to each other,
-      NAT
-      traversal is impossible and no connection can be made. A workaround is to proxy through the connection through a
-      TURN
-      server. The PeerServer cloud service provides a free TURN server. This will allow your PeerJS app to work seamlessly for this situation</p>
-    <h3>How do I use a TURN server?</h3>
-    <p>When creating your Peer object, pass in the ICE servers as the config key of the options hash.</p>
-    <pre>
-var peer = new Peer({
-  config: {'iceServers': [
-    { url: 'stun:stun.l.google.com:19302' },
-    { url: 'turn:homeo@turn.bistri.com:80', credential: 'homeo' }
-  ]} /* Sample servers, please use appropriate ones */
-});
-</pre>
-    <h3>What if my peer has not yet connected to the server when I attempt to connect to it?</h3>
-
-    <p>When you try to connect to a peer, PeerServer will hold a connection offer for up to 5 seconds before rejecting
-      it. This
-      is useful if you want to reconnect to a peer as it disconnects and reconnects rapidly between web pages.</p>
-
-    <h3>Why am I unable to connect?</h3>
-    <p>You could be behind a symmetric NAT, in which case you'll need to set up a TURN server.</p>
-    <p>Another possible issue is your network blocking port 443, which the PeerServer cloud runs on. In this you must
-      use your
-      own PeerServer running on an appropriate port instead of the cloud service.</p>
-
-    <h3>What about latency/bandwidth?</h3>
-
-    <p>Data sent between the two peers do not touch any other servers, so the connection speed is limited only by the
-      upload
-      and download rates of the two peers. This also means you don't have the additional latency of an intermediary
-      server.</p>
-    <p>The latency to establish a connection can be split into two components: the brokering of data and the
-      identification
-      of clients. PeerJS has been designed to minimize the time you spend in these two areas. For brokering, data is
-      sent
-      through an XHR streaming request before a WebSocket connection is established, then through WebSockets. For client
-      identification, we provide you the ability to pass in your own peer IDs, thus eliminating the RTT for retrieving
-      an
-      ID from the server.</p>
-
-    <h3>More questions?</h3>
-    <p>
-      <a href="https://t.me/joinchat/ENhPuhTvhm8WlIxTjQf7Og">Discuss PeerJS on our Telegram channel.</a>
-      <br>
-      <br>
-    </p>
-  </section>
-
-  <header class="left">
-    <h2>API Reference
-      <a class="hide icon">&laquo;</a>
-      <a class="show icon">&raquo;</a>
-    </h2>
-  </header>
-  <header class="right">
-    <h2>Getting Started</h2>
-  </header>
-
-  <section class="api">
-    {{{html}}}
-  </section>
-
-</body>

+ 20 - 0
lib/baseconnection.ts

@@ -6,8 +6,17 @@ import { ConnectionType } from "./enums";
 export type BaseConnectionEvents = {
 	/**
 	 * Emitted when either you or the remote peer closes the connection.
+	 *
+	 * ```ts
+	 * connection.on('close', () => { ... });
+	 * ```
 	 */
 	close: () => void;
+	/**
+	 * ```ts
+	 * connection.on('error', (error) => { ... });
+	 * ```
+	 */
 	error: (error: Error) => void;
 	iceStateChanged: (state: RTCIceConnectionState) => void;
 };
@@ -17,6 +26,10 @@ export abstract class BaseConnection<
 > extends EventEmitter<T & BaseConnectionEvents> {
 	protected _open = false;
 
+	/**
+	 * Any type of metadata associated with the connection,
+	 * passed in by whoever initiated the connection.
+	 */
 	readonly metadata: any;
 	connectionId: string;
 
@@ -24,11 +37,18 @@ export abstract class BaseConnection<
 
 	abstract get type(): ConnectionType;
 
+	/**
+	 * Whether the media connection is active (e.g. your call has been answered).
+	 * You can check this if you want to set a maximum wait time for a one-sided call.
+	 */
 	get open() {
 		return this._open;
 	}
 
 	constructor(
+		/**
+		 * The ID of the peer on the other end of this connection.
+		 */
 		readonly peer: string,
 		public provider: Peer,
 		readonly options: any,

+ 32 - 3
lib/dataconnection.ts

@@ -8,19 +8,28 @@ import { ServerMessage } from "./servermessage";
 import { EncodingQueue } from "./encodingQueue";
 import type { DataConnection as IDataConnection } from "./dataconnection";
 
-type DataConnectionEvents = {
+export type DataConnectionEvents = {
 	/**
 	 * Emitted when data is received from the remote peer.
+	 *
+	 * ```ts
+	 * dataConnection.on('data', (data) => { ... });
+	 * ```
 	 */
 	data: (data: unknown) => void;
 	/**
 	 * Emitted when the connection is established and ready-to-use.
+	 *
+	 * ```ts
+	 * dataConnection.on('open', () => { ... });
+	 * ```
 	 */
 	open: () => void;
 };
 
 /**
- * Wraps a DataChannel between two Peers.
+ * Wraps WebRTC's DataChannel.
+ * To get one, use {@apilink Peer.connect} or listen for the {@apilink PeerEvents | `connect`} event.
  */
 export class DataConnection
 	extends BaseConnection<DataConnectionEvents>
@@ -30,8 +39,18 @@ export class DataConnection
 	private static readonly MAX_BUFFERED_AMOUNT = 8 * 1024 * 1024;
 
 	private _negotiator: Negotiator<DataConnectionEvents, DataConnection>;
+	/**
+	 * The optional label passed in or assigned by PeerJS when the connection was initiated.
+	 */
 	readonly label: string;
+	/**
+	 * The serialization format of the data sent over the connection.
+	 * {@apilink SerializationType | possible values}
+	 */
 	readonly serialization: SerializationType;
+	/**
+	 * Whether the underlying data channels are reliable; defined when the connection was initiated.
+	 */
 	readonly reliable: boolean;
 	stringify: (data: any) => string = JSON.stringify;
 	parse: (data: string) => any = JSON.parse;
@@ -41,6 +60,9 @@ export class DataConnection
 	}
 
 	private _buffer: any[] = [];
+	/**
+	 * The number of messages queued to be sent once the browser buffer is no longer full.
+	 */
 	private _bufferSize = 0;
 	private _buffering = false;
 	private _chunkedData: {
@@ -54,6 +76,9 @@ export class DataConnection
 	private _dc: RTCDataChannel;
 	private _encodingQueue = new EncodingQueue();
 
+	/**
+	 * A reference to the RTCDataChannel object associated with the connection.
+	 */
 	get dataChannel(): RTCDataChannel {
 		return this._dc;
 	}
@@ -234,7 +259,11 @@ export class DataConnection
 		super.emit("close");
 	}
 
-	/** Allows user to send data. */
+	/**
+	 * `data` is serialized and sent to the remote peer.
+	 * @param data You can send any type of data, including objects, strings, and blobs.
+	 * @returns
+	 */
 	send(data: any, chunked?: boolean): void {
 		if (!this.open) {
 			super.emit(

+ 42 - 0
lib/enums.ts

@@ -4,17 +4,59 @@ export enum ConnectionType {
 }
 
 export enum PeerErrorType {
+	/**
+	 * The client's browser does not support some or all WebRTC features that you are trying to use.
+	 */
 	BrowserIncompatible = "browser-incompatible",
+	/**
+	 * You've already disconnected this peer from the server and can no longer make any new connections on it.
+	 */
 	Disconnected = "disconnected",
+	/**
+	 * The ID passed into the Peer constructor contains illegal characters.
+	 */
 	InvalidID = "invalid-id",
+	/**
+	 * The API key passed into the Peer constructor contains illegal characters or is not in the system (cloud server only).
+	 */
 	InvalidKey = "invalid-key",
+	/**
+	 * Lost or cannot establish a connection to the signalling server.
+	 */
 	Network = "network",
+	/**
+	 * The peer you're trying to connect to does not exist.
+	 */
 	PeerUnavailable = "peer-unavailable",
+	/**
+	 * PeerJS is being used securely, but the cloud server does not support SSL. Use a custom PeerServer.
+	 */
 	SslUnavailable = "ssl-unavailable",
+	/**
+	 * Unable to reach the server.
+	 */
 	ServerError = "server-error",
+	/**
+	 * An error from the underlying socket.
+	 */
 	SocketError = "socket-error",
+	/**
+	 * The underlying socket closed unexpectedly.
+	 */
 	SocketClosed = "socket-closed",
+	/**
+	 * The ID passed into the Peer constructor is already taken.
+	 *
+	 * :::caution
+	 * This error is not fatal if your peer has open peer-to-peer connections.
+	 * This can happen if you attempt to {@apilink Peer.reconnect} a peer that has been disconnected from the server,
+	 * but its old ID has now been taken.
+	 * :::
+	 */
 	UnavailableID = "unavailable-id",
+	/**
+	 * Native WebRTC errors.
+	 */
 	WebRTC = "webrtc",
 }
 

+ 6 - 4
lib/exports.ts

@@ -1,5 +1,6 @@
-import { util } from "./util";
+export { util, type Util } from "./util";
 import { Peer } from "./peer";
+export type { PeerEvents, PeerError } from "./peer";
 
 export type {
 	PeerJSOption,
@@ -8,8 +9,9 @@ export type {
 	CallOption,
 } from "./optionInterfaces";
 export type { UtilSupportsObj } from "./util";
-export type { DataConnection } from "./dataconnection";
-export type { MediaConnection } from "./mediaconnection";
+export type { BaseConnection } from "./baseconnection";
+export type { DataConnection, DataConnectionEvents } from "./dataconnection";
+export type { MediaConnection, MediaConnectionEvents } from "./mediaconnection";
 export type { LogLevel } from "./logger";
 export type {
 	ConnectionType,
@@ -19,5 +21,5 @@ export type {
 	ServerMessageType,
 } from "./enums";
 
-export { Peer, util };
+export { Peer };
 export default Peer;

+ 12 - 0
lib/logger.ts

@@ -8,9 +8,21 @@ Prints log messages depending on the debug level passed in. Defaults to 0.
 3  Prints all logs.
 */
 export enum LogLevel {
+	/**
+	 * Prints no logs.
+	 */
 	Disabled,
+	/**
+	 * Prints only errors.
+	 */
 	Errors,
+	/**
+	 * Prints errors and warnings.
+	 */
 	Warnings,
+	/**
+	 * Prints all logs.
+	 */
 	All,
 }
 

+ 23 - 3
lib/mediaconnection.ts

@@ -7,15 +7,20 @@ import { BaseConnection } from "./baseconnection";
 import { ServerMessage } from "./servermessage";
 import type { AnswerOption } from "./optionInterfaces";
 
-type MediaConnectionEvents = {
+export type MediaConnectionEvents = {
 	/**
 	 * Emitted when a connection to the PeerServer is established.
+	 *
+	 * ```ts
+	 * mediaConnection.on('stream', (stream) => { ... });
+	 * ```
 	 */
 	stream: (stream: MediaStream) => void;
 };
 
 /**
- * Wraps the streaming interface between two Peers.
+ * Wraps WebRTC's media streams.
+ * To get one, use {@apilink Peer.call} or listen for the {@apilink PeerEvents | `call`} event.
  */
 export class MediaConnection extends BaseConnection<MediaConnectionEvents> {
 	private static readonly ID_PREFIX = "mc_";
@@ -24,6 +29,9 @@ export class MediaConnection extends BaseConnection<MediaConnectionEvents> {
 	private _localStream: MediaStream;
 	private _remoteStream: MediaStream;
 
+	/**
+	 * For media connections, this is always 'media'.
+	 */
 	get type() {
 		return ConnectionType.Media;
 	}
@@ -79,6 +87,16 @@ export class MediaConnection extends BaseConnection<MediaConnectionEvents> {
 		}
 	}
 
+	/**
+	 * When receiving a {@apilink PeerEvents | `call`} event on a peer, you can call
+	 * `answer` on the media connection provided by the callback to accept the call
+	 * and optionally send your own media stream.
+
+	 *
+	 * @param stream A WebRTC media stream.
+	 * @param options
+	 * @returns
+	 */
 	answer(stream?: MediaStream, options: AnswerOption = {}): void {
 		if (this._localStream) {
 			logger.warn(
@@ -111,7 +129,9 @@ export class MediaConnection extends BaseConnection<MediaConnectionEvents> {
 	 * Exposed functionality for users.
 	 */
 
-	/** Allows user to close connection. */
+	/**
+	 * Closes the media connection.
+	 */
 	close(): void {
 		if (this._negotiator) {
 			this._negotiator.cleanup();

+ 24 - 0
lib/optionInterfaces.ts

@@ -1,4 +1,7 @@
 export interface AnswerOption {
+	/**
+	 * Function which runs before create answer to modify sdp answer message.
+	 */
 	sdpTransform?: Function;
 }
 
@@ -15,13 +18,34 @@ export interface PeerJSOption {
 }
 
 export interface PeerConnectOption {
+	/**
+	 * A unique label by which you want to identify this data connection.
+	 * If left unspecified, a label will be generated at random.
+	 *
+	 * Can be accessed with {@apilink DataConnection.label}
+	 */
 	label?: string;
+	/**
+	 * Metadata associated with the connection, passed in by whoever initiated the connection.
+	 *
+	 * Can be accessed with {@apilink DataConnection.metadata}.
+	 * Can be any serializable type.
+	 */
 	metadata?: any;
 	serialization?: string;
 	reliable?: boolean;
 }
 
 export interface CallOption {
+	/**
+	 * Metadata associated with the connection, passed in by whoever initiated the connection.
+	 *
+	 * Can be accessed with {@apilink MediaConnection.metadata}.
+	 * Can be any serializable type.
+	 */
 	metadata?: any;
+	/**
+	 * Function which runs before create offer to modify sdp offer message.
+	 */
 	sdpTransform?: Function;
 }

+ 73 - 19
lib/peer.ts

@@ -19,22 +19,70 @@ import type {
 } from "./optionInterfaces";
 
 class PeerOptions implements PeerJSOption {
-	debug?: LogLevel; // 1: Errors, 2: Warnings, 3: All logs
+	/**
+	 * Prints log messages depending on the debug level passed in.
+	 */
+	debug?: LogLevel;
+	/**
+	 * Server host. Defaults to `0.peerjs.com`.
+	 * Also accepts `'/'` to signify relative hostname.
+	 */
 	host?: string;
+	/**
+	 * Server port. Defaults to `443`.
+	 */
 	port?: number;
+	/**
+	 * The path where your self-hosted PeerServer is running. Defaults to `'/'`
+	 */
 	path?: string;
+	/**
+	 * API key for the PeerServer.
+	 * This is not used anymore.
+	 * @deprecated
+	 */
 	key?: string;
 	token?: string;
+	/**
+	 * Configuration hash passed to RTCPeerConnection.
+	 * This hash contains any custom ICE/TURN server configuration.
+	 *
+	 * Defaults to {@apilink util.defaultConfig}
+	 */
 	config?: any;
+	/**
+	 * Set to true `true` if you're using TLS.
+	 * :::danger
+	 * If possible *always use TLS*
+	 * :::
+	 */
 	secure?: boolean;
 	pingInterval?: number;
 	referrerPolicy?: ReferrerPolicy;
 	logFunction?: (logLevel: LogLevel, ...rest: any[]) => void;
 }
 
-type PeerEvents = {
+class PeerError extends Error {
+	constructor(type: PeerErrorType, err: Error | string) {
+		if (typeof err === "string") {
+			super(err);
+		} else {
+			super();
+			Object.assign(this, err);
+		}
+
+		this.type = type;
+	}
+
+	type: PeerErrorType;
+}
+export type { PeerError };
+
+export type PeerEvents = {
 	/**
 	 * Emitted when a connection to the PeerServer is established.
+	 *
+	 * You may use the peer before this is emitted, but messages to the server will be queued. <code>id</code> is the brokering ID of the peer (which was either provided in the constructor or assigned by the server).<span class='tip'>You should not wait for this event before connecting to other peers if connection speed is important.</span>
 	 */
 	open: (id: string) => void;
 	/**
@@ -55,8 +103,10 @@ type PeerEvents = {
 	disconnected: (currentId: string) => void;
 	/**
 	 * Errors on the peer are almost always fatal and will destroy the peer.
+	 *
+	 * Errors from the underlying socket and PeerConnections are forwarded here.
 	 */
-	error: (error: Error) => void;
+	error: (error: PeerError) => void;
 };
 /**
  * A peer who can initiate connections with other peers.
@@ -82,6 +132,9 @@ export class Peer extends EventEmitter<PeerEvents> {
 	private readonly _lostMessages: Map<string, ServerMessage[]> = new Map(); // src => [list of messages]
 	/**
 	 * The brokering ID of this peer
+	 *
+	 * If no ID was specified in {@apilink Peer | the constructor},
+	 * this will be `undefined` until the {@apilink PeerEvents | `open`} event is emitted.
 	 */
 	get id() {
 		return this._id;
@@ -142,6 +195,7 @@ export class Peer extends EventEmitter<PeerEvents> {
 	 * A peer can connect to other peers and listen for connections.
 	 * @param id Other peers can connect to this peer using the provided ID.
 	 *     If no ID is given, one will be generated by the brokering server.
+	 * The ID must start and end with an alphanumeric character (lower or upper case character or a digit). In the middle of the ID spaces, dashes (-) and underscores (_) are allowed. Use {@apilink PeerOptions.metadata } to send identifying information.
 	 * @param options for specifying details about PeerServer
 	 */
 	constructor(id: string, options?: PeerOptions);
@@ -410,7 +464,7 @@ export class Peer extends EventEmitter<PeerEvents> {
 
 	/**
 	 * Connects to the remote peer specified by id and returns a data connection.
-	 * @param peer The brokering ID of the remote peer (their peer.id).
+	 * @param peer The brokering ID of the remote peer (their {@apilink Peer.id}).
 	 * @param options for specifying details about Peer Connection
 	 */
 	connect(peer: string, options: PeerConnectOption = {}): DataConnection {
@@ -549,24 +603,18 @@ export class Peer extends EventEmitter<PeerEvents> {
 	emitError(type: PeerErrorType, err: string | Error): void {
 		logger.error("Error:", err);
 
-		let error: Error & { type?: PeerErrorType };
-
-		if (typeof err === "string") {
-			error = new Error(err);
-		} else {
-			error = err as Error;
-		}
-
-		error.type = type;
-
-		this.emit("error", error);
+		this.emit("error", new PeerError(type, err));
 	}
 
 	/**
 	 * Destroys the Peer: closes all active connections as well as the connection
-	 *  to the server.
-	 * Warning: The peer can no longer create or accept connections after being
-	 *  destroyed.
+	 * to the server.
+	 *
+	 * :::caution
+	 * This cannot be undone; the respective peer object will no longer be able
+	 * to create or receive any connections, its ID will be forfeited on the server,
+	 * and all of its data and media connections will be closed.
+	 * :::
 	 */
 	destroy(): void {
 		if (this.destroyed) {
@@ -630,7 +678,13 @@ export class Peer extends EventEmitter<PeerEvents> {
 		this.emit("disconnected", currentId);
 	}
 
-	/** Attempts to reconnect with the same ID. */
+	/** Attempts to reconnect with the same ID.
+	 *
+	 * Only {@apilink Peer.disconnect | disconnected peers} can be reconnected.
+	 * Destroyed peers cannot be reconnected.
+	 * If the connection fails (as an example, if the peer's old ID is now taken),
+	 * the peer's existing connections will not close, but any associated errors events will fire.
+	 */
 	reconnect(): void {
 		if (this.disconnected && !this.destroyed) {
 			logger.log(

+ 40 - 2
lib/util.ts

@@ -4,11 +4,33 @@ import BinaryPack from "peerjs-js-binarypack";
 import { Supports } from "./supports";
 
 export interface UtilSupportsObj {
+	/**
+	 * The current browser.
+	 * This property can be useful in determining whether two peers can connect.
+	 *
+	 * ```ts
+	 * if (util.browser === 'firefox') {
+	 *  // OK to peer with Firefox peers.
+	 * }
+	 * ```
+	 *
+	 * `util.browser` can currently have the values
+	 * `'firefox', 'chrome', 'safari', 'edge', 'Not a supported browser.', 'Not a browser.' (unknown WebRTC-compatible agent).
+	 */
 	browser: boolean;
 	webRTC: boolean;
+	/**
+	 * True if the current browser supports media streams and PeerConnection.
+	 */
 	audioVideo: boolean;
+	/**
+	 * True if the current browser supports DataChannel and PeerConnection.
+	 */
 	data: boolean;
 	binaryBlob: boolean;
+	/**
+	 * True if the current browser supports reliable DataChannels.
+	 */
 	reliable: boolean;
 }
 
@@ -27,7 +49,7 @@ const DEFAULT_CONFIG = {
 	sdpSemantics: "unified-plan",
 };
 
-class Util {
+export class Util {
 	noop(): void {}
 
 	readonly CLOUD_HOST = "0.peerjs.com";
@@ -43,7 +65,13 @@ class Util {
 	readonly browser = Supports.getBrowser();
 	readonly browserVersion = Supports.getVersion();
 
-	// Lists which features are supported
+	/**
+	 * A hash of WebRTC features mapped to booleans that correspond to whether the feature is supported by the current browser.
+	 *
+	 * :::caution
+	 * Only the properties documented here are guaranteed to be present on `util.supports`
+	 * :::
+	 */
 	readonly supports = (function () {
 		const supported: UtilSupportsObj = {
 			browser: Supports.isBrowserSupported(),
@@ -171,4 +199,14 @@ class Util {
 		return location.protocol === "https:";
 	}
 }
+
+/**
+ * Provides a variety of helpful utilities.
+ *
+ * :::caution
+ * Only the utilities documented here are guaranteed to be present on `util`.
+ * Undocumented utilities can be removed without warning.
+ * We don't consider these to be breaking changes.
+ * :::
+ */
 export const util = new Util();

Някои файлове не бяха показани, защото твърде много файлове са промени