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

@paapi/client

v1.0.2

Published

![๐Ÿ”— paapi](https://raw.githubusercontent.com/paapi-js/paapi/master/.github/banner.svg)

Downloads

4

Readme

๐Ÿ”— paapi

Paapi is a wrapper around Socket.io that makes pairing two devices and establishing a connection very simple

๐Ÿš€ Quick start

Install the package in your project with the package manager of your choice:

npm i @paapi/client
yarn add @paapi/client
pnpm add @paapi/client

Then use it in your modules or with a bundler:

import paapi from '@paapi/client'

Paapi will be working out-of-the-box because it uses by default the demo server as backend. It is strongly advised to run your own server for a more reliable experience.

๐Ÿ”— Pairing

You will then need to share an identifier between the two devices you want to pair. This identifier can be shared the way you want. The most common method is a QR code (see the demo)

The pairing is done like that:

const link = await paapi().pair('yourId')

If you need the server to generate an ID for you, call the pair method with no parameters.

const link = await paapi().pair('yourId')
link.id // this is the ID the other device will need to know to pair

The link is considered paired when both devices have established a connection with the server. You can be notified for the pairing with the onPair method.

link.onPair(() => {
    console.log(`The link is now paired with id ${link.id}`)
})

๐Ÿ”ƒ Sending data between peers

Under the hood, a Link is using Socket.io to transfer data between the server and the clients.

๐Ÿ“ฎ Sending data

To send data, use the emit() method of the link.

The first parameter is the event name, and the second the data. This can be any javascript data structure.

link.emit('myEvent', {
    some: 'data'
})

๐Ÿ“จ Receiving data

To receive data, you have to bind a listener on the event you want to listen to. This is done with the on() method.

link.on('myEvent', data => {
    console.log(data) // => { some: 'data' }
})

๐Ÿ“ Documentation

๐Ÿญ Factory function paapi()

The paapi() function is used to create a new link.

const link = paapi('https://my-server-url/')

๐Ÿ”— Complete Link API

The Link object is exposing each method of the Socket.io Socket Object. See the documentation there.

Link-specific API

The Link instance has some additional methods and attributes.

Attributes

| Method | Returns | Description | |----------|-----------------------------------------------------------------|--------------------------------------------------| | id | string | The room id the link is paired with | | paired | boolean (readonly) | true if the link is paired. false otherwise | | socket | Socket | The Socket.io's Socket instance used by the link |

Methods

| Method | Returns | Description | |------------------------------|--------------------|----------------------------------------------------------------------------------------------------------| | pair([id: string]) | Promise<Link> | Pairs the link with the provided room id.If id is not provided, the server will autogenerate one. | | onPair(listener: Function) | void | Registers a listener for when the link will be paired. | | waitFor(event: string) | Promise<any> | Utility method that return a promise that will resolve the next time the specified event is fired. |

๐Ÿ“ก Running your own server

โณ Coming soon !