Thursday, 16 March 2017

Rethinkdb Node.JS .changes() unwanted looping

i have a a problem with Node JS, and rethinkdb module. I'm currently developing program for my thesis

this pieces code of db.js:

var r = require("rethinkdb"); 
var host = "localhost";
var db = "example";
var port = 28015;
class dbs{
    connectToDb(callback){
        r.connect({
        host:host,
        port:port,
        db:db
        },function(err,connection){});
    }

  streamAllData(tableName,callback){
  this.connectToDb(function(err,conn){
    r.table(tableName).changes().run(conn,function(err,cursor){
      if(err){
        return callback(true,err);
      }
      else{
        cursor.next(function(err,rows){
          return callback(null,rows);
        });

      }
    });
  });
}
}

and this pieces of code from server.js

var dbrs = require("./db");
var rdb = new dbrs();
var io = require("socket.io").listen(https.createServer(options,app).listen(port));
io.on("connection",function(socket){
   rdb.streamAllData("userlocation",function(err,data){
      socket.emit("broadcast:userlocation",data);
   });
});

that result is always sending 7 same data . actually mobile phone sending cordinates to server is clean with configured interval.

this unwanted looping is always crashed my browser when im trying to draw driver location to maps.

enter image description here

that is a screenshot from chrome console



via Muhammad Reza