From e7948357346de8166166a039794233ce272b29a2 Mon Sep 17 00:00:00 2001 From: Gabriel Jaldon Date: Fri, 16 Sep 2016 21:02:18 +0800 Subject: [PATCH] Join admin:active_users topic on mount of Chat. The admin:active_users topic is used to track the presence of users currently connected to our app. We need to join the topic every time the Chat component is mounted so the admin can be made aware that a user is online. --- src/PhoenixChat.jsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/PhoenixChat.jsx b/src/PhoenixChat.jsx index f1e46fe..a81ef89 100644 --- a/src/PhoenixChat.jsx +++ b/src/PhoenixChat.jsx @@ -116,6 +116,7 @@ export class PhoenixChat extends React.Component { componentWillUnmount() { this.channel.leave() + this.adminChannel.leave() } configureChannels(room) { @@ -135,6 +136,12 @@ export class PhoenixChat extends React.Component { messages: this.state.messages.concat([payload]) }) }) + + this.adminChannel = this.socket.channel(`admin:active_users`) + this.adminChannel.join() + .receive("ok", ({ id }) => { + console.log(`${id} succesfully joined the active_users topic.`) + }) } handleMessageSubmit(e) {