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

primus-client

v7.3.4

Published

Prebuilt client library for Primus - a simple abstraction around real-time frameworks

Downloads

672

Readme

Primus-client

This is a prebuilt primus client-side library with default options. It does not come pre-minified as that is out of the scope of this project.

Link to the full library

https://www.npmjs.com/package/primus

Example client-side code

// can be used with feathers (optional)
import feathers from '@feathersjs/feathers';
// can be used with feathers (optional)
import primusClient from '@feathersjs/primus-client';
import Primus from 'primus-client';
import set from 'lodash/set';

const protocol = `ws${location.protocol === 'https:' ? 's' : ''}:`;

const connectionString = `${protocol}//${location.hostname}`;

const socket = new Primus(connectionString, {
  protocol,
});

// can be used with feathers (optional)
const app = feathers();

// can be used with feathers (optional)
app.configure(primusClient(socket));

// you can add token for auth or other query params
socket.on('outgoing::url', function connectionURL(url) {
  set(url, 'query', `${url.query}&token=${token}`);
});

function executePrimusRequest(...args) {
  if (!args[2]) {
    set(args, 2, {});
  }

  socket.send(...args);
}

const data = {
  test: true,
};

// provides an optional callback to the request if you match the server response type and id like:
// spark.write({
//   type: 1,
//   data: [null, msg],
//   id,
// });
executePrimusRequest('someRequestType', data, (err, msg) => {});

// listen to custom server response messages like:
// spark.write({
//   type: 0,
//   data: ['someResponseType', msg],
// });
socket.on('someResponseType', (msg) => {});

The following options are built-in (can NOT be changed):

Name | Description | Default --------------------|-------------------------------------------|--------------- authorization | Authorization handler | null pathname | The URL namespace that Primus can own | /primus parser | Message encoder for all communication | JSON transformer | The transformer we should use internally | websockets plugin | The plugins that should be applied | {} pingInterval | Interval at which heartbeats are sent | 30000 global | Set a custom client class / global name | Primus compression | Use permessage-deflate / HTTP compression | false maxLength | Maximum allowed packet size, in bytes | 10485760 transport | Transformer specific configuration | {} idGenerator | Custom spark id generator function | undefined origins | cors List of origins | * methods | cors List of accepted HTTP methods | GET,HEAD,PUT,POST,DELETE,OPTIONS credentials | cors Allow sending of credentials | true maxAge | cors Cache duration of CORS preflight | 30 days headers | cors Allowed headers | false exposed | cors Headers exposed to the client | false