Giter Club home page Giter Club logo

devicehive-javascript's People

Contributors

andreylatysh avatar antgrisha avatar denisantonenko avatar heash avatar itrambovetskyi avatar mykytaliashenko avatar nikolay-kha avatar sitnik avatar tmatvienko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

devicehive-javascript's Issues

Problem with api (rest or websocket) type determination.

Hello ,

I have a problem with the determining of api type.
The version of NodeJS that I use is v7.10.1 .
Currently I'am doing this:

const refreshToken = "xxxx.xxx.xxxx"
const serverURL = "https://playground.devicehive.com/api/rest"
const devicehive  = require('devicehive');

async function Authenticate(token, url){
  return await new devicehive({
    refreshToken: refreshToken,
    serverURL: serverURL
  })
}


async function main(){
  try{
    let conn = await Authenticate(refreshToken,serverURL)
    let info = await conn.getInfo();
    console.log(info)
    let networks = await conn.listNetworks({})
    console.log(networks)
    let saveDevice = await conn.putDevice('44m6',{})
    console.log(saveDevice)
    let device = await conn.getDevice('44m6')
    console.log(device)
    await conn.subscribeCommands('44m6',function(cmd){ // problem here
      console.log(cmd)
    },{names:'hi'})
  }catch(err){
    console.log(err)
  }
}

main()

The log result that I get is this:

api.js init function api type = ht
api.js init function https://playground.devicehive.com/api/rest
{ apiVersion: '3.3.2',
  serverTimestamp: '2017-09-30T15:23:33.995',
  webSocketServerUrl: 'ws://playground.devicehive.com/api/websocket' }
[ Network {
    id: 35,
    name: 'Network LJXKWO for ([email protected])',
    description: 'Playground Network' } ]
{}
Device {
  id: '44m6',
  name: '44m6',
  data: null,
  networkId: 35,
  isBlocked: false,
  _commandsSubscribers: {},
  _notificationsSubscribers: {} }
api.js subscribeCommands function api type = undefined
TypeError: api.commandsSubscribe is not a function
    at DeviceHive.subscribeCommands (/home/mike/Desktop/Devicehive_dev/node_modules/devicehive/lib/DeviceHive.js:344:18)
    at main (/home/mike/Desktop/Devicehive_dev/connector.js:25:16)
    at process._tickCallback (internal/process/next_tick.js:109:7)

I tried to debug this problem and realized that,
when DeviceHive class constructor is called it runs init function from /src/api.js file, and the
init function returns the API determined by the serverURL which in my case should be 'ht'.
Little bit later when i try to call subscribeCommands the error appeared. I printed the value of 'type' from the subscribeCommands function

// lib/DeviceHive.js
subscribeCommands(deviceIds, subscriber, commandFilter){
    commandFilter.deviceIds = deviceIds;
    console.log('api.js subscribeCommands function api type = ' + type)
    if (type === `ht`){
      const filterKey = JSON.stringify(commandFilter);
      this._commandsSubscribers[filterKey] = subscriber;
      this._pollCommands(commandFilter);
      return Promise.resolve();
    } else {
      return api.commandsSubscribe(commandFilter, subscriber, DeviceCommand);
    }
  }

So type turned out to be undefined and the code ends up in the else block and tries to call the function commandsSubscribe which does not exist in rest api.

When I force the value of 'type' to 'ht' in src/api.js everything works fine.

Can you please tell me if I am doing something wrong, or the problem is really there.

Thank you,
Mihail Lyaskov

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.