Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ataraxia-services

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ataraxia-services

Services with RPC and events over Ataraxia mesh network

  • 0.8.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ataraxia-services

npm version Dependencies

Services with RPC and events for Ataraxia.

This project provides a service layer on top of a Ataraxia network and allows nodes to easily register services and to call methods and receive events on services on other nodes.

Usage

npm install ataraxia-services
import { Services } from 'ataraxia-services';

const net = ... // setup network with at least one transport

const services = new Services(net);

services.onAvailable(service => console.log(service.id, 'is now available'));
services.onUnavailable(service => console.log(service.id, 'is no longer available'));

// Start the network
await net.start();

// Start the services on top of the network
await services.start();

// Register a service as a plain object
const handle = services.register({
  id: 'service-id',
  
  hello() {
    return 'Hello world';
  }
});

// Classes can be registered and created
services.register(class Test {
  constructor(handle) {
    this.handle = handle;

    this.id = 'service-id';
  }

  hello() {
    return 'Hello World';
  }
})

// Interact with services
const service = services.get('service-id');
if(service) {
  console.log('Service found', service);

  // Call functions on the service
  const reply = await service.hello();
}

Events

ataraxia-services supports emitting and listening to events. The support for events is designed to be used via Atvik.

import { Event } from 'atvik';

class TestService {
  constructor(handle) {
    this.id = 'test';

    this.helloEvent = new Event(this);
  }

  get onHello() {
    // This onX method makes the event available on the service
    return this.helloEvent.subscribable;
  }

  sayHello(message) {
    // Emit an event
    this.helloEvent.emit(message);

    // Return a result
    return 'Hello ' + message + '!';
  }
}

// Register the service
services.register(TestService);

// Get the service either on the same node or another node
const service = services.get('test');

// Listen to the event
const handle = await service.onHello(message => console.log('Service emitted hello event:', message));

// Call the method to emit the event
await service.sayHello('World');

// Unsubscribe from event
await handle.unsubscribe();

FAQs

Package last updated on 17 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc