Instantly share code, notes, and snippets.

@iamfunsho /block8.js Secret
Created Oct 24, 2017

Embed
What would you like to do?
client().then(
res => {
// App routes
app.get("/", routes.home);
app.get("/chat/:username", routes.chatRoom);
app.get("/messages", routes.messages);
app.get("/users", routes.users);
app.post("/user", routes.createUser);
app.delete("/user", routes.deleteUser);
app.post("/message", routes.createMessage);
//Start the server
const server = app.listen(PORT, () => {
console.log("Server Started");
});
const io = socket.listen(server);
// //listen and emit messages and user events (leave or join) using socket.io
io.on("connection", socket => {
// subscribe to Pub/Sub channels
res.subscribe("chatMessages");
res.subscribe("activeUsers");
res.on("message", (channel, message) => {
if (channel === "chatMessages") {
socket.emit("message", JSON.parse(message));
} else {
socket.emit("users", JSON.parse(message));
}
});
});
},
err => {
console.log("Redis connection failed: ", err);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment