tabris-js
tabris-js copied to clipboard
Socket.IO integration
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?
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
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?
@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.
@bev-on We haven't tried it that way yet. But we will have a look and let you know.
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.
Is there any chance to see normal working solution in nearest future?
+1 XHR polling is not an option
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?
@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.
@mpost sounds really good, thx for response
@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
WebSockets are supported in 2.0.0. Could you try again with the latest version npm install tabris@latest
.
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?
@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
I'm using the latest tabris client [email protected]
I tried using ttys, and now instead of missing tty, it shows missing fs.. from ttys itself.
@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?
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..
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.
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..
@NickLD A basic fs
API was recently added in #1364
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"
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 usingXHR
. To make it work I had to modify socket.io.js to change the lineXHR.prototype.supportsBinary = true;
toXHR.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:
xhr.responseType
- "arraybuffer" #613
- "blob"
xhr.response
support for response types:
ArrayBuffer
#613Blob
xhr.send(data)
argument types:
ArrayBuffer
#613Blob
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
We can't use socket.io-client
at the moment.
engine.io-client
uses the xmlhttprequest-ssl
module, where errors occur due to the lack of implementation of the Node API.
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:
- Move
fs
fromtabris
tofs
module - Make a
url
module (or useurl-polyfill
) - Make
child_process.spawn
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