Created
January 12, 2012 13:30
-
-
Save cballou/1600529 to your computer and use it in GitHub Desktop.
Get _room and _manager from TT.FM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _room; | |
var _manager; | |
/** | |
* Function to retrieve turntable objects. | |
*/ | |
function getTurntableObjects() { | |
// reset room | |
_room = null; | |
var dfd = $.Deferred(); | |
var resolveWhenReady = function() { | |
if (window.location.pathname !== '/lobby') { | |
// find room | |
for (var o in _tt) { | |
if (_tt[o] !== null && _tt[o].creatorId) { | |
_room = _tt[o]; | |
break; | |
} | |
} | |
// find room manager | |
if (_room) { | |
for (var o in _room) { | |
if (_room[o] !== null && _room[o].myuserid) { | |
_manager = _room[o]; | |
} | |
} | |
dfd.resolve(); | |
} else { | |
setTimeout(function() { | |
resolveWhenReady(); | |
}, 250); | |
} | |
} else { | |
setTimeout(function() { | |
resolveWhenReady(); | |
}, 250); | |
} | |
}; | |
resolveWhenReady(); | |
return dfd.promise(); | |
} | |
// ensure we get a valid user object before handling auto-responder | |
$.when(getTurntableObjects()).then(function() { | |
// put any code depending on _manager and _room here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment