1.3.1 • Published 8 years ago

qaap-pharos v1.3.1

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

GitHub license Build Status npm
NPM

qaap-pharos

(deprecated - please use rpc-websockets)

Pharos wraps the "websockets/ws" library providing JSON RPC 2.0 support on top.

Installation

npm install qaap-pharos

Examples

var Pharos = require('qaap-pharos')

// instantiate Pharos and start listening for requests
var server = new Pharos({
  port: 8080,
  host: 'localhost',
  rpc: {
    root_path: '/rpc',
    version: '1.0'
  }
})

// register an RPC method
server.register('sum', function(params) {
  return params[0] + params[1]
})

// create an event
server.event('feedUpdated')

// get events (getter method)
console.log(server.eventList)

// emit an event to subscribers
server.emit('feedUpdated')

// close the server
server.close()

API

var Pharos = require('qaap-pharos')

var server = new Pharos({
  port: 8080,
  host: 'localhost',
  rpc: {
    root_path: '/rpc',
    version: '1.0'
  }
})

new Pharos(options) -> Pharos

Instantiate a Pharos server.

Parameters:

  • options {Object}: Server options that are also forwarded to ws.
    • port {Number}: Port number on which the server will listen for incoming requests.
    • host {String}: Address on which the server will listen for incoming requests.
    • rpc {Object}:
      • root_path {String}: RPC server endpoint.
      • version {String}: RPC API version.

Once the Pharos class is instantiated, you can use a ws library's instance via server.wss object.

server.register(method, callback)

Registers an RPC method.

Parameters:

  • method {String}: RPC method name.
  • callback {Function}: RPC function that will be fired with a possible parameter object once the method is started.

server.event(name)

Creates a new event that can be emitted to clients.

Parameters:

  • method {String}: RPC method name.
  • callback {Function}: RPC function that will be fired once the method is started.

get server.eventList -> Array

Lists all created events.

server.createError(code, message, data) -> Object

Creates a structured error that can be thrown in a .register callback.

Parameters:

  • code {Number}: Indicates the error type that occurred.
  • message {String}: Provides a short description of the error.
  • data {String|Object}: Details containing additional information about the error.

server.close() -> Promise

Closes the server and terminates all clients.

Event: 'listening'

Emits when the server has started listening for requests.

Event: 'error'

  • <Error>

Emits when a server error is raised.

1.3.1

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.10

8 years ago

1.1.9

8 years ago

1.1.8

8 years ago

1.1.7

8 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago