Giter Site home page Giter Site logo

microwavekonijn / ps2census Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 5.0 1.82 MB

The PS2 Census Client is a tool to simplify the interaction with the Planetside 2 Census API.

Home Page: https://www.npmjs.com/package/ps2census

License: Apache License 2.0

TypeScript 98.91% JavaScript 1.04% Shell 0.04%
planetside2 ps2 typescript websocket node api-client census-api nodejs

ps2census's Introduction

PS2 Census Library

CI npm version downloads Dependencies GitHub

About

The PS2 Census library is here to simplify the interaction with the Planetside 2 Census API for Javascript and Typescript projects.

Requirements

Event Stream

  • Node.js v14+ or any modern browser with WebSocket support;
  • DBG Census API Service ID.

Rest API

  • ES6;
  • DBG Census API Service ID(optional, but recommended).

Installation

npm install ps2census

For better performance it is recommended to install bufferutil and utf-8-validate, though this is optional. The --save-optional flag can be used to install them as optionalDependencies.

Getting started

Event Stream

const { CensusClient } = require('ps2census');

const subscriptions = {
  worlds: ['10'],
  eventNames: ['MetagameEvent'],
};

const client = new CensusClient('ServiceID', 'ps2', {
  streamManager: {
    subscription: subscriptions,
  },
});

client.on('ps2Event', event => {
  // Handle the event, for more information see http://census.daybreakgames.com/#websocket-details
});
// or
client.on('facilityControl', event => {
}); // Note that the event always starts with a lower case letter

client.on('subscribed', subscription => {
}); // Notification of a subscription made by the event stream
client.on('duplicate', event => {
}); // When a duplicate event has been received
client.on('ready', () => {
}); // Client is ready
client.on('reconnecting', () => {
}); // Client is reconnecting
client.on('disconnected', () => {
}); // Client got disconnected
client.on('error', error => {
}); // Error
client.on('warn', error => {
}); // Error, when receiving a corrupt message

client.watch();

// To terminate the client
client.destroy();

Rest API

const { Rest } = require('ps2census');

const client = new Rest.Client('ps2ps4eu', { serviceId: 'example' });

// Get character with items
client
  .getQueryBuilder('character')
  .resolve('item')
  .exactMatchFirst(true)
  .get({ 'name.first_lower': '^microwave' })
  .then(characters => {
    // Process the data
  });

Nanite Systems ESS

With the Census ESS being having some issues the NS ESS has made its entrance. Basic usage with Typescript:

new CensusClient('serviceid', 'ps2', {
  streamManager: {
    endpoint: 'wss://push.nanite-systems.net/streaming',
  },
});
// or
new CensusClient('serviceid', 'all' as any, {
  streamManager: {
    endpoint: 'wss://push.nanite-systems.net/streaming',
  },
});

Documentation

Contribution

Please make sure not to create duplicate issues. When making a PR make sure to check if eslint doesn't report any problems.

Disclaimer

The PS2 Census Library comes with no warranties. This software is as is and usage is at the developer/users own discretion.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.