OpenTok-Angular
OpenTok-Angular copied to clipboard
allow async load?
if this line is removed
if (!window.OT) throw new Error('You must include the OT library before the OT_Angular library');
and this is removed
.factory('OT', function() {
return OT;
})
and OT
injection changes to window.OT
and OT.$.eventing(OTSession);
changes to
var _interval = $interval(function(){
if (window.TB) {
$interval.cancel(_interval);
OT.$.eventing(OTSession);
}
}, 500);
then you can have:
service.addScript = function(url, defer) {
if (window.TB) {
defer.resolve()
return
}
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.onload = function(){
defer.resolve();
};
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
}
and in state definition:
resolve : {
TBloaded: function(){
service.addScript("...tokboxjslink...", defer)
return defer.promise
}
}
so then you can load tokbox asynchronously (and you can also register window.onload event to download tokbox after everything else has loaded). I think it makes a big difference because its a big library.
I could make a pull request but i probably won't find time to unit-test it, but if someone feels like doing it here's the coded needed.