Loopcast / beta

1 stars 0 forks source link

Update subscription logic #318

Closed hems closed 9 years ago

hems commented 9 years ago

Due to some problems with implementing the feature "people in this room" using pusher, we end up rolling our own socket.io server @ heroku.

Now the subscription way changes a little bit, which will simplify both sides of the game.

There will be only 2 kind of channels, user_id and room_id, all the information a user can subscribed will go through that channel and all the information regarding a room will go through the room channel.

Following the new implementation, when a user logs in, we would do something more or less like this:

# app/sockets/user

socket = require "app/controllers/socket"

socket.subscribe user_id # or room_id
socket.on user_id, ( data ) =>
   console.log "type of message: #{data.type}"

  if data.type is "liked"
    @on_user_followed( data )
    return

  if data.type is "upload:finished"
    @on_upload_finished data
    return

  if data.type is "upload:error"
    @on_upload_error data
    return

# unsubscribe will automatically stop listening and remove all the listeners for this channel
sockets.unsubscribe user_id # or room_id
hems commented 9 years ago

@stefanoortisi i updated this doc, which is kinda of the "official" reference for the socket messages..

https://github.com/Loopcast/beta/blob/development/docs/Sockets

Let me know if something isn't clear.

In order to test the new API i implemented chat messages, and the "listener" method you created and it seems to work fine.

Now i think you still need to subscribe to the user channel and do all this following jazz, also the upload:finish and upload:error message will change when i close #317

stefanoortisi commented 9 years ago

I've added the like notification for the follow action and it works fine. nice stuff!

stefanoortisi commented 9 years ago

@thomas1602 shall we have a notification for the unfollow action? I think it's a bit rude..

thomas1602 commented 9 years ago

Yes I agree, let's not have that lol

hems commented 9 years ago

there was a bug on the chat thing, i just fixed. hopefully will be all fine, it seems to be all fine

hems commented 9 years ago

@stefanoortisi i think everything is good?

did you implement this notifications for user following, etcs, as the example i wrote in this issue?

stefanoortisi commented 9 years ago

@hems yep! this issue can be closed now.