nolancaster / angular2-actioncable

Integrate ActionCable with Angular2+
25 stars 16 forks source link

No way to send / broadcast to a particular event #2

Closed jaybloke closed 6 years ago

jaybloke commented 6 years ago

I'm trying to use ActionCable to send events from the client side to the server, but learned that the channel.send() method has no provision to handle this.

e.g. channel.send('appear', { user_id: 12345 }) - this would call the 'appear' method in my channel.

Example of this can be found here: http://guides.rubyonrails.org/action_cable_overview.html#example-1-user-appearances

Is there another way I can achieve the desired result with your lib? I don't really want to revert back to the standard ActionCable library if I can help it.

nolancaster commented 6 years ago

There isn't currently anything built specifically for this, but I saw that example a couple weeks ago and I've been thinking on how to implement something like that.

In the meantime I think you might actually be able to use channel.send() if you give you data object an 'action' property corresponding to the remote method. Can you try something like this and let me know if it works?

channel.send({action: 'appear', user_id: 12345 })

jaybloke commented 6 years ago

Thanks @nolancaster - your solution works. Perhaps the docs should mention this somewhere as it's not immediately obvious how to handle custom actions.

nolancaster commented 6 years ago

@jaybloke I just published version 1.2.0 that adds a Channel.perform() method that should work like the example in the Rails docs. It should work, but my project doesn't actually use this feature so if you have any problems let me know.