arunoda / meteor-streams

Realtime messaging for Meteor
http://arunoda.github.io/meteor-streams
MIT License
287 stars 97 forks source link

Trouble Adding Rooms #15

Closed xTACTICSx closed 10 years ago

xTACTICSx commented 10 years ago

Hey everyone,

I was wondering if this method would be even possible using streams but is it possible to add rooms? I have tried several different ways but I am having trouble getting it to work. Do I need to add clusters? Any help would be greatly appreciated!

arunoda commented 10 years ago

Try this. you don't need cluster unless you've a multi server setup.

Chat = new Meteor.Stream('chat');

if(Meteor.isClient) {
  Chat.emit('join', 'meteor-talk-room');
  sendMessage = function(message) {
    Chat.emit('message', message, 'meteor-talk-room');
  }
}

if(Meteor.isServer) {
  var subscriptionGroup = {};
  Chat.on('join', function(group) {
    var subscriptionId = this.subscriptionId;
    subscriptionGroup[subscriptionId] = group;

    this.onDisconnect = function() {
      delete subscriptionGroup[subscriptionId];
    };
  });

  Chat.permission.write(function() {
    true;
  });

  Chat.permission.read(function(event, message, group) {
    var myGroup = subscriptionGroup[this.subscriptionId];
    return event == 'message' && myGroup == group;
  }, false);
}
xTACTICSx commented 10 years ago

Thank you so much! Works great(: I was able to get it working

smmoosavi commented 9 years ago

Can you provide simple API for rooms/channel? like as socket-io.