Skip to content

Commit

Permalink
try fanout
Browse files Browse the repository at this point in the history
  • Loading branch information
comster committed Jan 29, 2018
1 parent decfa48 commit 075b62f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
32 changes: 23 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,40 @@ module.exports = function (cb) {
var server = http.createServer(ecstatic({ root: path.join(__dirname, 'public') }))
var sse = SSE('/data')
var header

var clients = []

input.on('data', function(data){
for(var c in clients) {
clients[c].write(data);
}
})

sse.install(server)

console.log('init chart-stream')

/// TODO MANUALLY MANAGE CONENCTED CLIENTS AND SEND THEM INPUT > FANOUT


sse.on('connection', function (client) {
console.log('client connection...')

var cx = clients.push(client) - 1
if(header) client.write(header);

setTimeout(function(){
console.log('client connection pump starting..')
pump(input, client);
client.on('close', function(){
console.log('client closed')
})
},5000)
client.on('close', function(){
console.log('client closed. remove from clients list len: '+clients.length)
clients.splice(cx, 1);
console.log('client closed. removed from clients list len: '+clients.length)
})


// setTimeout(function(){
// console.log('client connection pump starting..')
// pump(input, client);
// client.on('close', function(){
// console.log('client closed')
// })
// },5000)

// input.once('data', function (chunk) {
// // console.log('input data')
Expand Down
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#graph {
height: 100vh;
}
path {
stroke-width: 4px;
path, path.c3-line {
stroke-width: 3px;
}
</style>
</head>
Expand Down

0 comments on commit 075b62f

Please sign in to comment.