Hooks on socket.io

22 views
Skip to first unread message

B

unread,
Jul 8, 2014, 9:37:21 PM7/8/14
to cozy-...@googlegroups.com
Hi,

For an application I am making, I need to reuse the socket.io instance.
After some digging, I found out it is spawned in cozy-home
(/server/initializers/realtime.coffee). TL;DR: how could we generally
hook up to this socket.io instance?

More in depth:
- my use case needs the compound.io variable from realtime.coffee.
- even if an app spawns its own instance of socket.io, apparently
browsers can't handle several of them (well, at least Firefox can't),
and only the first one, top level socket.io is reached.
- of course, I could just have my own clone of cozy-home and reuse it,
rebasing modifications atop of mine, but that's something I'd like to avoid.

Could we imagine a system of optional plugins for the realtime adapter?
Or maybe make an americano plugin that adds the hook (I suppose it would
need to make cozy-realtime-adapter an americano plugin itself)?

In this case, I need the socket.io instance for setting up an easyrtc
server [1].

Any other ideas or feedback will be appreciated :)
Cheers,
Ben

[1] https://github.com/priologic/easyrtc

Romain Foucault

unread,
Jul 9, 2014, 3:14:02 AM7/9/14
to cozy-...@googlegroups.com
Hi

The compound.io variable is actually bound to whatever you pass to RealtimeAdapter. For instance, 

RealtimeAdapter = require 'cozy-realtime-adapter' app.server = server
realtime = RealtimeAdapter app, ....
app.io.emit ....

We use 1 websocket / app and they seem to work in Firefox


Images intégrées 1


If you don't need the cozy-realtime-adapter, and just want a basic socket.io server, remember to set the resource options on the client : 


Hope this helps.
Cheers, 
Romain

B

unread,
Jul 9, 2014, 6:36:07 PM7/9/14
to cozy-...@googlegroups.com
Hi Romain,

The lib I am using, easyrtc, wrongly assumes that the socket.io instance to which we want to connect is located at the top-level path. This library doesn't provide any way to set the resource option, so I made a pull request to the project [1].

Thanks for the hint to the resource option!

Cheers,
Benjamin

[1] https://github.com/priologic/easyrtc/pull/74
Reply all
Reply to author
Forward
0 new messages