Coder Social home page Coder Social logo

nanomsg-browser's People

Contributors

void-dragon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nanomsg-browser's Issues

Cannot send

Hi, I encountered a bug when trying to send a message using the PAIR socket. The websocket closed for no apparent reason. Later i discovered that when it closes the event carries an error code, which gave me 1003. Which according to https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent means unsupported data. Please log it in the debug mode. It's too useful to be ignored.

The solution was to convert the string manually to something the websocket supports like an ArrayBuffer. I got this working with the nng pair example code available here: https://nanomsg.org/gettingstarted/nng/pair.html

I debugged your code on Repl.it, so I can give you the link to a working example: https://repl.it/repls/StrongExternalFan

Anyway, thank you very much for publishing your code. It saved me loads of time regardless of this bug.

As a bonus, your code seems to be compatible with NNG. Hurray 🥳

Features proposal

Hello,

First of all, thank you for this great project. I am currently using it to communicate with server-side nng endpoints and this works great.
I would like to know if the following additions might interest you:

  • As nng / nanomsg communication protocols and dialers / listeners are orthogonal concepts, the fact that the client cannot create (listen) websockets won't prevent to the client to be a publisher / replier (but it will have to connect to all the subscribers / requesters beforehand or dynamically)
  • req/rep protocol is supposed to be reliable in the sense that requests are resent after setup timeout value. This does not look like it is implemented yet in nanomsg-brwowser and as websockets rely on the TCP protocol which is supposed to be reliable this may not be necessary. However it could allow to add a certain degree of reliability at the application level in case of a replier having received the message but having not processed it for whatever reason / error.

What do you think?

not connecting (firefox)

On all browsers it works just fine, except when using Firefox (67.0.4 , Ubuntu18.04 ), it never connects.

in debugmode I see this:

nanomsg connect to: ws://0.0.0.0:5555/

and somewhat later

Firefox can’t establish a connection to the server at ws://0.0.0.0:5555/.
nanomsg close: ws://0.0.0.0:5555/

It seems it never gets to ws.onopen

Other browsers work and correctly show:

nanomsg connect to: ws://0.0.0.0:5555/
nanomsg.js:1 nanomsg connected: ws://0.0.0.0:5555/

Configuration and modules

Setting the package wide configuration variables have no effect when used with modules. For example, the following:

import nanomsg from 'nanomsg-browser';
nanomsg.receiveArrayBuffer = true;
nanomsg.debug = true;

const sub = new nanomsg.Socket(nanomsg.SUB);
sub.connect(subaddr);
sub.on('data',  (msg) => {
    console.log(typeof msg);
});

logs "string", while I would expect an Array Buffer.

I believe the problem is here:

if (typeof exports !== 'undefined') {
  Object.assign(exports, nanomsg);
}

Which means exports is now a copy of the nanomsg object, not a reference, and changes to it are not reflected in the object the Socket methods see. Keeping the CommonJS syntax, you can instead do:

if (typeof module !== 'undefined') {
  module.exports = nanomsg;
}

I'm not sure how this will work with other systems such as ES6 modules, but I suspect that will properly will probably require something different. Adding getters and setters might be a solution.

Support ES6 module import

You already use npm for package install like this:
npm install nanomsg-browser

But need to support import like this:

<script type="text/javascript">
  import nanomsg from 'nanomsg-browser'
  // Milliseconds between reconnects.
  nanomsg.reconnectTime = 10 * 1000;
  // Show some debug logging in the console.
  nanomsg.debug = true;
  // Receives ArrayBuffer objects instead of strings. Default is `false`.
  nanomsg.receiveArrayBuffer = false;
</script>

Instead of brutal import from node_modules

Just use export default nanomsg for example

nng compatibility

Hi,
Have you ever tested it with nng version? As stated in the documentation, nng is wire compatible with nanomsg. I am just curious about using Connect method instead of Dial to connect to a nng socket.

Afshin

Binary messages

Current implementation cannot deal binary data because it uses 'readAsText()' to read the data.
(There are same problem in 'send()' because it uses 'charCodeAt()')

What do you think?
Is it reasonable to add option to use binary data, like below?

nanomsg.binary = true

Small fix in the readme example

Hello, I may be wrong, but in this example in the readme:

// be hippster, be async/await
await sock.connect('ws://myhost:8080');
const answer = await sock.send('some cool msg');
console.log('got =>', msg);

shouldn't you log answer to the console instead of msg?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.