@iotracks/container-sdk-nodejs
Native node.js SDK for ioTracks development.
Last updated 3 years ago by iotracks .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @iotracks/container-sdk-nodejs 
SYNC missed versions from official npm registry.

container-sdk-nodejs

This module lets you easily build an ioElement. It gives you all the functionality to interact with ioFog via Local API. Additionally some useful methods to work with ioMessage.

  • send new message to ioFog (sendNewMessage)
  • fetch next unread messages from ioFog (getNextMessages)
  • fetch messages for time period and list of accessible publishers (getMessagesByQuery)
  • get config options (getConfig)
  • create ioMessage JSON object (ioMessage)
  • connect to ioFog Control Channel via WebSocket (wsControlConnection)
  • connect to ioFog Message Channel via WebSocket (wsMessageConnection) and publish new message via this channel (wsSendMessage)

Code snippets:

import module:

  var ioFogClient = require('@iotracks/container-sdk-nodejs');

set up custom host, port and container's ID (in case of no params default values for host and port will be used: 'ioFog', 54321) and pass main callback to trigger when ioFogClient initialization is done:

  ioFogClient.init( 'iofog', 54321, null,
    function () {
        // any code to perform after ioFog is initialized
    }
  );

REST calls

post new ioMessage to ioFog via REST call:

  ioFogClient.sendNewMessage(
    ioFogClient.ioMessage(
                 {
                     'tag': 'Bosch Camera 8798797',
                     'groupid': 'group1',
                     'sequencenumber': 2,
                     'sequencetotal': 100,
                     'priority': 5,
                     'authid': 'auth',
                     'authgroup': 'authgrp',
                     'chainposition': 10,
                     'hash': 'hashingggg',
                     'previoushash': 'prevhashingggg',
                     'nonce': 'nounceee',
                     'difficultytarget': 30,
                     'infotype': 'image/jpeg',
                     'infoformat': 'base64',
                     'contextdata': 'gghh',
                     'contentdata' : 'sdkjhwrtiy8wrtgSDFOiuhsrgowh4touwsdhsDFDSKJhsdkljasjklweklfjwhefiauhw98p328'
                 }),
    {
        'onBadRequest':
            function(errorMsg) {
                console.log(errorMsg);
            },
        'onMessageReceipt':
            function(messageId, timestamp) {
                console.log(messageId + ' : ' + timestamp);
            },
        'onError':
            function(error) {
                console.log(error);
            }
    }
  );

get list of ioMessages by time frame for accessible publishers from ioFog via REST call

  ioFogClient.getMessagesByQuery( Date.now(), Date.now(), ['PUBLISHER'],
    {
        'onBadRequest':
            function(errorMsg) {
                console.log(errorMsg);
            },
        'onMessagesQuery':
            function(timeframestart, timeframeend, messages) {
                console.log(timeframestart + ':' + timeframeend);
                console.log(messages);
            },
        'onError':
            function(error) {
                console.log(error);
            }
    }
  );

get list of next unread ioMessages via REST call

  ioFogClient.getNextMessages(
    {
        'onBadRequest':
            function(errorMsg) {
                console.log(errorMsg);
            },
        'onMessages':
            function(messages) {
                console.log(messages);
            },
        'onError':
            function(error) {
                console.log(error);
            }
    }
  );

get container's config via REST call

  ioFogClient.getConfig(
    {
        'onBadRequest':
            function(errorMsg) {
                console.log(errorMsg);
            },
        'onNewConfig':
            function(config) {
               console.log(config);
            },
        'onError':
            function(error) {
                console.log(error);
            }
    }
  );

WebSocket(WS) calls

open WS Message Channel to ioFog with callback that will be executed on open socket (in this example - sends new message via this channel)

  ioFogClient.wsMessageConnection(
    function(ioFogClient) {
        var ioMsg = ioFogClient.ioMessage(
                 {
                     'tag': 'Bosch Camera 8798797',
                     'groupid': 'group1',
                     'sequencenumber': 2,
                     'sequencetotal': 100,
                     'priority': 5,
                     'authid': 'auth',
                     'authgroup': 'authgrp',
                     'chainposition': 10,
                     'hash': 'hashingggg',
                     'previoushash': 'prevhashingggg',
                     'nonce': 'nounceee',
                     'difficultytarget': 30,
                     'infotype': 'image/jpeg',
                     'infoformat': 'base64',
                     'contextdata': 'gghh',
                     'contentdata' : 'sdkjhwrtiy8wrtgSDFOiuhsrgowh4touwsdhsDFDSKJhsdkljasjklweklfjwhefiauhw98p328'
                 });
        ioFogClient.wsSendMessage(ioMsg);
    },
    {
        'onMessages':
            function(messages) {
                console.log(messages);
            },
        'onMessageReceipt':
            function(messageId, timestamp) {
                console.log(messageId + ' : ' + timestamp);
            },
        'onError':
            function(error) {
                console.log(error);
            }
    }
  );

Open WS Control Channel to ioFog

  ioFogClient.wsControlConnection(
    {
        'onNewConfigSignal':
            function() {
                console.log('New config is awaiting.');
            },
        'onError':
            function(error) {
                console.log(error);
            }
    }
  );

Current Tags

  • 1.1.22                                ...           latest (3 years ago)

26 Versions

  • 1.1.22                                ...           3 years ago
  • 1.1.21                                ...           3 years ago
  • 1.1.20                                ...           3 years ago
  • 1.1.19                                ...           3 years ago
  • 1.1.18                                ...           3 years ago
  • 1.1.17                                ...           3 years ago
  • 1.1.16                                ...           4 years ago
  • 1.1.15                                ...           4 years ago
  • 1.1.14                                ...           4 years ago
  • 1.1.13                                ...           4 years ago
  • 1.1.12                                ...           4 years ago
  • 1.1.11                                ...           4 years ago
  • 1.1.10                                ...           4 years ago
  • 1.1.9                                ...           4 years ago
  • 1.1.8                                ...           4 years ago
  • 1.1.7                                ...           4 years ago
  • 1.1.6                                ...           4 years ago
  • 1.1.5                                ...           4 years ago
  • 1.1.4                                ...           4 years ago
  • 1.1.3                                ...           4 years ago
  • 1.1.2                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 26
This Month 27
Last Day 0
Last Week 1
Last Month 0
Dependencies (3)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |