eclipsesource / tabris-js

Create native mobile apps in JavaScript or TypeScript.
https://tabrisjs.com
BSD 3-Clause "New" or "Revised" License
1.4k stars 170 forks source link

Socket.IO integration #598

Open bev-on opened 9 years ago

bev-on commented 9 years ago

Is there any way to integrate socket.io service in tabrisjs app?

For web it's really easy, all you have to do is include socket.io javascript file and that's it:

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io('http://localhost');
  socket.on('news', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>

how should I use socket.io.js in tabrisjs? Can I load it as module?

cookieguru commented 9 years ago

Just add it to the dependencies section of your package.json. Here's an example with chart.js:

https://github.com/eclipsesource/tabris-js/tree/v1.1.0/examples/chart

gmitros commented 9 years ago

Tabris.js currently doesn't have client side support for WebSocket, so the core functionality would not work. @bev-on What would you like to do with socket.io? Maybe engine.io is an option?

bev-on commented 9 years ago

@gosia-eclipsesource @cookieguru Thanks!

@gosia-eclipsesource I need it for simple text exchange. I will try to use engine.io as client in my app and I will add it at dependencies as @cookieguru suggested it. Can I connect socket.io server using engine.io client or should I use engine.io as server too? Because I can't touch anything server side and it's already running socket.io.

gmitros commented 9 years ago

@bev-on We haven't tried it that way yet. But we will have a look and let you know.

cpetrov commented 9 years ago

Tested socket.io-client [git][npm] in a very simple use case for text-based data exchange. As WebSocket is not supported yet (see #188), the client falls back to using XHR. To make it work I had to modify socket.io.js to change the line XHR.prototype.supportsBinary = true; to XHR.prototype.supportsBinary = false;.

For the module to be supported out of the box with XHR and to enable binary data exchange, following web interfaces and XHR features would need to be supported:

There may be more browser APIs which need to be supported for the client to work out of the box.

sergio-doman commented 8 years ago

Is there any chance to see normal working solution in nearest future?

sand123 commented 8 years ago

+1 XHR polling is not an option

sergio-doman commented 8 years ago

Is this possible to create static local html file with connected socket.io library, open it in hidden webview and organize some kind of "tunnel" between my apps logic and sockets?

mpost commented 8 years ago

@sergio-doman A direct communication is currently not possible via a hidden WebView. We are currently working on ArrayBuffers which should add direct support in the very near future.

sergio-doman commented 8 years ago

@mpost sounds really good, thx for response

mpost commented 8 years ago

@sergio-doman With the advancements in ArrayBuffers we are also pushing a WebSocket integration so expect to have something in your hands in the not to distant future: https://github.com/eclipsesource/tabris-js/issues/188#issuecomment-196724300

ralfstx commented 7 years ago

WebSockets are supported in 2.0.0. Could you try again with the latest version npm install tabris@latest.

NickLD commented 7 years ago

Maybe it's just me, but I cannot get socket.io-client to work with tabris. I Loaded in the javascript file and added it to the dependencies. Then, I required it in the script, and wrote some code to tell it to connect, and console.log saying that it works.

When running the code on my device, no errors arise, but also nothing happens. Not sure whats going on at this point. I'm certain the socket.io server works correctly, as I have other socketio clients connecting to it without a problem (server is over HTTPS)

I also then tried using the npm package "socket.io-client" but that throws an error when running about the missing tty module.

Any thoughts about what could be going on?

cookieguru commented 7 years ago

@NickLD Which Tabris.js and client versions are you using?

You might also try the ttys package as mentioned in https://github.com/eclipsesource/tabris-js/issues/1293#issuecomment-299614026

NickLD commented 7 years ago

I'm using the latest tabris client tabris@2.0.0-rc1

I tried using ttys, and now instead of missing tty, it shows missing fs.. from ttys itself.

cookieguru commented 7 years ago

@NickLD Sounds like the same issues as mentioned in the other thread.

Is there something you're after that Socket.io provides that isn't part of WebSocket?

NickLD commented 7 years ago

Well, the rest of my service. which i'm trying to create the app for, uses socket.io for all the other endpoints and clients. Being able to keep everything consistent would be ideal. I suppose it would be entirely possible to implement a socket.io client from scratch, but it would be so much better to be able to use the official client for obvious reasons.

I also need support for receiving binary payloads, which I isn't available yet, but is in the works if I understand. XHR polling isn't really an option either..

cookieguru commented 7 years ago

Ditto the sentiments about XHR and code re-usage.

I haven't looked at the Socket.io source myself; do you know why the client would need access to the filesystem? If it's ephemeral storage, you could probably stub the fs methods out and have them write to memory and get the same functionality.

NickLD commented 7 years ago

Socket.IO client doesn't use fs itself, but it appears that ttys does. It seems ttys uses it to emulate stdout?

https://github.com/TooTallNate/ttys/blob/master/index.js

I'm still not sure why the client needs this in the first place. This is with the npm version of socketio client. I tried the browser socketio client, and while it didnt throw any errors, it seems to just do nothing. Very confusing..

cookieguru commented 7 years ago

@NickLD A basic fs API was recently added in #1364

zswDev commented 6 years ago

I found using socket.io.js can, although this is the browser used, this is the URL"https://cdn.bootcss.com/socket.io/2.0.3/socket.io.js"

fax1ty commented 4 years ago

Tested socket.io-client [git][npm] in a very simple use case for text-based data exchange. As WebSocket is not supported yet (see #188), the client falls back to using XHR. To make it work I had to modify socket.io.js to change the line XHR.prototype.supportsBinary = true; to XHR.prototype.supportsBinary = false;.

For the module to be supported out of the box with XHR and to enable binary data exchange, following web interfaces and XHR features would need to be supported:

  • the Blob constructor
  • xhr.responseType

    • "arraybuffer" #613
    • "blob"
  • xhr.response support for response types:

    • ArrayBuffer #613
    • Blob
  • xhr.send(data) argument types:

    • ArrayBuffer #613
    • Blob

There may be more browser APIs which need to be supported for the client to work out of the box.

At the moment, we already have Blob, ArrayBuffer and WebSocket. I will try to connect socket.io-client to socket.io as soon as I can

fax1ty commented 4 years ago

We can't use socket.io-client at the moment.

image

engine.io-client uses the xmlhttprequest-ssl module, where errors occur due to the lack of implementation of the Node API.

image

Even if there is a easy replacement for two modules, child_process must be done natively.

What do we need from the Tabris team to make socket.io-client worked without errors:

  1. Move fs from tabris to fs module
  2. Make a url module (or use url-polyfill)
  3. Make child_process.spawn
mpost commented 4 years ago

I doubt that child_process.spawn will not be possible on a mobile device as you are not able to create a new process.

It likely makes more sense to wrap the official native socket.io sdk libraries in a tabris plugin. eg https://github.com/socketio/socket.io-client-java