Raygordonbooks chat room
And since we won’t be using the shout function is in charge of broadcasting any chat events to everyone that’s joined our channel.Notice that this is set to pattern match on “shout” - we’ll need to remember to use this when we push events out from the client . Water Cooler Channel do use Chat Web, :channel def join("water_cooler:lobby", _payload, socket) do end #It is also common to receive messages from the client and #broadcast to everyone in the current topic (water_cooler:lobby). I can come in whenever and know that there are plenty of people to talk to who share my interests thanks to the many different rooms. Teen chat is an amazing free chat where you can meet some awesome friends from all over the place.If you want to chat with me I'm usually in here under katie n megan.to chat with you soon!We’ll fix that by saving our chats to the database.Let’s have Phoenix do the heavy lifting for us here and use the context generator to build out the modules and database migration that we’ll need.We’ll go to the command line - and we’ll stop our server. Then if we do a quick check of the database - we see our messages are there.And let’s our new context ‘Chats’ our ecto schema module will be ‘Message’ And our table will be messages with a name column that’s a string and body column that’s a text. then let’s open the chats context And it’s been populated with some functions to save and get our messages. And if we go back to our chat and refresh the page - we see our existing messages are loaded.
We’ll open our browser and in the console - we see our success message is printed.
It’s a nice guide for where we could put authorization logic.
In our example we won’t do any authorization, so let’s remove the logic and have it always return the OK tuple with our socket.
Now that we’re joining successfully let’s create a chat window and form we’ll use to post messages with. We’ll remove the Then let’s open our browser and see what it looks like. Now let’s add some Java Script to get our chat working, so that when we post a message it’s displayed.
We’ll create a new file in our that will take our socket.