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

Compatibility Socket.io 1.0 #9

Open
javg2k opened this issue Oct 26, 2014 · 46 comments
Open

Compatibility Socket.io 1.0 #9

javg2k opened this issue Oct 26, 2014 · 46 comments

Comments

@javg2k
Copy link

javg2k commented Oct 26, 2014

There is a way to make this module compatible with the new version socket io 1.0?

@yuchi
Copy link

yuchi commented Dec 12, 2014

We at @smclab are working on this. Please watch this repository or this thread to get updates!

@rborn
Copy link

rborn commented Dec 12, 2014

Amazing news :)

Sent from my iPhone

On Dec 12, 2014, at 11:26 AM, Pier Paolo Ramon [email protected] wrote:

We at @smclab are working on this. Please watch this repository or this thread to get updates!


Reply to this email directly or view it on GitHub.

@yuchi
Copy link

yuchi commented Dec 12, 2014

The idea is to be able to do the following

# this installs both `socket.io` and `tiws`
gittio install socket.io
var io = require('socket.io');
var socket = io('url');

socket.on('message', function (data) {
  Ti.API.info(data);
});

:)

@HilkoLantinga
Copy link
Contributor

Any news or help wanted?

@yuchi
Copy link

yuchi commented Dec 19, 2014

@HilkoLantinga Our titaniumifier is almost 1.0.0, with it we’ll have full gitTio integration, so once it’s out we’ll start working on ti-socket.io.

In case, would you be interested in helping us?

@HilkoLantinga
Copy link
Contributor

Of course as I'd love to finally get rid of 0.9.16 in my own software, but I must say I failed miserably with my previous attempt on 1.0.x of socket.io even with the help of Guillermo. It was like staring in to the abyss, I got to the point that no more errors occurred, but it also wouldn't connect and I was totally clueless of why. Guillermo was and probably still is interested of supporting Titanium so make sure to ask him as well when you have an issue that you can't work out.
https://github.com/guille

edit: This is what I had with my last version (attempting 1.0.4 at the time):
I can see that WS.prototype.check runs every 20 seconds and returns true. Nothing else seems to happen.

And my explanation of the diffs for Titanium to Guillermo:
1) Titanium supports CommonJS so it has require, but require does not support the node_module layout or require a folder (index.js).
2) Titanium does not have document, navigator, global, XMLHttpRequest or WebSocket globals.
3) Titanium does have Titanium.Network.createHTTPClient (mostly implements the XMLHttpRequest specification) and there is a module (with socketrocket) called net.iamyellow.tiws that has a createWS method (WebSocket like, but .addEventListener('open', function () {... instead of .onopen = function () {... ).

Here you can see the main changes that needed to be made with 0.9.x: http://www.diffnow.com/?report=psxmb

At the moment I'm thinking of an extra make file in socket.io-client that creates a titanium/socket.io.js which does not use browserify but uses require with adjusted paths and maybe does not use engine.io, but the WebSocket directly.

Two options Guillermo mentioned would be replacing engine.io with an alternative that only uses tiws or add a JSON long poll transport using Titanium.Network.createHTTPClient to engine.io.

I only went for the first as I'm pretty biased towards websockets, however I must admit that not having to use modules (SocketRocket/Android-WebSocket) is appealing as well as it would make maintenance between IOS and Titanium updates virtually non existent and would make it a lot easier for people to use.

@ravivarma434
Copy link

Can any one help in How to call TCP URL from "socket.io.js" from IOS in Titanium ??

@yuchi
Copy link

yuchi commented Jan 6, 2015

Titaniumifier reached v1.0.0, and gitTio is integrated, so we’ll start working on this shortly.

@HilkoLantinga thank you so much for this valuable info. I’ll get in touch asap with the roadmap. Drop me a line on twitter (_pier) or via email ([email protected]).

@yuchi
Copy link

yuchi commented Jan 6, 2015

@ravivarma434 sorry, by now I have no idea.

@ravivarma434
Copy link

@yuchi Thanks, Any body Please help me in this issue.

@ndob
Copy link
Contributor

ndob commented Jan 6, 2015

I've been using socket io 1.2.0 on Android (with tiws). If it helps, here is a gist with a patched socket.io and a diff from vanilla socket io:
https://gist.github.com/ndob/4742514cd23eec7a81a3

There are shortcomings (though at the moment, they are not relevant for my usage):

  • Only websocket transport works. ie. connect with
 io('https://server.ip:1111', { transports: ["websocket"] });
  • Works only on Android. iOS connection times out. I've debugged it a bit and one possible clue for investigating further is marked with following comment: "TODO: Figure out and fix. This causes initial connection to time out on iOS."

@HilkoLantinga
Copy link
Contributor

I know nothing of native modules, but what suprises me is that I only see nsstring in tiws, shouldn't it also use nsdata and buffer for when the server returns binary?
I also did a bit more thinking about websocket vs others, but I think I might have found another reason for using socketrocket. As it uses CFStream I think it also would use the AES extensions in 64 bit, which would make wss encryption 8x faster on an Apple a7. I did ask someone from Appcelerator if their HTTP request uses the extension.

@omorandi
Copy link
Owner

@HilkoLantinga Actually the current version of TiWS for iOS only supports string data. Supporting binary is doable, but it requires some more work. I'll try looking into that

@omorandi
Copy link
Owner

Regarding compatibility with vanilla socket.io or any other third party JS lib, my plan would be to first make the API compatible with browser's websockets through a pure JS wrapper (see issue #15), and implement missing features (e.g. readyState, etc). Ideally, the final step would be to implement @yuchi's vision through Titaniumifier

@DouglasHennrich
Copy link

Any news about this threat?
I reaaaally need socket.io 1.0 on titanium =/

@WillDent
Copy link

If someone is interested we have a customer that would be willing to pay someone to update this module to work with socket.io 1.0 . If you know of anyone interested please let me know.

@dottodot
Copy link

Has there been any update in regards to socket.io 1.0?

@himanshusoni
Copy link

i have spent more than an hour searching for the socket io client for 1.x
Any updates ?

@DouglasHennrich
Copy link

@yuchi any news about 1.0.0 ?

@celsoperezcruz
Copy link

Check it out the gist of @ndob in : https://gist.github.com/ndob/4742514cd23eec7a81a3

applying change in last comment run in Android and iOS, I running my app with SocketIO 1.3.7 on server!

Enjoy!

@DouglasHennrich
Copy link

@celsoperezcruz 👍 👍 👍 Thanks man!

@xChat
Copy link

xChat commented Jan 27, 2016

@jvega2k
Copy link

jvega2k commented Feb 11, 2016

Hi, How are you... This is not working for me it sends:

[ERROR] : Script Error {
[ERROR] : column = 24;
[ERROR] : line = 2422;
[ERROR] : message = "Can't find variable: document";
[ERROR] : sourceURL = "";
[ERROR] : }

Can any one help me... Thanks

@DouglasHennrich
Copy link

wow 1.4.5 ? You're sure this work for both ? server and client side

@xChat
Copy link

xChat commented Feb 12, 2016

@DouglasHennrich Ye, using it with a v1.4.5 server on the node server side, both iOS and Android working fine for me at the moment.

It's for titanium / appcelerator projects though.

@DouglasHennrich
Copy link

greeat I will copy your socket file :D

Thanks

@jvega2k
Copy link

jvega2k commented Feb 12, 2016

@xChat i have try your code on titanium project and says Can't find variable: document. Can you send me your titanium implementation example so i can make it work. It looks like the error is because there is no web ambient on the titanium and can not find the document variable.

i am using tiws module and the socket io file you post.

Thanks for your help.

@xChat
Copy link

xChat commented Feb 12, 2016

@jvega2k Hi, you will have to use the websocket protocol with tiws module.

eg.
io('https://server.ip:1234', { transports: ['websocket'] });

The second parameter is a must.

Please keep me posted.

Thanks.

@DouglasHennrich
Copy link

socket = io.connect("http://localhost:5000", {
    'transports' : [ 'websocket' ],
    'reconnect' : true,
    'reconnect delay' : 100,
    'reconnect limit' : 5000,
    'multiplex': true,
    'max reconnection attempts' : Infinity,
    'query': 'user_id=' + Alloy.User.user_id
});

@DouglasHennrich
Copy link

how can I do to the user always get the same socket or eliminate the previous socket when he reconnect ?

@xChat
Copy link

xChat commented Feb 16, 2016

@DouglasHennrich

var socket,io;
...

function initSocket(_bool) {
   if (_bool) {
      if (socket) {
         socket.io.disconnect();
      }
      io = require('socket.io-client-1.4.5/socket.io');
      socket = io.connect(Alloy.Globals.socketUrl, {
         'reconnection' : true,
         'reconnectionDelay' : 500,
         transports : ["websocket"] // only works with websocket transport with TiWS module
      });
      // do something useful
      setupEvents();
   } else {
      socket.io.disconnect();
   }
}

This should be in a socket.io thread? haha

@ottopic
Copy link

ottopic commented Mar 29, 2016

Hi @xChat , I have same problem with this library, do you have an appcelerator implementation example to help me?

@jvega2k
Copy link

jvega2k commented Mar 29, 2016

@ottopic what had you try the examples above? There is any error on your try?

@HazemKhaled
Copy link

@Max87ZA
Copy link

Max87ZA commented Oct 31, 2017

Hi guys, please help... I want to use TiWS with extra headers authentication(token), but no luck so far, server returns error 400. Have you somebody implemented this? Thanks

@DouglasHennrich
Copy link

How are you doing this? I be able to implement JWT

@Max87ZA
Copy link

Max87ZA commented Oct 31, 2017

Hi Douglas,
here is example code:
`var socket;
var io = require('socket.io-client');
var socketConfig = {
'transports' : [ 'websocket'],
'reconnect' : true,
'reconnect delay' : 100,
'reconnect limit' : 5000,
'multiplex': true,
'max reconnection attempts' : Infinity,
"polling":{
"extraHeaders":
{
"Authorization": Ti.App.Properties.getString("authToken")
}
},

};
socket = io.connect(socketUrl, socketConfig);

Ti.API.log("socketConfig: "+JSON.stringify(socketConfig));

socket.on('connect',function () {
		Ti.API.log('socket connected!');
		socket.emit("startCommunication", function(e)
			{
				Ti.API.log("startCommunication: "+JSON.stringify(e));
			});
	});
socket.on("error", function()
{
	alert("socket error");
});`

@DouglasHennrich
Copy link

And you confirm that you're getting this extraHeaders on your server-side ?

@Max87ZA
Copy link

Max87ZA commented Oct 31, 2017

Server returns me error:
startCommunication: {"data":null,"error":{"errorMessage":"Token not recieved","errorCode":400}}

@DouglasHennrich
Copy link

try the jwt as I said maybe it works for your case

@Max87ZA
Copy link

Max87ZA commented Oct 31, 2017

Can you please help me ho to integrate jwt to appcelerator project?
Thanks

edit: I talked to my boss and he told me, that jwt won't work. Only option to authenticate is send token in header.

@DouglasHennrich
Copy link

Can't you create a event to be emitted passing this token? if it's invalid, disconnect the socket, otherwise continue with your code

@Max87ZA
Copy link

Max87ZA commented Nov 2, 2017

I can't pass it in emit(because of the rules), it has to be in headers...

@DouglasHennrich
Copy link

Did you tried to put extraHeaders outside pooling ?
according with this, that's possible under 2+.

Looking into socket.io lib, it has this extraHeaders option.. so it should work... which socket.io lib are you using?

@DouglasHennrich
Copy link

Can you use thorugh query ?

query : "token="+auth.getToken() 

@DouglasHennrich
Copy link

also, how you're getting and validating this header on your server? I guess I will move to this approach too

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