[
  {
    "name": "Peer",
    "type": "constructor",
    "snippet": "var 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. <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": "path",
            "type": "string",
            "description": "The path where your self-hosted PeerServer is running. Defaults to <code>'/'</code>."
          },
          {
            "name": "secure",
            "type": "boolean",
            "tags": [
              "beta (0.3.0)"
            ],
            "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' }], 'sdpSemantics': 'unified-plan' }</code>"
          },
          {
            "name": "debug",
            "type": "number",
            "tags": [
              "beta (0.3.0)"
            ],
            "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": "var <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",
    "tags": [
      "beta (0.3.0)"
    ],
    "type": "method",
    "snippet": "var <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='#dataconnection-metadata'><code>dataConnection.metadata</code></a>. Can be any serializable type."
          }
        ]
      }
    ]
  },
  {
    "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",
        "tags": [
          "beta (0.3.0)"
        ],
        "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",
    "tags": [
      "beta (0.3.0)"
    ],
    "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]);",
        "description": "When recieving 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": ".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 'Firefox', 'Chrome', 'Unsupported', or 'Supported' (unknown WebRTC-compatible browser)."
      },
      {
        "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."
          }
        ]
      }
    ]
  }
]