Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow simpler direct data access #3

Open
r1chardj0n3s opened this issue Oct 22, 2014 · 4 comments
Open

Allow simpler direct data access #3

r1chardj0n3s opened this issue Oct 22, 2014 · 4 comments

Comments

@r1chardj0n3s
Copy link
Contributor

The current module makes working directly with the raw data coming from the socket tricky. I would like to add an option to not automatically JSON encode/decode the data being sent and retrieved. This would be defaulted to enabling the parsing, for backwards compatibility.

@wilk
Copy link
Owner

wilk commented Nov 8, 2014

JSON is good for sending complex data through the network.
What's the alternative for non-JSON encoded data?
Which is the encoding that ng-websocket needs to send data with the disabled JSON flag?

@r1chardj0n3s
Copy link
Contributor Author

Hi, I agree JSON is a good idea, but in my use case the websocket is a terminal connection to a virtual machine serial console - raw terminal data :)

@wilk
Copy link
Owner

wilk commented Nov 9, 2014

Ok but how do you send complex data through the network?

For instance, this is how ng-websocket sends data via websocket:

var ws = new WebSocket(url),
      complexData = {a:10, b:'hello', c:{ca:20, cb: 'world'}, d: ['a', 'b', 10, {da: 15}]};

ws.send(JSON.stringify(complexData));

What's your way?

@r1chardj0n3s
Copy link
Contributor Author

My current use-case is just the console connection, like so:

      var socket = $websocket.$new(scope.connection.url, ['binary', 'base64']);
      ...
      term.on('data', function (data) {
        socket.$$ws.send(data);
      });
      socket.$on('$message', function (message) {
        if (message instanceof Blob) {
          var f = new FileReader();
          f.onload = function () {term.write(f.result); };
          f.readAsText(message);
        } else {
          term.write(message);
        }
      });

(from https://github.com/r1chardj0n3s/angboard/blob/master/app/scripts/directives/console.js)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants