You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by da...@apache.org on 2016/03/02 09:54:10 UTC

cordova-plugin-media git commit: CB-10636 Add JSHint for plugins

Repository: cordova-plugin-media
Updated Branches:
  refs/heads/master 50d9440d8 -> 3fe3a3009


CB-10636 Add JSHint for plugins


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/commit/3fe3a300
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/3fe3a300
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/3fe3a300

Branch: refs/heads/master
Commit: 3fe3a300969720919499d9ad0882eaec00f7ba20
Parents: 50d9440
Author: daserge <v-...@microsoft.com>
Authored: Mon Feb 29 18:18:57 2016 +0300
Committer: daserge <v-...@microsoft.com>
Committed: Wed Mar 2 11:01:20 2016 +0300

----------------------------------------------------------------------
 .gitignore                |  2 +-
 .jshintrc                 | 17 ++++++++
 .travis.yml               |  4 ++
 README.md                 |  2 +
 package.json              |  9 ++++-
 src/blackberry10/index.js |  2 +
 src/tizen/MediaProxy.js   |  5 ++-
 src/windows/MediaProxy.js | 18 +++++----
 tests/tests.js            | 20 +++++-----
 www/Media.js              | 27 ++++++++-----
 www/browser/Media.js      | 90 +++++++++++++++++++++++-------------------
 11 files changed, 125 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 52b558e..6964ea0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,7 @@ Thumbs.db
 *.swp
 *.user
 
-
+node_modules
 
 
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/.jshintrc
----------------------------------------------------------------------
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..df32482
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,17 @@
+{
+    "browser": true
+  , "devel": true
+  , "bitwise": true
+  , "undef": true
+  , "trailing": true
+  , "quotmark": false
+  , "indent": 4
+  , "unused": "vars"
+  , "latedef": "nofunc"
+  , "globals": {
+        "module": false,
+        "exports": false,
+        "require": false,
+        "cordova": true
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..b9af4c5
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+sudo: false
+node_js:
+  - "4.2"

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index e5bb4a4..ca012ff 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,8 @@
 #         under the License.
 -->
 
+[![Build Status](https://travis-ci.org/apache/cordova-plugin-media.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-media)
+
 # cordova-plugin-media
 
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 5021bc5..f8d7a47 100644
--- a/package.json
+++ b/package.json
@@ -36,9 +36,16 @@
     "cordova-windows",
     "cordova-tizen"
   ],
+  "scripts": {
+    "test": "npm run jshint",
+    "jshint": "jshint www && jshint src && jshint tests"
+  },
   "peerDependencies": {
     "cordova-plugin-file": "^4.0.0"
   },
   "author": "Apache Software Foundation",
-  "license": "Apache-2.0"
+  "license": "Apache-2.0",
+  "devDependencies": {
+    "jshint": "^2.6.0"
+  }
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js
index 1b9b786..e48fafa 100644
--- a/src/blackberry10/index.js
+++ b/src/blackberry10/index.js
@@ -19,6 +19,8 @@
  *
 */
 
+/* global qnx, PluginResult */
+
 var audioObjects = {},
     mediaErrorsHandled = false;
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/src/tizen/MediaProxy.js
----------------------------------------------------------------------
diff --git a/src/tizen/MediaProxy.js b/src/tizen/MediaProxy.js
index 96665f0..15ab7f0 100644
--- a/src/tizen/MediaProxy.js
+++ b/src/tizen/MediaProxy.js
@@ -19,8 +19,9 @@
  *
 */
 
-var cordova = require('cordova'),
-    Media = require('cordova-plugin-media.Media');
+/* global webkitURL */
+
+var Media = require('cordova-plugin-media.Media');
 
 var MediaError = require('cordova-plugin-media.MediaError'),
     audioObjects = {};

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/src/windows/MediaProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/MediaProxy.js b/src/windows/MediaProxy.js
index fddec2c..d7fe294 100644
--- a/src/windows/MediaProxy.js
+++ b/src/windows/MediaProxy.js
@@ -34,6 +34,11 @@ var PARAMETER_IS_INCORRECT = -2147024809;
 var SUPPORTED_EXTENSIONS = ['.mp3', '.wma', '.wav', '.cda', '.adx', '.wm', '.m3u', '.wmx', '.m4a'];
 var SUPPORTED_PREFIXES = ['http', 'https', 'rstp'];
 
+var fsTypes = {
+    PERSISTENT: 'PERSISTENT',
+    TEMPORARY: 'TEMPORARY'
+};
+
 module.exports = {
     mediaCaptureMrg:null,
 
@@ -52,7 +57,9 @@ module.exports = {
         var extension = srcUri.extension;
         if (thisM.node === null) {
             if (SUPPORTED_EXTENSIONS.indexOf(extension) === -1 && SUPPORTED_PREFIXES.indexOf(prefix) === -1) {
-                lose && lose({ code: MediaError.MEDIA_ERR_ABORTED });
+                if (lose) {
+                    lose({ code: MediaError.MEDIA_ERR_ABORTED });
+                }
                 return false; // unable to create
             }
 
@@ -116,7 +123,9 @@ module.exports = {
         try {
             thisM.node.play();
         } catch (err) {
-            lose && lose({code:MediaError.MEDIA_ERR_ABORTED});
+            if (lose) {
+                lose({code:MediaError.MEDIA_ERR_ABORTED});
+            }
         }
     },
 
@@ -371,11 +380,6 @@ function processUri(src) {
     return uri;
 }
 
-var fsTypes = {
-    PERSISTENT: 'PERSISTENT',
-    TEMPORARY: 'TEMPORARY'
-};
-
 /**
  * Extracts path, filename and filesystem type from Uri
  * @param  {Object} uri Windows.Foundation.Uri

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 0497293..246e40b 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -18,6 +18,10 @@
  * under the License.
  *
  */
+
+/* jshint jasmine: true */
+/* global Windows, Media, MediaError, LocalFileSystem, halfSpeedBtn */
+
 // increased timeout for actual playback to give device chance to download and play mp3 file
 // some emulators can be REALLY slow at this, so two minutes
 var ACTUAL_PLAYBACK_TEST_TIMEOUT = 2 * 60 * 1000;
@@ -225,7 +229,7 @@ exports.defineAutoTests = function () {
                             }, 1000);
                         }
                     };
-                media = new Media(mediaFile, successCallback, failed.bind(self, done, 'media1 = new Media - Error creating Media object. Media file: ' + mediaFile, context), statusChange);
+                media = new Media(mediaFile, successCallback, failed.bind(null, done, 'media1 = new Media - Error creating Media object. Media file: ' + mediaFile, context), statusChange);
                 media.play();
             }, ACTUAL_PLAYBACK_TEST_TIMEOUT);
 
@@ -254,7 +258,7 @@ exports.defineAutoTests = function () {
                             }, 1000);
                         }
                     };
-                media = new Media(mediaFile, successCallback, failed.bind(self, done, 'media1 = new Media - Error creating Media object. Media file: ' + mediaFile, context), statusChange);
+                media = new Media(mediaFile, successCallback, failed.bind(null, done, 'media1 = new Media - Error creating Media object. Media file: ' + mediaFile, context), statusChange);
                 media.play();
             }, ACTUAL_PLAYBACK_TEST_TIMEOUT);
 
@@ -284,7 +288,7 @@ exports.defineAutoTests = function () {
                             expect(position).toBeCloseTo(20, 0);
                             context.done = true;
                             done();
-                        }, failed.bind(null, done, 'media1.getCurrentPosition - Error getting media current position', context))
+                        }, failed.bind(null, done, 'media1.getCurrentPosition - Error getting media current position', context));
                     }
 
                     if (statusCode == Media.MEDIA_PAUSED) {
@@ -292,7 +296,7 @@ exports.defineAutoTests = function () {
                         media.play();
                     }
                 };
-                media = new Media(mediaFile, successCallback, failed.bind(self, done, 'media1 = new Media - Error creating Media object. Media file: ' + mediaFile, context), statusChange);
+                media = new Media(mediaFile, successCallback, failed.bind(null, done, 'media1 = new Media - Error creating Media object. Media file: ' + mediaFile, context), statusChange);
                 
                 // CB-10535: Play after a few secs, to give allow enough buffering of media file before seeking
                 setTimeout(function() {
@@ -325,7 +329,7 @@ exports.defineAutoTests = function () {
                         }, 1000);
                     }
                 };
-                media = new Media(mediaFile, successCallback, failed.bind(self, done, 'media1 = new Media - Error creating Media object. Media file: ' + mediaFile, context), statusChange);
+                media = new Media(mediaFile, successCallback, failed.bind(null, done, 'media1 = new Media - Error creating Media object. Media file: ' + mediaFile, context), statusChange);
                 
                 // CB-10535: Play after a few secs, to give allow enough buffering of media file before seeking
                 setTimeout(function() {
@@ -349,7 +353,6 @@ exports.defineAutoTests = function () {
                 return;
             }
             var mediaFile = 'https://cordova.apache.org/downloads/BlueZedEx.mp3',
-                mediaState = Media.MEDIA_STOPPED,
                 successCallback,
                 context = this,
                 flag = true,
@@ -371,8 +374,8 @@ exports.defineAutoTests = function () {
                         }, 4000);
                     }
                 };
-                
-            var media1 = new Media(mediaFile, successCallback, failed.bind(null, done, 'media1 = new Media - Error creating Media object. Media file: ' + mediaFile, context), statusChange);
+
+            var media1 = new Media(mediaFile, successCallback, failed.bind(null, done, 'media1 = new Media - Error creating Media object. Media file: ' + mediaFile, context), statusChange); // jshint ignore:line
             //make audio playback two times faster
             media1.setRate(2);
             media1.play();
@@ -901,7 +904,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
         pauseAudio();
     }, 'pauseBtn');
     createActionButton('HalfSpeed', function() {
-    
         if(halfSpeedBtn.firstChild.firstChild.innerText == 'HalfSpeed') {
             halfSpeedBtn.firstChild.firstChild.innerText = 'FullSpeed';
             media1.setRate(0.5);

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/www/Media.js
----------------------------------------------------------------------
diff --git a/www/Media.js b/www/Media.js
index 37b1511..57e4f76 100644
--- a/www/Media.js
+++ b/www/Media.js
@@ -159,7 +159,7 @@ Media.prototype.setRate = function(rate) {
     if (cordova.platformId === 'ios'){
         exec(null, null, "Media", "setRate", [this.id, rate]);
     } else {
-        console.warn('media.setRate method is currently not supported for', cordova.platformId, 'platform.')
+        console.warn('media.setRate method is currently not supported for', cordova.platformId, 'platform.');
     }
 };
 
@@ -176,30 +176,37 @@ Media.onStatus = function(id, msgType, value) {
 
     var media = mediaObjects[id];
 
-    if(media) {
+    if (media) {
         switch(msgType) {
             case Media.MEDIA_STATE :
-                media.statusCallback && media.statusCallback(value);
-                if(value == Media.MEDIA_STOPPED) {
-                    media.successCallback && media.successCallback();
+                if (media.statusCallback) {
+                    media.statusCallback(value);
+                }
+                if (value == Media.MEDIA_STOPPED) {
+                    if (media.successCallback) {
+                        media.successCallback();
+                    }
                 }
                 break;
             case Media.MEDIA_DURATION :
                 media._duration = value;
                 break;
             case Media.MEDIA_ERROR :
-                media.errorCallback && media.errorCallback(value);
+                if (media.errorCallback) {
+                    media.errorCallback(value);
+                }
                 break;
             case Media.MEDIA_POSITION :
                 media._position = Number(value);
                 break;
             default :
-                console.error && console.error("Unhandled Media.onStatus :: " + msgType);
+                if (console.error) {
+                    console.error("Unhandled Media.onStatus :: " + msgType);
+                }
                 break;
         }
-    }
-    else {
-         console.error && console.error("Received Media.onStatus callback for unknown media :: " + id);
+    } else if (console.error) {
+        console.error("Received Media.onStatus callback for unknown media :: " + id);
     }
 
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/3fe3a300/www/browser/Media.js
----------------------------------------------------------------------
diff --git a/www/browser/Media.js b/www/browser/Media.js
index 855faac..2e3da7f 100644
--- a/www/browser/Media.js
+++ b/www/browser/Media.js
@@ -19,7 +19,7 @@
  *
 */
 
-/*global MediaError, module, require*/
+/* global MediaError */
 
 var argscheck = require('cordova/argscheck'),
     utils = require('cordova/utils');
@@ -27,6 +27,38 @@ var argscheck = require('cordova/argscheck'),
 var mediaObjects = {};
 
 /**
+ * This class provides access to the device media, interfaces to both sound and video
+ *
+ * @constructor
+ * @param src                   The file name or url to play
+ * @param successCallback       The callback to be called when the file is done playing or recording.
+ *                                  successCallback()
+ * @param errorCallback         The callback to be called if there is an error.
+ *                                  errorCallback(int errorCode) - OPTIONAL
+ * @param statusCallback        The callback to be called when media status has changed.
+ *                                  statusCallback(int statusCode) - OPTIONAL
+ */
+var Media = function(src, successCallback, errorCallback, statusCallback) {
+    argscheck.checkArgs('SFFF', 'Media', arguments);
+    this.id = utils.createUUID();
+    mediaObjects[this.id] = this;
+    this.src = src;
+    this.successCallback = successCallback;
+    this.errorCallback = errorCallback;
+    this.statusCallback = statusCallback;
+    this._duration = -1;
+    this._position = -1;
+
+    Media.onStatus(this.id, Media.MEDIA_STATE, Media.MEDIA_STARTING);
+    
+    try {
+        this.node = createNode(this);
+    } catch (err) {
+        Media.onStatus(this.id, Media.MEDIA_ERROR, { code: MediaError.MEDIA_ERR_ABORTED });
+    }
+};
+
+/**
  * Creates new Audio node and with necessary event listeners attached
  * @param  {Media} media Media object
  * @return {Audio}       Audio element 
@@ -66,38 +98,6 @@ function createNode (media) {
     return node;
 }
 
-/**
- * This class provides access to the device media, interfaces to both sound and video
- *
- * @constructor
- * @param src                   The file name or url to play
- * @param successCallback       The callback to be called when the file is done playing or recording.
- *                                  successCallback()
- * @param errorCallback         The callback to be called if there is an error.
- *                                  errorCallback(int errorCode) - OPTIONAL
- * @param statusCallback        The callback to be called when media status has changed.
- *                                  statusCallback(int statusCode) - OPTIONAL
- */
-var Media = function(src, successCallback, errorCallback, statusCallback) {
-    argscheck.checkArgs('SFFF', 'Media', arguments);
-    this.id = utils.createUUID();
-    mediaObjects[this.id] = this;
-    this.src = src;
-    this.successCallback = successCallback;
-    this.errorCallback = errorCallback;
-    this.statusCallback = statusCallback;
-    this._duration = -1;
-    this._position = -1;
-
-    Media.onStatus(this.id, Media.MEDIA_STATE, Media.MEDIA_STARTING);
-    
-    try {
-        this.node = createNode(this);
-    } catch (err) {
-        Media.onStatus(this.id, Media.MEDIA_ERROR, { code: MediaError.MEDIA_ERR_ABORTED });
-    }
-};
-
 // Media messages
 Media.MEDIA_STATE = 1;
 Media.MEDIA_DURATION = 2;
@@ -230,29 +230,37 @@ Media.onStatus = function(id, msgType, value) {
 
     var media = mediaObjects[id];
 
-    if(media) {
+    if (media) {
         switch(msgType) {
             case Media.MEDIA_STATE :
-                media.statusCallback && media.statusCallback(value);
-                if(value === Media.MEDIA_STOPPED) {
-                    media.successCallback && media.successCallback();
+                if (media.statusCallback) {
+                    media.statusCallback(value);
+                }
+                if (value === Media.MEDIA_STOPPED) {
+                    if (media.successCallback) {
+                        media.successCallback();
+                    }
                 }
                 break;
             case Media.MEDIA_DURATION :
                 media._duration = value;
                 break;
             case Media.MEDIA_ERROR :
-                media.errorCallback && media.errorCallback(value);
+                if (media.errorCallback) {
+                    media.errorCallback(value);
+                }
                 break;
             case Media.MEDIA_POSITION :
                 media._position = Number(value);
                 break;
             default :
-                console.error && console.error("Unhandled Media.onStatus :: " + msgType);
+                if (console.error) {
+                    console.error("Unhandled Media.onStatus :: " + msgType);
+                }
                 break;
         }
-    } else {
-         console.error && console.error("Received Media.onStatus callback for unknown media :: " + id);
+    } else if (console.error) {
+        console.error("Received Media.onStatus callback for unknown media :: " + id);
     }
 };
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org