Comments (5)
you don't have to track the connected sockets you can use io.sockets.connected like this:
ss(socket).on('file', function(incomingstream, data) {
for(var i in io.sockets.connected) {
//don't send the stream back to the initiator
if (io.sockets.connected[i].id != socket.id)
{
var socketTo = io.sockets.connected[i]
var outgoingstream = ss.createStream();
ss(socketTo).emit('file', outgoingstream, data);
incomingstream.pipe(outgoingstream);
}
}
});
from socket.io-stream.
Yeah, there is no way to do that for now, but I think we can implement that as you explain.
Please keep the issue open.
from socket.io-stream.
It is possible to collect all "consumer" sockets in an array, create a outgoing stream per consumer and pipe the stream to all consumers.
var nsp = io.of('/user');
nsp.on('connection', function(socket) {
var query = socket.handshake.query;
debug("/user new connection type: ",query.type);
switch(query.type) {
case "consumer":
consumerSockets.push(socket);
break;
}
debug(" consumerSockets.length: ",consumerSockets.length);
// receive the image
ss(socket).on('image', function(incomingStream, data) {
debug("on image ",data);
for(var i in consumerSockets) {
var consumerSocket = consumerSockets[i];
var outgoingStream = ss.createStream();
ss(consumerSocket).emit('image', outgoingStream, {name: data.name});
incomingStream.pipe(outgoingStream);
}
});
});
But the problem when you run multiple Node.js instances (clustering) is that you never have references to all client sockets. I've used my own Redis pub/sub library to talk to a specific client, but I'm not sure yet how to use that with streams, see:
socketio/socket.io#1811
from socket.io-stream.
Looking through the code I understand socket.io-stream sends chunks of the data using regular emit's. This means implementing a broadcast shouldn't be impossible. Then socket.io-redis would take care of the clustering challenge.
this.sio.emit(exports.event + '-write', id, chunk, encoding, callback);
From: https://github.com/nkzawa/socket.io-stream/blob/master/lib/socket.js#L151
from socket.io-stream.
@celevra You can't use properties like io.sockets.connected
if you want to work clustered and you usually want to to handle scale.
from socket.io-stream.
Related Issues (20)
- Is this project still active? HOT 7
- Streaming to Android
- server > client HOT 1
- Simpler API
- MediaStream HOT 11
- Can you upload a folder?
- events.js:62 Uncaught Error: Uncaught, unspecified "error" event. (Authentication error) HOT 1
- Able to send/receive a native browser stream HOT 1
- An error when using Socket.io-stream with Electron.
- A port to other languages
- Stream interrupted file
- Uncaught TypeError: Cannot read property '_read' of null HOT 3
- Server dont recive emit or client dont emit HOT 3
- Send audio file from node.js server to another node.js server
- Client iOS
- This version of debug is vulnerable to ReDos attacks HOT 3
- In browser console getting error
- [Deprecation] SharedArrayBuffer
- add a settimeout to it to reduce cpu consumption
- Unfortunately there is no support for rooms and broadcasting for now.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket.io-stream.