Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

raw events stream for new api version

  • Loading branch information...
commit 4320fef2ed2fbfbabff94a3bdc3a03082b024e15 1 parent e7ce58c
@soldair soldair authored
Showing with 31 additions and 3 deletions.
  1. +9 −1 browser.js
  2. +22 −2 lib/api.js
View
10 browser.js
@@ -80,13 +80,21 @@ module.exports = window.pinoccioAPI = function(opts){
};
// request some or all stats by account.
- // stats are defined as a time series of reports
+ // stats are a time series of report data
// if multiple reports are provided they
api.stats = function(obj){
//
return a.stats(api.token,obj);
}
+ // get the raw events stream.
+ // to subscribe to a troops raw events you must either execute a command on a scout in that troop or watch the troop
+ // api.rest({url:"/v1/{troopid}",method:"watch"},console.log.bind(console))
+ api.events = function(){
+ //
+ return a.events(api.token);
+ }
+
return api;
}
View
24 lib/api.js
@@ -1,7 +1,7 @@
// retry rpc calls and resume streams and live streams.
// a connection is a function that returns
var through = require('through');
-//var rest = require('./resthttp');
+var json = require('./json');
var connection = require('./connection');
var repipe = require('repipe');
@@ -25,7 +25,7 @@ module.exports = function(config,reconnect){
var e = new Error("call timedout");
e.code = "E_TIMEOUT";
_cb(e);
- if(streamKey) delete expectingStream[k];
+ if(streamKey) delete o.expectingStream[streamKey];
},z.restTimeout);
var _cb = function(err,data){
@@ -114,6 +114,23 @@ module.exports = function(config,reconnect){
});
return s; // resume!
+ },
+ events:function(){
+ var s = through();
+ repipe(s,function(err,last,done){
+ if(err && err.code != 'E_MDM') return done(err);
+
+ if(last) o.start = last.key;
+ getConnection(function(err,con){
+ if(err) return done(err);
+ done(false,con.mdm.createReadStream({type:"events"}));
+ });
+ });
+
+ return s.pipe(through(function(data){
+ data = json(data);
+ if(data) this.queue(data);
+ }));
}
};
@@ -125,7 +142,10 @@ module.exports = function(config,reconnect){
if(reconnect.connected) o.connection = connection.rpc(reconnect._connection);
reconnect.on('connect',function(s){
o.connection = connection.rpc(s);
+
+ console.log('bound connection listener!');
o.connection.mdm.on('connection',function(stream){
+ console.log('mdm got stream from connection listener')
// the server has opened a stream from me.
if(stream.meta && stream.meta.type == "rest-stream") {
if(o.expectingStream[stream.meta.id]) {
Please sign in to comment.
Something went wrong with that request. Please try again.