[common] avoid overwriting MediaError if it already exists.

Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/490465b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/490465b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/490465b6

Branch: refs/heads/master
Commit: 490465b62bfa40921cd7bfc3efb6ca6347547d19
Parents: 2aa46aa
Author: Jesse MacFadyen <purplecabb...@gmail.com>
Authored: Wed Sep 5 12:00:00 2012 -0700
Committer: Jesse MacFadyen <purplecabb...@gmail.com>
Committed: Wed Sep 5 12:00:00 2012 -0700

----------------------------------------------------------------------
 lib/common/plugin/MediaError.js |   37 +++++++++++++++++++++++----------
 1 files changed, 26 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/490465b6/lib/common/plugin/MediaError.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/MediaError.js b/lib/common/plugin/MediaError.js
index e55f33e..bdc4e92 100644
--- a/lib/common/plugin/MediaError.js
+++ b/lib/common/plugin/MediaError.js
@@ -1,16 +1,31 @@
 /**
  * This class contains information about any Media errors.
- * @constructor
+*/
+/*
+ According to :: http://dev.w3.org/html5/spec-author-view/video.html#mediaerror
+ We should never be creating these objects, we should just implement the 
interface
+ which has 1 property for an instance, 'code'
+
+ instead of doing :
+    errorCallbackFunction( new MediaError(3,'msg') );
+we should simply use a literal :
+    errorCallbackFunction( {'code':3} );
  */
-var MediaError = function(code, msg) {
-    this.code = (code !== undefined ? code : null);
-    this.message = msg || "";
-};
 
-MediaError.MEDIA_ERR_NONE_ACTIVE    = 0;
-MediaError.MEDIA_ERR_ABORTED        = 1;
-MediaError.MEDIA_ERR_NETWORK        = 2;
-MediaError.MEDIA_ERR_DECODE         = 3;
-MediaError.MEDIA_ERR_NONE_SUPPORTED = 4;
+if(!MediaError) {
+    MediaError = function(code, msg) {
+        this.code = code || null;
+        this.message = msg || ""; // message is NON-standard! do not use!
+    };
+}
+
+MediaError.MEDIA_ERR_NONE_ACTIVE    = MediaError.MEDIA_ERR_NONE_ACTIVE    || 0;
+MediaError.MEDIA_ERR_ABORTED        = MediaError.MEDIA_ERR_ABORTED        || 1;
+MediaError.MEDIA_ERR_NETWORK        = MediaError.MEDIA_ERR_NETWORK        || 2;
+MediaError.MEDIA_ERR_DECODE         = MediaError.MEDIA_ERR_DECODE         || 3;
+MediaError.MEDIA_ERR_NONE_SUPPORTED = MediaError.MEDIA_ERR_NONE_SUPPORTED || 
4; 
+// TODO: MediaError.MEDIA_ERR_NONE_SUPPORTED is legacy, the W3 spec now 
defines it as below. 
+// as defined by 
http://dev.w3.org/html5/spec-author-view/video.html#error-codes
+MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = 
MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED || 4;
 
-module.exports = MediaError;
\ No newline at end of file
+module.exports = MediaError;

Reply via email to