Phoenix channels

I have completely fallen in love with phoenix channels and I am trying to learn as much as I can about them .

I am wondering why I cant pass a empty map as a parameter in the broadcast/3 , broadcast_from/3 and push/3 from the channel module.

What I am trying to achieve is sending a message to the client to run a specific function on the clients on the channel.
I just want the function to run on the client not to pass any data through the channel.

also is this a good use of channels ? or am I traversing the Atlantic in a bucket ?

1 Like

I was brain farting … again :slight_smile:

blank map goes through however the js side isn’t responding. I`ll dig through it a bit more

1 Like

I`m setting up a real time leaderboard for some activities for my kids this Christmas and I am refreshing the leaderbord on the :create , :update, and :edit functions in my controller

in my mind it was the quickest solution to send a call to the js location.reload(); function.

but I get the feeling I am missing something as I see from other sources that they prefer to add the data in the payload is there any pro/con I should know about. I am a complete newbie on both js and html.

1 Like

I can’t actually help, because I have little to no knowledge of channels, but I will be following along with this thread!
Keep up the good work.

I think you can broadcast from inside of your controllers. Something like YourAppName.Endpoint.broadcast(topic, event, msg) (docs) should do the trick. msg would be the new data (or the difference), which you can append (or do whatever you want) to the leaderboard with some javascript, instead of using location.reload(). With location.reload() you might end up requesting some unnecessary information (like all of html) every time something in the leaderboard changes.

Here’s a similar question on stackoverflow.

1 Like