Binaryjs + Meteor on the same port

import binaryjs from 'binaryjs';

var binaryserver = new binaryjs.BinaryServer({server: server, path: '/binary-endpoint'});

binaryserver.on('connection', function(client){
  var file = fs.createReadStream(__dirname + '/flower.png');
  client.send(file);
});

What I should pass in “server” argument?
In different ports I’ve been stuck into CORS…

I ran into the same issue a while back, decided to run it on another port by using: https://www.npmjs.com/package/get-ports

So a few snippets that might come in handy:

Getting an open port: tempPort could be your current meteor port for example. Using meteorhacks:async

BinaryJSPort = Async.runSync(function(done){
     GetPorts([tempPort+5], function(err, ports){
         done(null, ports[0]);
     });
}).result;

Starting a binaryjs server with that port:

BinaryJSServer = binaryjs.BinaryServer({
    port: BinaryJSPort
});

Hope this helps!

1 Like

Thank for you reply!

But when I ran this code:


WebApp.rawConnectHandlers.use(function(req, res, next) {
    res.setHeader("Access-Control-Allow-Origin", "*");
    return next();
});
import binaryjs from 'binaryjs';

client = new binaryjs.BinaryClient('ws://localhost:11777');

(from browser FF)

I got CORS restrict anyway.

hi developpers hi n0isy
you can use for example chrome extension to allow cross origin just for testing…
i did it with meteor 1.7 but i think binaryjs does not work with meteor …it’s a long time there with no update.
i installed express with meteor and configured all stuff with no error but binaryjs events does not fire

if anyone success to get things work…pealse share with us

this the correct way to bind meteor with binarys

// server

import { Meteor } from 'meteor/meteor';
import binaryjs from 'binaryjs';

const { httpServer } = WebApp;



Meteor.startup(() => {

    let binaryserver = new binaryjs.BinaryServer({server: httpServer, path: '/binary'});

    binaryserver.on('connection', function(client){

        console.log('binaryjs server is connected');

        /*var file = fs.createReadStream(__dirname + '/flower.png');
        client.send(file);*/
    });

});

// client

import { Meteor } from 'meteor/meteor';
import binaryjs from 'binaryjs';



Meteor.startup(() => {

    let host = location.origin.replace(/^http(s)?/, 'ws') + '/binary';
    let client = new binaryjs.BinaryClient(host);

});

tested with meteor 1.7… if you connect binaryjs without path it works with error because you override meteor connexion but if you use path it does not connect