CB-321: Media API: 'mediaSuccess' callback param to new Media() is called soon after new obj created

This commit is contained in:
macdonst 2012-03-30 15:29:26 -04:00
parent d2b329636f
commit 700ae50e9b

View File

@ -2901,7 +2901,7 @@ Media.get = function(id) {
* Start or resume playing audio file. * Start or resume playing audio file.
*/ */
Media.prototype.play = function(options) { Media.prototype.play = function(options) {
exec(this.successCallback, this.errorCallback, "Media", "startPlayingAudio", [this.id, this.src, options]); exec(null, null, "Media", "startPlayingAudio", [this.id, this.src, options]);
}; };
/** /**
@ -3512,8 +3512,9 @@ function Device() {
this.cordova = null; this.cordova = null;
var me = this; var me = this;
this.getInfo(
function(info) { channel.onCordovaReady.subscribeOnce(function() {
me.getInfo(function(info) {
me.available = true; me.available = true;
me.platform = info.platform; me.platform = info.platform;
me.version = info.version; me.version = info.version;
@ -3521,11 +3522,11 @@ function Device() {
me.uuid = info.uuid; me.uuid = info.uuid;
me.cordova = info.cordova; me.cordova = info.cordova;
channel.onCordovaInfoReady.fire(); channel.onCordovaInfoReady.fire();
}, },function(e) {
function(e) {
me.available = false; me.available = false;
utils.alert("[ERROR] Error initializing Cordova: " + e); utils.alert("[ERROR] Error initializing Cordova: " + e);
}); });
});
} }
/** /**
@ -4498,46 +4499,47 @@ var exec = require('cordova/exec'),
channel = require('cordova/channel'); channel = require('cordova/channel');
var NetworkConnection = function () { var NetworkConnection = function () {
this.type = null; this.type = null;
this._firstRun = true; this._firstRun = true;
this._timer = null; this._timer = null;
this.timeout = 500; this.timeout = 500;
var me = this; var me = this;
this.getInfo( channel.onCordovaReady.subscribeOnce(function() {
function (info) { me.getInfo(function (info) {
me.type = info; me.type = info;
if (info === "none") { if (info === "none") {
// set a timer if still offline at the end of timer send the offline event // set a timer if still offline at the end of timer send the offline event
me._timer = setTimeout(function(){ me._timer = setTimeout(function(){
cordova.fireDocumentEvent("offline"); cordova.fireDocumentEvent("offline");
me._timer = null; me._timer = null;
}, me.timeout); }, me.timeout);
} else { } else {
// If there is a current offline event pending clear it // If there is a current offline event pending clear it
if (me._timer !== null) { if (me._timer !== null) {
clearTimeout(me._timer); clearTimeout(me._timer);
me._timer = null; me._timer = null;
}
cordova.fireDocumentEvent("online");
} }
cordova.fireDocumentEvent("online");
}
// should only fire this once // should only fire this once
if (me._firstRun) { if (me._firstRun) {
me._firstRun = false; me._firstRun = false;
channel.onCordovaConnectionReady.fire(); channel.onCordovaConnectionReady.fire();
} }
}, },
function (e) { function (e) {
// If we can't get the network info we should still tell Cordova // If we can't get the network info we should still tell Cordova
// to fire the deviceready event. // to fire the deviceready event.
if (me._firstRun) { if (me._firstRun) {
me._firstRun = false; me._firstRun = false;
channel.onCordovaConnectionReady.fire(); channel.onCordovaConnectionReady.fire();
} }
console.log("Error initializing Network Connection: " + e); console.log("Error initializing Network Connection: " + e);
}); });
});
}; };
/** /**