Book Image

Learning Node.js for Mobile Application Development

Book Image

Learning Node.js for Mobile Application Development

Overview of this book

Table of Contents (21 chapters)
Learning Node.js for Mobile Application Development
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
14
Creating an E-Commerce Application Using the Ionic Framework
Index

We need some room!


So far, the most advanced thing that we have done with WebSockets in our apps has simply been sending data back and forth across a single WebSocket interface. We paid very little attention to partitioning and basically just let it all go on as a free-for-all app. However, in real life, we will frequently find ourselves in situations where we want to partition WebSocket connections and only let certain users have access to a subset of partitions.

To see how this can work, consider the case of a group chat. Here, rather than having just a single solitary chat interface, users instead have access to a multitude of them; each hosts its own members and conversation. To implement this, we can extend our existing chat server to simply start new node instances for the chat rooms that we want to open, with each of them having its own port, as follows:

// [snip]

// Connect the websocket handler to our server
var websocket = require('socket.io')(server);
// Create a handler for incoming...