diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js index 902893c96536a33b682a709ec08dd52d0a53d47c..04696158e2b02a6f7d7721fdaad4cca05f514aa5 100644 --- a/web-service/server/src/index.js +++ b/web-service/server/src/index.js @@ -32,6 +32,8 @@ let uri_data = {}; let peer_data = []; +let cfg_to_peer = {}; + /** * A client stream request object. Each source maintains a list of clients who * are wanting frames from that source. Clients can only request N frames at a @@ -244,16 +246,25 @@ app.get('/stream', (req, res) => { function checkStreams(peer) { if (!peer.master) { - peer.rpc("list_streams", (streams) => { - console.log("STREAMS", streams); - for (let i=0; i<streams.length; i++) { - //uri_to_peer[streams[i]] = peer; - let parsedURI = stringSplitter(streams[i]) - peer_uris[peer.string_id].push(parsedURI); - uri_to_peer[parsedURI] = peer; - uri_data[streams[i]] = new RGBDStream(streams[i], peer); - } - }); + setTimeout(() => { + peer.rpc("list_streams", (streams) => { + console.log("STREAMS", streams); + for (let i=0; i<streams.length; i++) { + //uri_to_peer[streams[i]] = peer; + let parsedURI = stringSplitter(streams[i]) + peer_uris[peer.string_id].push(parsedURI); + uri_to_peer[parsedURI] = peer; + uri_data[streams[i]] = new RGBDStream(streams[i], peer); + } + }); + + peer.rpc("list_configurables", (cfgs) => { + console.log("CONFIGS", cfgs); + for (let i=0; i<cfgs.length; i++) { + if (!cfg_to_peer.hasOwnProperty(cfgs[i])) cfg_to_peer[cfgs[i]] = peer; + } + }); + }, 500); // Give a delay to allow startup } } @@ -305,6 +316,11 @@ app.ws('/', (ws, req) => { delete peer_uris[peer.string_id]; } if (peer_by_id.hasOwnProperty(peer.string_id)) delete peer_by_id[peer.string_id]; + + // Clear configurables + for (let c in cfg_to_peer) { + if (cfg_to_peer[c] === p) delete cfg_to_peer[c]; + } }); p.bind("new_peer", (id) => { @@ -324,6 +340,25 @@ app.ws('/', (ws, req) => { return Object.keys(uri_data); }); + p.bind("list_configurables", () => { + let result = []; + for (let c in cfg_to_peer) { + if (cfg_to_peer[c] !== p) result.push(c); + } + console.log("List Configs: ", result); + return result; + }); + + p.proxy("get_configurable", (cb, uri) => { + if (cfg_to_peer.hasOwnProperty(uri)) { + let peer = cfg_to_peer[uri]; + peer.rpc("get_configurable", cb, uri); + } else { + console.log("Failed to get configurable ", uri); + return "{}"; + } + }); + p.bind("find_stream", (uri) => { const parsedURI = stringSplitter(uri) if (uri_to_peer.hasOwnProperty(parsedURI)) {