Socket
Socket
Sign inDemoInstall

@droplit/sdk

Package Overview
Dependencies
44
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @droplit/sdk

Give your Node and Web apps instant cloud control


Version published
Maintainers
4
Install size
2.95 MB
Created

Readme

Source

Droplit.io SDK

This SDK gives your application access to the droplit.io REST Api and real-time notifications through websockets!

Checkout droplit.io

About

This library is designed for both NodeJS and browser applications.

Server Notifications: We don't recommend using this SDK for server applications. If you are looking to get server notifications, consider using our Webhooks

Setup

yarn add @droplit/sdk
# or
npm install @droplit/sdk

Usage

Rest API

import * as Droplit from '@droplit/sdk';

const token = process.env.DEVELOPER_TOKEN; // Or User Account token or Server API Key
const droplit = Droplit.instance();
droplit.initialize(Droplit.HOST.IOE, token);

// User Accounts and Server API Key's are not permitted to call ecosystems.list()
droplit.ecosystems.list().then((response) => {
    console.log(response.body);
}).catch(error => {
    console.log(error);
})

Websockets

Initilize websocket connection

import * as Droplit from '@droplit/sdk';

const token = process.env.DEVELOPER_TOKEN; // Or User Account token
const socket = new Droplit.Websocket.Client(Droplit.Websocket.HOST.WS, token);

socket.on('connectSuccess', () => {
    console.log('ws client connected.');
});


socket.on('sessionStartSuccess', (sessionId) => {
    console.log('sessionId', sessionId);
    // Persist sessionId to resume sessions
});

socket.on('serviceNotification', (serviceNotification) => {
    console.log('serviceNotification', serviceNotification);    
});

socket.on('dataNotification', (dataNotification) => {
    console.log('dataNotification', dataNotification);
});

socket.on('close', (code, reason) => {
    console.log('disconnected', code, reason);
    // For `code` values, see Droplit.Websocket.CustomWebsocketStatusCodes and UniversalWs.StatusCode
});

socket.on('error', (error) => {
    console.log(error);
});

Subscribe to changes (managed by rest API calls)


import * as Droplit from '@droplit/sdk';

const deviceId = process.env.DEVICE_ID;
const token = process.env.DEVELOPER_TOKEN; // Or User Account token

const droplit = Droplit.instance();
droplit.initialize(Droplit.HOST.IOE, token);

const socket = new Droplit.Websocket.Client(Droplit.Websocket.HOST.WS, token);

socket.on('connectSuccess', () => {
    console.log('ws client connected.');
});

socket.on('sessionStartSuccess', (sessionId) => {
    console.log('sessionId', sessionId);

    // To subscribe to a resource, you must supply a sessionId and specify `subscription: 'add'`
    droplit.device.info(deviceId, {
        sessionId: sessionId,
        subscription: 'add'
    }).then(response => {
        console.log(response.body);
    })
});

socket.on('serviceNotification', (serviceNotification) => {
    console.log('serviceNotification', serviceNotification);    
});

socket.on('dataNotification', (dataNotification) => {
    console.log('dataNotification', dataNotification);
});

socket.on('close', (code, reason) => {
    console.log('disconnected', code, reason);
});

socket.on('error', (error) => {
    console.log(error);
});

Notes

HTTP

HTTP requests are made using isomorphic-fetch.

Websockets

Websocket transport layer is enabled by universal-ws, which provides a symmetric node/browser websocket api.

Keywords

FAQs

Last updated on 19 Feb 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc