Skip to content
Snippets Groups Projects
Commit 5711ff31 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Allow readonly access to cfgs from webservice

parent 0fe9c670
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,8 @@ let uri_data = {}; ...@@ -32,6 +32,8 @@ let uri_data = {};
let peer_data = []; let peer_data = [];
let cfg_to_peer = {};
/** /**
* A client stream request object. Each source maintains a list of clients who * 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 * are wanting frames from that source. Clients can only request N frames at a
...@@ -244,16 +246,25 @@ app.get('/stream', (req, res) => { ...@@ -244,16 +246,25 @@ app.get('/stream', (req, res) => {
function checkStreams(peer) { function checkStreams(peer) {
if (!peer.master) { if (!peer.master) {
peer.rpc("list_streams", (streams) => { setTimeout(() => {
console.log("STREAMS", streams); peer.rpc("list_streams", (streams) => {
for (let i=0; i<streams.length; i++) { console.log("STREAMS", streams);
//uri_to_peer[streams[i]] = peer; for (let i=0; i<streams.length; i++) {
let parsedURI = stringSplitter(streams[i]) //uri_to_peer[streams[i]] = peer;
peer_uris[peer.string_id].push(parsedURI); let parsedURI = stringSplitter(streams[i])
uri_to_peer[parsedURI] = peer; peer_uris[peer.string_id].push(parsedURI);
uri_data[streams[i]] = new RGBDStream(streams[i], peer); 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) => { ...@@ -305,6 +316,11 @@ app.ws('/', (ws, req) => {
delete peer_uris[peer.string_id]; delete peer_uris[peer.string_id];
} }
if (peer_by_id.hasOwnProperty(peer.string_id)) delete peer_by_id[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) => { p.bind("new_peer", (id) => {
...@@ -324,6 +340,25 @@ app.ws('/', (ws, req) => { ...@@ -324,6 +340,25 @@ app.ws('/', (ws, req) => {
return Object.keys(uri_data); 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) => { p.bind("find_stream", (uri) => {
const parsedURI = stringSplitter(uri) const parsedURI = stringSplitter(uri)
if (uri_to_peer.hasOwnProperty(parsedURI)) { if (uri_to_peer.hasOwnProperty(parsedURI)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment