123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <head>
- <title>PeerJS Documentation</title>
- <link href='http://fonts.googleapis.com/css?family=Lato:300,400,700,900' rel='stylesheet' type='text/css'>
- <link href="./style.css" rel="stylesheet" type="text/css">
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
- <script type="text/javascript" src="./index.js"></script>
- </head>
- <body>
- <section class="start">
- <h1><a href="/">PeerJS</a> <span class="title">docs</span></h1>
- <h2>Get started with PeerJS</h2>
- <div class="warning">Due to browsers' incomplete support of the WebRTC DataChannel specification, many features of PeerJS have caveats.<br><a href="/status">View the status page for full details</a>.</div>
- <p>PeerJS requires two components: the PeerJS client library and the PeerServer.</p>
- <h2>PeerServer</h2>
- <p>The PeerServer brokers connections between PeerJS clients. Once two clients have established a connection with each other with the PeerServer's help, data is will flow between the clients directly.</p>
- <p>Choose one of the following options:</p>
- <p><a href="/peerserver">Sign up for free cloud-hosted PeerServer service</a></p>
- <p>Alternatively, <a href="http://github.com/peers/peerjs-server">PeerServer is
- available on GitHub</a> and on <a href="https://npmjs.org/package/peer">npm</a>:</a>
- <pre><code>npm install peer</code></pre>
- <p>Setting up the server on your own is just a few lines of code:</a>
- <pre><code>var PeerServer = require('peer').PeerServer;
- var server = new PeerServer({ port: 9000 });</code></pre>
- <h2>PeerJS Client</h2>
- <p>The client is where all the action is at.<p>
- <h3>1. Include the PeerJS client in your frontend Javascript code:</h3>
- <pre><code><script src="http://cdn.peerjs.com/0/peer.min.js"></script>
- </code></pre>
- <h3>2. Create the Peer object.</h3>
- <p>
- You'll need to provide an ID. When other peers try to connect to you, they'll have to know this ID.</p>
- <p>
- Also you'll need to provide either the API key for your PeerServer cloud account or your own PeerServer:
- </p>
- <pre><code>var peer = new Peer('some-id', {key: 'myapikey'});
- </code></pre>
- <p>Or if you're running your own PeerServer</p>
- <pre><code>var peer = new Peer('some-id', {host: 'localhost', port: 9000});
- </code></pre>
- <h3>3. That's it! You're ready to send and receive binary P2P data connections!</h3>
- <p>Listening for incoming connections:</p>
- <pre><code>peer.on('connection', function(conn){
- conn.on('data', function(data) {
- console.log('Got data:', data);
- });
- });
- </code></pre>
- <p>Create a peer connection:</p>
- <pre><code>var conn = peer.connect('some-id');
- conn.on('open', function() {
- conn.send('Hello world!');
- });
- </code></pre>
- <h2>Other cool things you need to know</h2>
- <h3>What kind of data can I send?</h3>
- <p>PeerJS has the BinaryPack serialization format built-in. This means you can send any JSON type as well as binary Blobs and ArrayBuffers. You don't have to worry about serializing yourself. Simple put objects in on one side and get objects out on the other:</p>
- <pre><code>conn.send({
- strings: 'hi!',
- numbers: 150,
- arrays: [1,2,3],
- evenbinary: new Blob([1,2,3]),
- andmore: {bool: true}
- });
- </code></pre>
- <p>With BinaryPack, the data is never converted to strings. Everything is binary end-to-end. This results in bandwidth savings.
- </p>
- <h3>Preconnection</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>Connection 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 is identified by two factors: the brokering of data and identifying of clients. PeerJS has been carefully coded to minimize latency in both applications. Data is brokered through an XHR streaming request before a WebSocket connection is established, then through WebSocket afterwards. Identity is self-provided and thus a new client can report identity, accept an outstanding offer, and and provide answer and thus establish the peer-to-peer connection in very few RTTs.</p>
- <p>Note that in the infrequent case that both peers are behind symmetric NATs, this is no longer true. See below.</p>
- <h3>Peer-to-peer shortingcomings</h3>
- <p>A very low 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 what is known as a TURN server. The PeerServer cloud service does not provide a TURN server. You'll have to find your own. You can pass a TURN server into the <tt>Peer</tt> object options. This will allow your PeerJS app to work seamlessly for this situation</p>
- <h3>Current state of browser compatibility</h3>
- <p><a href="/status">Detailed browser compatibility information</a></p>
- <p><a href="https://groups.google.com/forum/?fromgroups#!forum/peerjs">Discuss PeerJS on our Google Group</a></p>
- </section>
- <header class="left">
- <h2>API Reference<a class="hide icon">«</a><a class="show icon">»</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">var 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.<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>.</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>80</code>.</p></div><div class="child beta_030 " id="peer-options-secure"><span class="name"><a href="#peer-options-secure">secure</a><span class="tag type boolean">boolean</span><span class="tag beta_030">beta (0.3.0)</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 the ICE servers. Defaults to <code>{ 'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }] }</code></p></div><div class="child beta_030 " id="peer-options-debug"><span class="name"><a href="#peer-options-debug">debug</a><span class="tag type number">number</span><span class="tag beta_030">beta (0.3.0)</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">var <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>true</code>.</p></div></div></div></div></div><div class="toplevel beta_030 " id="peercall"><span class="name"><a href="#peercall">peer.call</a><span class="tag type method">method</span><span class="tag beta_030">beta (0.3.0)</span><span class="snippet">var <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">Something else</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-constraints"><span class="name"><a href="#peercall-options-constraints">constraints</a><span class="tag type object">object</span></span><p class="description">[TODO: fill this in.]</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 beta_030 " id="peeron-call"><span class="name"><a href="#peeron-call">'call'</a><span class="tag type event">event</span><span class="tag beta_030">beta (0.3.0)</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>.<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-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 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 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 fatal">fatal</span></span><p class="description">The ID passed into the Peer constructor is already taken.</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 " id="peeron-error-server-disconnected"><span class="name"><a href="#peeron-error-server-disconnected">'server-disconnected'</a><span class="tag type Error">Error</span></span><p class="description">You've already disconnected this peer and can no longer make any new connections on it.</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></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>.<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="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.<span class='tip'>Because Chrome currently does not support reliable messaging, PeerJS uses the <a href='https://github.com/michellebu/reliable'>Reliable shim</a> when necessary. A caveat is that with the shim you will not be able to customize <code>serialization</code> when the shim is used.</span></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('data', 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.</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-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-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-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-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-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></div><div class="toplevel beta_030 " id="mediaconnection"><span class="name"><a href="#mediaconnection">MediaConnection</a><span class="tag type class">class</span><span class="tag beta_030">beta (0.3.0)</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]);</span></span><p class="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.</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></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.</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-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>
|