now
now copied to clipboard
Group enhancements
I've been noticing that I often want groups to work a little differently than they do.
While they are useful on the server for directing traffic to certain groups of users, I would like the client to know which groups they are in as well, and really have a separate now namespace for each.
- I'd like to be able to direct a message to a specific group that the client is in from the client
- I'd like to be able to indicate on the server that a function endpoint is only for a particular group, and have the client reflect that. This would allow me to associate a now group with a particular class instance on the client, which would simplify things
- If a user is in more than one group, then functions & variables set on the server for those groups that share the same name start to overwrite each other. I want to keep a sync'd object variable of who is in the room, but if the user is in more than one room, the variables overwrite each other on the client's now namespace.
To illustrate the last bullet:
var group1 = now.getGroup('group1');
var group2 = now.getGroup('group2');
group1.now.chat = function(){ };
group1.now.users = {};
//Oops, these group2 variables are going to overwrite group1's on the client's now variable
group2.now.chat = function(){ };
group2.now.users = {};
//It works ok to define chat on everyone and accept a groupId:
everyone.now.chat = function(groupId, message) {
var group = now.getGroup(groupId);
group.now.receiveChat(message);
};
But that doesn't work for variables, because I only want them to sync within the particular group. That requires me to do something like this to make sure they're unique:
group1.now.group_group1.users = {};
group2.now.group_group2.users = {};
//Now my client can look for the variable named group_groupId to find the user list for the group. Kind of funky but works.
``
I'm not sure if you have any interest in working on any of that, or how hard it would be given the existing implementation.