1 APE.PipeMulti = new Class({
5 initialize: function(core, options) {
6 this.parent(core, options);
9 this.name = options.pipe.properties.name;
11 //Test if pipe have users before sending event
12 //because this.users need to be defined
15 var users = options.users;
18 this.ape.fireEvent('multiPipeCreate', [this, options]);
22 for (var i=0; i < l; i++) {
23 this.addUser(users[i].pubid, users[i]);
26 this.onRaw('left', this.rawLeft);
27 this.onRaw('join', this.rawJoin);
30 rawJoin: function(raw, pipe) {
31 this.addUser(raw.data.user.pubid, raw.data.user);
34 rawLeft: function(raw, pipe) {
35 if (pipe.name.charAt(0) != '*') this.delUser(raw.data.user.pubid);
36 if (raw.data.user.pubid == this.ape.user.pubid) this.ape.delPipe(pipe.pipe.pubid);
40 this.ape.left(this.pipe.pubid);
43 addUser: function(pubid, updatedUser) {
45 if (!this.ape.users.has(pubid)) {
48 this.ape.users.set(pubid, updatedUser);
50 user = this.ape.users.get(pubid);
52 user.pipes.set(this.pipe.pubid, this);
53 var u = {'pipes':user.pipes ,'casttype': user.casttype, 'pubid': user.pubid, 'properties': updatedUser.properties};
54 this.users.set(pubid, u);
55 this.fireGlobalEvent('userJoin', [u, this]);
59 delUser: function(pubid) {
60 var u = this.users.get(pubid);
61 this.users.erase(pubid);
62 u.pipes.erase(this.pipe.pubid)
63 if (u.pipes.getLength() == 0) {
64 this.ape.users.erase(u.pubid);
66 this.fireGlobalEvent('userLeft', [u, this]);
70 getUser: function(pubid) {
71 return this.users.get(pubid);
74 getUserPipe: function(user) {
75 if (typeof user == 'string') user = this.users.get(users.pubid);
76 return this.ape.newPipe('uni', {'pipe':user});