-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
time system is required for telemetry
Simplify realtime provider Due to nasa/openmct#1594 we no longer need to worry about multiple calls for the same identifier. Host all routes on same port, use host-relative urls for client Update readme
- Loading branch information
Showing
9 changed files
with
93 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,41 @@ | ||
var WebSocketServer = require('ws').Server; | ||
|
||
function RealtimeServer(spacecraft, port) { | ||
this.spacecraft = spacecraft; | ||
this.server = new WebSocketServer({ port: port }); | ||
this.server.on('connection', this.handleConnection.bind(this)); | ||
console.log('Realtime server started at ws://localhost:' + port); | ||
}; | ||
var express = require('express'); | ||
|
||
function RealtimeServer(spacecraft) { | ||
|
||
var router = express.Router(); | ||
|
||
router.ws('/', function (ws) { | ||
var unlisten = spacecraft.listen(notifySubscribers); | ||
var subscribed = {}; // Active subscriptions for this connection | ||
var handlers = { // Handlers for specific requests | ||
subscribe: function (id) { | ||
subscribed[id] = true; | ||
}, | ||
unsubscribe: function (id) { | ||
delete subscribed[id]; | ||
} | ||
}; | ||
|
||
function notifySubscribers(point) { | ||
if (subscribed[point.id]) { | ||
ws.send(JSON.stringify(point)); | ||
} | ||
} | ||
|
||
RealtimeServer.prototype.handleConnection = function (ws) { | ||
var unlisten = this.spacecraft.listen(notifySubscribers); | ||
subscribed = {}, // Active subscriptions for this connection | ||
handlers = { // Handlers for specific requests | ||
subscribe: function (id) { | ||
subscribed[id] = true; | ||
}, | ||
unsubscribe: function (id) { | ||
delete subscribed[id]; | ||
// Listen for requests | ||
ws.on('message', function (message) { | ||
var parts = message.split(' '), | ||
handler = handlers[parts[0]]; | ||
if (handler) { | ||
handler.apply(handlers, parts.slice(1)); | ||
} | ||
}; | ||
}); | ||
|
||
function notifySubscribers(point) { | ||
if (subscribed[point.id]) { | ||
ws.send(JSON.stringify(point)); | ||
} | ||
} | ||
|
||
// Listen for requests | ||
ws.on('message', function (message) { | ||
var parts = message.split(' '), | ||
handler = handlers[parts[0]]; | ||
if (handler) { | ||
handler.apply(handlers, parts.slice(1)); | ||
} | ||
// Stop sending telemetry updates for this connection when closed | ||
ws.on('close', unlisten); | ||
}); | ||
|
||
// Stop sending telemetry updates for this connection when closed | ||
ws.on('close', unlisten); | ||
return router; | ||
}; | ||
|
||
|
||
|
||
module.exports = RealtimeServer; | ||
module.exports = RealtimeServer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
var express = require('express'); | ||
|
||
function StaticServer(port) { | ||
var server = express(); | ||
|
||
server.use('/', express.static(__dirname + '/..')); | ||
|
||
console.log('Open MCT hosted at http://localhost:' + port); | ||
|
||
server.listen(port); | ||
function StaticServer() { | ||
var router = express.Router(); | ||
|
||
router.use('/', express.static(__dirname + '/..')); | ||
|
||
return router | ||
} | ||
|
||
module.exports = StaticServer; | ||
module.exports = StaticServer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters