478 lines
12 KiB
HTML
Raw Normal View History

2017-10-20 12:21:15 +01:00
<!doctype html>
2019-08-21 17:17:25 +02:00
<html>
<head>
<meta charset='utf-8'>
2019-09-30 13:29:23 +02:00
<title>libp2p-websockets 0.13.0 | Documentation</title>
2019-08-21 17:17:25 +02:00
<meta name='description' content='JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' rel='stylesheet'>
<link href='assets/style.css' rel='stylesheet'>
<link href='assets/github.css' rel='stylesheet'>
<link href='assets/split.css' rel='stylesheet'>
</head>
<body class='documentation m0'>
<div class='flex'>
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>libp2p-websockets</h3>
2019-09-30 13:29:23 +02:00
<div class='mb1'><code>0.13.0</code></div>
2019-08-21 17:17:25 +02:00
<input
placeholder='Filter'
id='filter-input'
class='col12 block input'
type='text' />
<div id='toc'>
<ul class='list-reset h5 py1-ul'>
<li><a
href='#intro'
class="h5 bold black caps">
Intro
</a>
</li>
2019-09-30 13:29:23 +02:00
<li><a
href='#websockets'
class=" toggle-sibling">
WebSockets
<span class='icon'></span>
</a>
<div class='toggle-target display-none'>
<ul class='list-reset py1-ul pl1'>
<li class='h5'><span>Instance members</span></li>
<li><a
href='#websocketsdial'
class='regular pre-open'>
#dial
</a></li>
<li><a
href='#websocketscreatelistener'
class='regular pre-open'>
#createListener
</a></li>
<li><a
href='#websocketsfilter'
class='regular pre-open'>
#filter
</a></li>
</ul>
</div>
</li>
2019-08-21 17:17:25 +02:00
</ul>
</div>
<div class='mt1 h6 quiet'>
<a href='https://documentation.js.org/reading-documentation.html'>Need help reading this?</a>
</div>
</div>
</div>
<div id='split-right' class='relative overflow-auto height-viewport-100'>
<div class='keyline-top-not py2'><section class='py2 clearfix'>
<h2 id='intro' class='mt0'>
Intro
</h2>
<p>Installable via <code>npm install --save libp2p-websockets</code>, it can also be used directly in the browser.</p>
2017-10-20 12:21:15 +01:00
<h2>Download</h2>
<p>The source is available for download from <a href="git+https://github.com/libp2p/js-libp2p-websockets.git">GitHub</a>. Alternatively, you can install using npm:</p>
<pre class='hljs'>$ npm install --save libp2p-websockets</pre>
<p>You can then <code>require()</code> libp2p-websockets as normal:</p>
<pre class='hljs'><span class="hljs-keyword">const</span> libp2PWebsockets = <span class="hljs-built_in">require</span>(<span class="hljs-string">'libp2p-websockets'</span>)</pre>
<h2>In the Browser</h2>
<p>Libp2p-websockets should work in any ES2015 environment out of the box.</p>
<p>Usage:</p>
2019-08-21 17:17:25 +02:00
<pre class='hljs'><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"index.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></pre>
2019-01-10 14:56:33 +01:00
<p>The portable versions of libp2p-websockets, including <code>index.js</code> and <code>index.min.js</code>, are included in the <code>/dist</code> folder. Libp2p-websockets can also be found on <a href="https://unpkg.com">unpkg.com</a> under</p>
2017-10-20 12:21:15 +01:00
<ul>
<li><a href="https://unpkg.com/libp2p-websockets/dist/index.min.js">https://unpkg.com/libp2p-websockets/dist/index.min.js</a></li>
<li><a href="https://unpkg.com/libp2p-websockets/dist/index.js">https://unpkg.com/libp2p-websockets/dist/index.js</a></li>
</ul>
2019-08-21 17:17:25 +02:00
</section></div>
2019-09-30 13:29:23 +02:00
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<h3 class='fl m0' id='websockets'>
WebSockets
</h3>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/libp2p/js-libp2p-websockets/blob/b5496fbc2190241c856cb94bb32bcb25af128bb8/src/index.js#L19-L130'>
<span>src/index.js</span>
</a>
</div>
<div class='pre p1 fill-light mt0'>new WebSockets()</div>
<div class='py1 quiet mt1 prose-big'>Instance Members</div>
<div class="clearfix">
<div class='border-bottom' id='websocketsdial'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'></a>
<span class='code strong strong truncate'>dial(ma, options = {})</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/libp2p/js-libp2p-websockets/blob/b5496fbc2190241c856cb94bb32bcb25af128bb8/src/index.js#L37-L47'>
<span>src/index.js</span>
</a>
</div>
<div class='pre p1 fill-light mt0'>dial(ma: Multiaddr, options: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a>?): Connection</div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>ma</span> <code class='quiet'>(Multiaddr)</code>
</div>
</div>
<div class='space-bottom0'>
<div>
<span class='code bold'>options</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a>?
= <code>{}</code>)</code>
</div>
<table class='mt1 mb2 fixed-table h5 col-12'>
<colgroup>
<col width='30%' />
<col width='70%' />
</colgroup>
<thead>
<tr class='bold fill-light'>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody class='mt1'>
<tr>
<td class='break-word'><span class='code bold'>options.signal</span> <code class='quiet'>AbortSignal?</code>
</td>
<td class='break-word'><span>Used to abort dial requests
</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code>Connection</code>:
An upgraded Connection
</section>
</div>
</div>
<div class='border-bottom' id='websocketscreatelistener'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'></a>
<span class='code strong strong truncate'>createListener(options = {}, handler)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/libp2p/js-libp2p-websockets/blob/b5496fbc2190241c856cb94bb32bcb25af128bb8/src/index.js#L104-L111'>
<span>src/index.js</span>
</a>
</div>
<p>Creates a Websockets listener. The provided <code>handler</code> function will be called
anytime a new incoming Connection has been successfully upgraded via
<code>upgrader.upgradeInbound</code>.</p>
<div class='pre p1 fill-light mt0'>createListener(options: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a>?, handler: function (Connection)): Listener</div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>options</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a>?
= <code>{}</code>)</code>
</div>
<table class='mt1 mb2 fixed-table h5 col-12'>
<colgroup>
<col width='30%' />
<col width='70%' />
</colgroup>
<thead>
<tr class='bold fill-light'>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody class='mt1'>
<tr>
<td class='break-word'><span class='code bold'>options.server</span> <code class='quiet'>http.Server?</code>
</td>
<td class='break-word'><span>A pre-created Node.js HTTP/S server.
</span></td>
</tr>
</tbody>
</table>
</div>
<div class='space-bottom0'>
<div>
<span class='code bold'>handler</span> <code class='quiet'>(function (Connection))</code>
</div>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code>Listener</code>:
A Websockets listener
</section>
</div>
</div>
<div class='border-bottom' id='websocketsfilter'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'></a>
<span class='code strong strong truncate'>filter(multiaddrs)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/libp2p/js-libp2p-websockets/blob/b5496fbc2190241c856cb94bb32bcb25af128bb8/src/index.js#L118-L129'>
<span>src/index.js</span>
</a>
</div>
<p>Takes a list of <code>Multiaddr</code>s and returns only valid Websockets addresses</p>
<div class='pre p1 fill-light mt0'>filter(multiaddrs: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;Multiaddr>): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;Multiaddr></div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>multiaddrs</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;Multiaddr>)</code>
</div>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;Multiaddr></code>:
Valid Websockets multiaddrs
</section>
</div>
</div>
</div>
</section>
2019-08-21 17:17:25 +02:00
</div>
</div>
<script src='assets/anchor.js'></script>
<script src='assets/split.js'></script>
<script src='assets/site.js'></script>
</body>
</html>