mardi 20 octobre 2015

Phoenix/EmberJS Websocket access with actions (noob)

I have a basic Ember frontend app which connects to a Phoenix backend via a websocket in an initializer. Next I want to be able to use 'chan.push("new_msg", {body: "test"}) to send a message to the Phoenix channel.

Obviously, I can't do this from the initializer itself, but that is the only place where 'chan' is defined and I don't know how to access it from another location.

I want this to happen on a action from an {{input action="sendMessage()"}} so I have tried several things such as putting the 'sendMessage()' function in the initializer and calling it in a component action etc... But any time I try to access the initializer from another file (or vice versa) I get an error saying the function is not defined. I know initializers should not be used this way of course, I just don't know where else to put the code such that I can access the websocket connection I have defined.

The majority of the code related to this problem matches what you will see in this guide: http://ift.tt/1Lnda1f . Unfortunately this doesn't cover how to make use of this websocket connection from the frontend for noobs.

Thanks again.




Aucun commentaire:

Enregistrer un commentaire