1

Below the event binding on socket.io worked correctly,

io = require('socket.io')()

io.on 'connection', (socket) ->
    console.log socket.id

io.listen 3000

Then tried to convert socket.io event to Bacon EventStream,

Bacon = require('baconjs').Bacon
io = require('socket.io')()

connections = Bacon.fromEventTarget io, 'connection'

connections.onValue (socket) ->
    console.log socket.id

io.listen 3000

Why did it fail below?

TypeError: Object connection has no method 'on'
sof
  • 9,113
  • 16
  • 57
  • 83

2 Answers2

4

In version 0.7.46 there's an improved version of Bacon.fromEventTarget (or just Bacon.fromEvent btw), that should find the appropriate bind/unbind pair for you.

raimohanska
  • 3,265
  • 17
  • 28
2

fromEventTarget blindly tries a couple different callback-taking methods, including bind and on. In socket.io:Server's case, both methods exist and fromEventTarget is using the wrong one.

I would use fromCallback instead:

connections = Bacon.fromCallback(io, 'on', 'connection')

This seems a bit shaky so I created a Github issue.

chreekat
  • 974
  • 7
  • 16