namibia
90d6a07e7e4539815d3e24e48c81d37282fb4e71
namibia / public / ape-source / Pipe / PipeMulti.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
APE.PipeMulti = new Class({ Extends: APE.Pipe, initialize: function(core, options) { this.parent(core, options); this.type = 'multi'; this.name = options.pipe.properties.name; //Test if pipe have users before sending event //because this.users need to be defined if (options.users) { this.users = new $H; var users = options.users; } this.ape.fireEvent('multiPipeCreate', [this, options]); if (options.users) { var l = users.length; for (var i=0; i < l; i++) { this.addUser(users[i].pubid, users[i]); } } this.onRaw('left', this.rawLeft); this.onRaw('join', this.rawJoin); }, rawJoin: function(raw, pipe) { this.addUser(raw.data.user.pubid, raw.data.user); }, rawLeft: function(raw, pipe) { if (pipe.name.charAt(0) != '*') this.delUser(raw.data.user.pubid); if (raw.data.user.pubid == this.ape.user.pubid) this.ape.delPipe(pipe.pipe.pubid); }, left: function() { this.ape.left(this.pipe.pubid); }, addUser: function(pubid, updatedUser) { var user; if (!this.ape.users.has(pubid)) { user = updatedUser; user.pipes = new $H; this.ape.users.set(pubid, updatedUser); } else { user = this.ape.users.get(pubid); } user.pipes.set(this.pipe.pubid, this); var u = {'pipes':user.pipes ,'casttype': user.casttype, 'pubid': user.pubid, 'properties': updatedUser.properties}; this.users.set(pubid, u); this.fireGlobalEvent('userJoin', [u, this]); return u; }, delUser: function(pubid) { var u = this.users.get(pubid); this.users.erase(pubid); u.pipes.erase(this.pipe.pubid) if (u.pipes.getLength() == 0) { this.ape.users.erase(u.pubid); } this.fireGlobalEvent('userLeft', [u, this]); return u; }, getUser: function(pubid) { return this.users.get(pubid); }, getUserPipe: function(user) { if (typeof user == 'string') user = this.users.get(users.pubid); return this.ape.newPipe('uni', {'pipe':user}); } }); |
Commits for namibia/public/ape-source/Pipe/PipeMulti.js
Revision | Author | Commited | Message |
---|---|---|---|
df0489 ... | Mark | Fri 14 Oct, 2016 10:01:00 +0000 | initial commit |