Create multiple channels using mdm
Create multiple channels using mux-demux
A channel is a function that pipes up the incoming stream to a persistant stream based on the incoming stream name.
This means that when multiple clients connect to the channel then each message to the channel is relayed to all of them
var MultiChannel = require"multi-channel-mdm"MuxDemux = require"mux-demux-net"channel = MultiChannelMuxDemuxchannel 8642
Spin up multiple clients to note that each has been piped up to the back end channel. This basically functions as broadcasting to all open connections to the channel
var MuxDemux = require"mux-demux-net"mdm = MuxDemux8642var room1 = mdmcreateStream"room1"room2 = mdmcreateStream"room2"room1on"data" console.logbindconsole "room1"room2on"data" console.logbindconsole "room2"room1write"hello"room2write"world"
multi channel was created to interact nicely with the stream router.
Notice how you can also pass a persistance store directly to multi channel so you have control over how the streamName to stream mapping occurs
var MultiChannel = require"../.."MuxDemux = require"mux-demux-net"StreamRouter = require"stream-router"StreamStore = require"stream-store"var router = StreamRouterStreamStorechannel = MultiChannelMuxDemuxrouter 8642routeraddRoute"/channel/:streamName" channel
If you use a store that has a database you can distribute your channels!
var MultiChannel = require"../.."MuxDemux = require"mux-demux-net"RedisStore = require"redis-stream-store"var redisStore = RedisStore6379 "localhost" "redis-demo"channel = MultiChannelredisStoreMuxDemuxchannel processargv2 || 8642
npm install multi-channel-mdm