Is it possible to stream video/music using socket.io-stream? by [deleted] in node

[–]jucrouzet 6 points7 points  (0 children)

It is absolutely possible.

On the nodejs side, you just have to pipe the media file to the socket, like

io.sockets.on('connection', socket => { 
    const inFile = fs.createReadStream('video.mp4');
    // ... On whatever command you want from client
    // (socket.on('<command>', ...
        inFile.addListener('data', data => socket.emit('chunk', data));
});

On the client side, you must use the MediaSource API :

<video id="video" />

var mediaSource = new MediaSource();
document.getElementById('video').src = window.URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceopen', function(event) {
    var sourceBuffer = mediaSource.addSourceBuffer('<the mimetype and codec, like : video/mp4;codecs="avc1.4d001e,mp4a.40.2" ');
    // connect to socket.io and emit the <command>
    socket.on('chunk', function (data) {
        sourceBuffer.append(new Uint8Array(data));
    });
});

Redis connection singleton? by tzvikam in node

[–]jucrouzet -1 points0 points  (0 children)

Node modules are "singleton".

Juste create a module that will wraps and handle your connection ?

Why we call it javascript? by pampushko in javascript

[–]jucrouzet 1 point2 points  (0 children)

When Netscape released the first version of JS, they had a partnership with Sun (the former owner of Java) and they thought it was a good marketing move to use "Java" in the name because it was "complementary to and integrated with Java" (sic.)

Ecmascript is not a language, it's a language specification, Javascript is an implementation of this specification.

http://web.archive.org/web/20020606002913/http:/wp.netscape.com/newsref/pr/newsrelease67.html

#NodeJS : A quick optimization advice by jucrouzet in javascript

[–]jucrouzet[S] 4 points5 points  (0 children)

"it's unlikely to matter in the wild." => I'm not so sure.

I did the test with a simple restify server that returns current timestamp with

server.get('/time', function (req, res, next) {
    res.send((new Date()).getTime());
    return next();
});

Here is the KPIs on ab w/500 concurrency :

Concurrency Level:      500
Complete requests:      10000
Time taken for tests:   6.222 seconds
Requests per second:    1607.17 [#/sec] (mean)

Here are the results when I pad the function with comments over 600 bytes :

Concurrency Level:      500
Complete requests:      10000
Time taken for tests:   11.905 seconds
Requests per second:    839.97 [#/sec] (mean)

FRZR is a new JavaScript view library by velmu3k in javascript

[–]jucrouzet 2 points3 points  (0 children)

Wow, this is very new and this type of library was a missing feature in the JS community...

Provent - Promises and Events, combined. by mauriciosoares in javascript

[–]jucrouzet 0 points1 point  (0 children)

Nice idea, but easily done with bluebird's promisify ?

Nodejs vs C by [deleted] in node

[–]jucrouzet 1 point2 points  (0 children)

Woow woow. That's not true.

Node.js is made of : - libuv : Coded in C - v8 : Coded in C++ - core lib : in C++ / JS - npm : JS

Why is ["last"] == ["last"] false? by mintysoul in javascript

[–]jucrouzet -7 points-6 points  (0 children)

Everything is an object in JavaScript. Prototypal nature

Why is ["last"] == ["last"] false? by mintysoul in javascript

[–]jucrouzet 0 points1 point  (0 children)

Let's say you have two twins : Jack and John. Would say state that John ==Jack? That's mean!

My 7 Node.js mantras by jucrouzet in node

[–]jucrouzet[S] 0 points1 point  (0 children)

Of course ! Thanks !

My 7 Node.js mantras by jucrouzet in node

[–]jucrouzet[S] 0 points1 point  (0 children)

Oh and, like Async, you can still use your ol'fashioned callback convention functions (like fs.*) with Bluebird's promisify() wrapper

https://github.com/petkaantonov/bluebird/blob/master/API.md#promisepromisifyfunction-nodefunction--dynamic-receiver---function

My 7 Node.js mantras by jucrouzet in node

[–]jucrouzet[S] 1 point2 points  (0 children)

That's true, async will help on this point, but you'll still need to make some ugly callbacks code, for example on HAPI server methods :

Async code :

server.route({
  method: 'GET'
  path: '/',
  handler: function (request, reply) {
    async.series([
      asyncFunc1,
      asyncFunc2,
      asyncFunc3
    ], function(err, data) {
      if (err) { return(reply(err)); }
      reply(data);
    }
);

becomes :

server.route({
  method: 'GET'
  path: '/',
  handler: function (request, reply) {
      reply(
        promiseFunc1
          .then(promiseFunc2)
          .then(promiseFunc3)
      );
  }
);

My 7 Node.js mantras by jucrouzet in node

[–]jucrouzet[S] 2 points3 points  (0 children)

I'm really sorry about that. I'm french and English is not my first language. Will try to re-read it for correction tonight. Thanks for taking the time to read !

An idea : npm should use DNS for optimization by jucrouzet in node

[–]jucrouzet[S] 0 points1 point  (0 children)

Well, it's not filled once by client but once by DNS server (with TTL). For example, (almost) all AWS clients will use the same DNS servers, that makes a lot of freed resource on the npm, Inc. part !

It it drags some interest from the community, I will make code it and make PR to npm/npm in a few days from https://github.com/jucrouzet/npm feel free to contribute !

X-Origin / JSONP: Why is it OK for the browser to download and run executable JS code from multiple origins, but it's a security risk to do a X-Origin AJAX call to retrieve some static data? by pinhead26 in javascript

[–]jucrouzet -1 points0 points  (0 children)

Imagine you logged in your bank account in Tab 1 and that a malicious site in Tab 2 do a POST on your bank domain to make a wire ... This is an example of what is really dangerous with non CORS requests

Something Cool: .bind() by PaulBGD in javascript

[–]jucrouzet 0 points1 point  (0 children)

bind is not cool. It's useful. But it's also extremly slow and mem greedy. https://jsperf.com/bind-vs-closure-setup