npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

plink

v0.1.0

Published

Simple peer-to-peer browser connections with tokens

Downloads

5

Readme

Plink makes networking browsers easy

Plink is small tool (a thin layer on top of P) for creating data channels between two browsers.

Example

Here's an example of two applications which will establish a peer-to-peer connection with each other using a plink-server and then send greetings to each other via a peer-to-peer data channel.

hello.html

<!doctype html><title>Hello!</title>
<script src="/plink.js"></script>
<script>
	// Connect to plink-server and await connection using
	// 'something secret' as the key.
	Plink.create()
		.connect('ws://' + location.hostname + ':20500/')
		.on('connection', function(peer){
			peer.on('open', function(){
				peer.send('Hello!');
			});
		})
		.setKey('something secret');
</script>

hi.html

<!doctype html><title>Hi!</title>
<script src="/plink.js"></script>
<script>
	// Connect to plink-server and attempt to connect to
	// peer using 'something secret' as the key.
	Plink.create()
		.connect('ws://' + location.hostname + ':20500/')
		.useKey('something secret')
		.then(function(peer){
			peer.on('open', function(){
				peer.send('Hi!');
			});
		});
</script>

Note that the "Hello!" and "Hi!" messages never go through the plink-server. The plink-server is only used to help the two peers connect to each other using a shared passcode.

API

  • For WebRtcNode API documentation, see P.
  • For Promise API documentation, see when.js.
// Create root plink instance
var plink = Plink.create();

// Connect to a plink-server
var plinkServer = plink.connect(plinkServerAddress);

// Set a key. Other peers can use to connect to this browser using this 
// key via a the connected plink-server.
// Returns a promise on whether the operation succeeded.
var promise = plinkServer.setKey(mySecretKeyString);

// Set a key with an expiration in milliseconds
// Returns a promise on whether the operation succeeded.
var promise = plinkServer.setKey(mySecretKeyString, 60 * 1000);

// Revoke a key.
// Returns a promise on whether the operation succeeded.
var promise = plinkServer.revokeKey(mySecretKeyString);

// Use a key to connect to a peer.
// Returns a promise for a WebRtcNode, please see the P documentation for
// the API of the WebRtcNode.
var webRtcNodePromise = plinkServer.useKey(theirSecretKeyString);

// Events
plinkServer.on('connection', webRTCNodeHandler);
plinkServer.on('open', openHandler);
plinkServer.on('close', closeHandler);
plinkServer.on('error', errorHandler);
plinkServer.removeListener(eventName, optionalBoundHandler);