Comments (18)
Yes, you can write data like that, but stream#write
only accepts Buffer or string, and objectMode
is not supported for now.
from socket.io-stream.
Thanks for your response, does an ArrayBuffer count as a Buffer? That's what I'm attempting to use.
from socket.io-stream.
ArrayBuffer is not Buffer, and I think you need browserify to use Buffer on browser. This is very confusing for users. We have to fix that :(
https://nodejs.org/api/buffer.html
from socket.io-stream.
I wonder if a better solution would be to use socket.io without socket.io-stream and just send my array buffers to have them assembled for me on the server instead. Forgive me for not knowing this but the emits are sent in order if I do that correct? They cannot get all jumbled up?
Or should I change my stream#write calls with socket.io-stream to pass strings and then finagle them a bit on the server after that.
from socket.io-stream.
Socket.io keeps order of sending data. so you can just use socket.io, but splitting data to small chunks and combining them afterwards would be usually troublesome.
So basically, this is what socket.io-stream should support.
from socket.io-stream.
I exposed Buffer
class for use on browser. df60bca
It's just Buffer on node, and you can use it like:
sream.write(new ss.Buffer([1,2,3,4,5]));
from socket.io-stream.
I'm making an effort to convert my typed array into Buffer before writing it to the stream. For some reason I don't think Buffer is turning up properly client side.
1. l = myInt16.byteLength
2. buffer = new ss.Buffer l
3.
4. while l--
5. buffer[l] = myInt16[l]
6.
7. buffer
returns:
Uncaught TypeError: undefined is not a function
on line 2 above.
I think I'm compiling properly from console.
cd node_modules/socket.io-stream
browserify index.js -s ss > socket.io-stream.js
subl socket.io-stream.js
Then I copy and paste the contents of that file into my client side javascript. I see your change in there.
exports.Buffer = Buffer
I'm not sure what's wrong.
from socket.io-stream.
Sorry, it's not released yet. if you'd like to try, change dependencies on package.json like "socket.io-stream": "nkzawa/socket.io-stream#master",
from socket.io-stream.
You're right. I was mistaken, I got that working... but... :(
5::/microphone:{"name":"$stream-read","args":["ba4d0198-d786-494a-b31b-43bff29d4006",16384]}
5:1+:/microphone:{"name":"$stream-write","args":["ba4d0198-d786-494a-b31b-43bff29d4006",{},"buffer"]}
5::/microphone:{"name":"$stream-error","args":["9b57c954-ac95-488d-9c20-7919a8ec3ef6","Invalid non-string/buffer chunk"]}
It's not your fault, this whole week has been a bust so far.
from socket.io-stream.
# @bStream = ss.createStream()
_onAudio: (e) =>
# Audio process
data = e.inputBuffer.getChannelData 0
@bStream.write @_convertInt16toBuffer @_convertFloat32ToInt16 data
_convertFloat32ToInt16: (buffer) =>
# Convert buffer to 16 bit
l = buffer.length
buf = new Int16Array l
while l--
s = Math.max(-1, Math.min(1, buffer[l]))
buf[l] = s * (if s < 0 then 0x8000 else 0x7FFF)
buf.buffer
_convertInt16toBuffer: (buffer) =>
# Convert buffer to stream compatible buffer
buf = new ss.Buffer buffer.byteLength
l = buf.length
while l--
buf[l] = buffer[l]
buf
As a contrast, this all works perfectly sans the _convertInt16toBuffer method, with binaryjs, I'd like to move away from binaryjs. It seems socket.io-stream just doesn't quite like my ss.Buffer generated buffer somehow.
I've also tried returning buf rather than buf.buffer from _convertFloat32ToInt16 with the same result.
from socket.io-stream.
Hmm, I don't know why. As far as I tested, it seems to work well.
Can I ask what version of browserify do you use?
from socket.io-stream.
[email protected] /usr/local/lib/node_modules/browserify
from socket.io-stream.
It looks ok. Sorry, I have no idea ...
The code I tested is the following.
var stream = ss.createStream();
ss(socket).emit('foo', stream);
stream.write(new ss.Buffer([0, 1]));
stream.write(new ss.Buffer([2, 3]));
stream.end();
Works fine with Browserify 9.0.8, on Chrome. What's the difference?
from socket.io-stream.
I dunno man, I'm emitting just the same way. I double checked my convert from arraybuffer to buffer code from somewhere else on the net. I suppose I'm just generating an invalid arraybuffer... or who knows what else.
I'm really sorry I'm not more help. I think for now my implementation doesn't work and I'll need to hack with someone on it. Peer programming in my future.
from socket.io-stream.
@Kequc
Below code can get the stream from client. But I can not store the stream as audio file. Do you have any idea?
Server code:
ss(socket).on('stream_start', function(stream, meta) {
filename = "recordings/"+ new Date().getTime() + ".pcm";
fileWriter = fs.createWriteStream(filename);
stream.pipe(fileWriter);
});
ss(socket).on('close', function() {
if (fileWriter != null) {
fileWriter.end();
}
});
Client code:
function onAudio(e) {
if(!bStream || !bStream.writable)
{
return;
};
var left = e.inputBuffer.getChannelData(0);
var canvas = document.getElementById("canvas");
drawBuffer( canvas.width, canvas.height, canvas.getContext('2d'), left );
console.log("onAudio");
reSample(e.inputBuffer,resampleRate,function(reSampledBuffer){
var channel = reSampledBuffer.getChannelData(0);
bStream.write(convertFloat32ToInt16(channel));
});
}
function convertFloat32ToInt16(buffer) {
var l = buffer.length;
var buf = new Int16Array(l);
var return_buf = new ss.Buffer(l);
while (l--) {
buf[l] = Math.min(1, buffer[l])*0x7FFF;
return_buf[l] = buf[l];
if (l % 100 == 0){
console.log(return_buf[l]);
}
}
return return_buf;
}
from socket.io-stream.
@wyvernbai were you ever able to get it working? Got about as far as you, but not able to save as a .wav
from socket.io-stream.
My implementation that works has me sending base64 encoded data (strings) in chunks to the server, then decoding base64 and writing it to a stream. I'm using a version of this library: https://github.com/chris-rudmin/Recorderjs which encodes my audio into the opus audio codec. The library seems to be fluctuating currently, so it is changing, but it works well to ensure I'm sending a smaller amount of data than wav would require.
Then on the server I simply put it together using stream.write
. Sorry I haven't updated this topic sooner. I thought the topic would have been out of date. Instead of using socket.io-stream I'm just sending raw strings.
Edit: Specifically I'm using my fork. Which is quite out of date by now, but in case it is useful: https://github.com/Kequc/Recorderjs
from socket.io-stream.
Ahh, that's a good approach. Thanks for the detailed response. I will try
your method!
On Mon, Aug 8, 2016 at 2:45 PM, Kequc [email protected] wrote:
My implementation that works has me sending base64 encoded data (strings)
in chunks to the server, then decoding base64 and writing it to a stream.
I'm using a version of this library: https://github.com/chris-
rudmin/Recorderjs which encodes my audio into the opus audio codec. The
library seems to be fluctuating currently, so it is changing, but it works
well to ensure I'm sending a smaller amount of data than wav would require.Then on the server I simply put it together using stream.write. Sorry I
haven't updated this topic sooner. I thought the topic would have been out
of date. Instead of using socket.io-stream I'm just sending raw strings.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#44 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABMLOWdzuegxgIQkv8PKz05NxtVGJJPWks5qd6OUgaJpZM4EES2u
.
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.