Skip to content

Commit

Permalink
Convert jshint to eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
GedasGa committed Jun 18, 2019
1 parent b1c1353 commit 97c5db9
Show file tree
Hide file tree
Showing 9 changed files with 700 additions and 685 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off
17 changes: 0 additions & 17 deletions .jshintrc

This file was deleted.

12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"cordova-windows"
],
"scripts": {
"test": "npm run jshint",
"jshint": "jshint www && jshint src && jshint tests"
"test": "npm run eslint",
"eslint": "eslint --ignore-path .gitignore ."
},
"author": "Apache Software Foundation",
"license": "Apache-2.0",
Expand All @@ -48,6 +48,12 @@
}
},
"devDependencies": {
"jshint": "^2.6.0"
"eslint": "^5.15.2",
"eslint-config-semistandard": "^13.0.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0"
}
}
103 changes: 52 additions & 51 deletions src/windows/MediaProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
*
*/

/*global Windows:true */
/* global Windows Audio */
/* eslint no-undef: "error" */

var Media = require('cordova-plugin-media.Media');
var MediaError = require('cordova-plugin-media.MediaError');

var recordedFile;
var tempFolderAppDataBasePath = 'ms-appdata:///temp/',
localFolderAppDataBasePath = 'ms-appdata:///local/',
tempFolderFullPath = Windows.Storage.ApplicationData.current.temporaryFolder.path,
localFolderFullPath = Windows.Storage.ApplicationData.current.localFolder.path;
var tempFolderAppDataBasePath = 'ms-appdata:///temp/';
var localFolderAppDataBasePath = 'ms-appdata:///local/';
var tempFolderFullPath = Windows.Storage.ApplicationData.current.temporaryFolder.path;
var localFolderFullPath = Windows.Storage.ApplicationData.current.localFolder.path;

var PARAMETER_IS_INCORRECT = -2147024809;
var SUPPORTED_EXTENSIONS = ['.mp3', '.wma', '.wav', '.cda', '.adx', '.wm', '.m3u', '.wmx', '.m4a'];
Expand All @@ -40,10 +41,10 @@ var fsTypes = {
};

module.exports = {
mediaCaptureMrg:null,
mediaCaptureMrg: null,

// Initiates the audio file
create:function(win, lose, args) {
create: function (win, lose, args) {
var id = args[0];

var srcUri = processUri(args[1]);
Expand All @@ -66,7 +67,7 @@ module.exports = {
// Don't create Audio object in case of record mode
if (createAudioNode === true) {
thisM.node = new Audio();
thisM.node.msAudioCategory = "BackgroundCapableMedia";
thisM.node.msAudioCategory = 'BackgroundCapableMedia';
thisM.node.src = srcUri.absoluteCanonicalUri;

thisM.node.onloadstart = function () {
Expand Down Expand Up @@ -104,10 +105,10 @@ module.exports = {
},

// Start playing the audio
startPlayingAudio:function(win, lose, args) {
startPlayingAudio: function (win, lose, args) {
var id = args[0];
//var src = args[1];
//var options = args[2];
// var src = args[1];
// var options = args[2];

var thisM = Media.get(id);
// if Media was released, then node will be null and we need to create it again
Expand All @@ -124,51 +125,51 @@ module.exports = {
thisM.node.play();
} catch (err) {
if (lose) {
lose({code:MediaError.MEDIA_ERR_ABORTED});
lose({ code: MediaError.MEDIA_ERR_ABORTED });
}
}
},

// Stops the playing audio
stopPlayingAudio:function(win, lose, args) {
stopPlayingAudio: function (win, lose, args) {
var id = args[0];
try {
var thisM = Media.get(id);
thisM.node.pause();
thisM.node.currentTime = 0;
Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED);
} catch (err) {
lose("Failed to stop: "+err);
lose('Failed to stop: ' + err);
}
},

// Seeks to the position in the audio
seekToAudio:function(win, lose, args) {
seekToAudio: function (win, lose, args) {
var id = args[0];
var milliseconds = args[1];
var thisM = Media.get(id);
try {
thisM.node.currentTime = milliseconds / 1000;
win(thisM.node.currentTime);
} catch (err) {
lose("Failed to seek: "+err);
lose('Failed to seek: ' + err);
}
},

// Pauses the playing audio
pausePlayingAudio:function(win, lose, args) {
pausePlayingAudio: function (win, lose, args) {
var id = args[0];
var thisM = Media.get(id);
try {
thisM.node.pause();
Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_PAUSED);
} catch (err) {
lose("Failed to pause: "+err);
lose('Failed to pause: ' + err);
}
},

// Gets current position in the audio
getCurrentPositionAudio:function(win, lose, args) {
getCurrentPositionAudio: function (win, lose, args) {
var id = args[0];
try {
var p = (Media.get(id)).node.currentTime;
Expand All @@ -179,7 +180,7 @@ module.exports = {
},

// Start recording audio
startRecordingAudio:function(win, lose, args) {
startRecordingAudio: function (win, lose, args) {
var id = args[0];
var srcUri = processUri(args[1]);

Expand All @@ -200,37 +201,37 @@ module.exports = {
var captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audio;
thisM.mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
thisM.mediaCaptureMgr.addEventListener("failed", error);
thisM.mediaCaptureMgr.addEventListener('failed', error);

thisM.mediaCaptureMgr.initializeAsync(captureInitSettings).done(function (result) {
thisM.mediaCaptureMgr.addEventListener("recordlimitationexceeded", error);
thisM.mediaCaptureMgr.addEventListener("failed", error);
thisM.mediaCaptureMgr.addEventListener('recordlimitationexceeded', error);
thisM.mediaCaptureMgr.addEventListener('failed', error);

// Start recording
Windows.Storage.ApplicationData.current.temporaryFolder.createFileAsync(destFileName, Windows.Storage.CreationCollisionOption.replaceExisting).done(function (newFile) {
recordedFile = newFile;
var encodingProfile = null;
switch (newFile.fileType) {
case '.m4a':
encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createM4a(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
break;
case '.mp3':
encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createMp3(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
break;
case '.wma':
encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createWma(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
break;
default:
error("Invalid file type for record");
break;
case '.m4a':
encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createM4a(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
break;
case '.mp3':
encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createMp3(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
break;
case '.wma':
encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createWma(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
break;
default:
error('Invalid file type for record');
break;
}
thisM.mediaCaptureMgr.startRecordToStorageFileAsync(encodingProfile, newFile).done(success, error);
}, error);
}, error);
},

// Stop recording audio
stopRecordingAudio:function(win, lose, args) {
stopRecordingAudio: function (win, lose, args) {
var id = args[0];
var thisM = Media.get(id);
var srcUri = processUri(thisM.src);
Expand Down Expand Up @@ -272,7 +273,7 @@ module.exports = {
},

// Release the media object
release:function(win, lose, args) {
release: function (win, lose, args) {
var id = args[0];
var thisM = Media.get(id);
try {
Expand All @@ -285,10 +286,10 @@ module.exports = {
delete thisM.node;
}
} catch (err) {
lose("Failed to release: "+err);
lose('Failed to release: ' + err);
}
},
setVolume:function(win, lose, args) {
setVolume: function (win, lose, args) {
var id = args[0];
var volume = args[1];
var thisM = Media.get(id);
Expand All @@ -297,12 +298,12 @@ module.exports = {
};

/**
* Converts a path to Windows.Foundation.Uri basing on App data temporary folder
* Converts a path to Windows.Foundation.Uri basing on App data temporary folder
* if scheme is not defined, e.g.: path/to/file.m4a -> ms-appdata:///temp/path/to/file.m4a
* @param {String} src Input path
* @return {Object} Windows.Foundation.Uri
*/
function setTemporaryFsByDefault(src) {
function setTemporaryFsByDefault (src) {
var uri;
try {
uri = new Windows.Foundation.Uri(src);
Expand All @@ -314,7 +315,7 @@ function setTemporaryFsByDefault(src) {
throw e;
}
} finally {
return uri;
return uri; // eslint-disable-line
}
}

Expand All @@ -323,13 +324,13 @@ function setTemporaryFsByDefault(src) {
* @param {Object} uri Windows.Foundation.Uri
* @return {Object} ms-appdata Windows.Foundation.Uri
*/
function fullPathToAppData(uri) {
function fullPathToAppData (uri) {
if (uri.schemeName === 'file') {
if (uri.rawUri.indexOf(Windows.Storage.ApplicationData.current.localFolder.path) !== -1) {
// Also remove path' beginning slash to avoid losing folder name part
uri = new Windows.Foundation.Uri(localFolderAppDataBasePath, uri.rawUri.replace(localFolderFullPath, '').replace(/^[\\\/]{1,2}/, ''));
uri = new Windows.Foundation.Uri(localFolderAppDataBasePath, uri.rawUri.replace(localFolderFullPath, '').replace(/^[\\/]{1,2}/, ''));
} else if (uri.rawUri.indexOf(Windows.Storage.ApplicationData.current.temporaryFolder.path) !== -1) {
uri = new Windows.Foundation.Uri(tempFolderAppDataBasePath, uri.rawUri.replace(tempFolderFullPath, '').replace(/^[\\\/]{1,2}/, ''));
uri = new Windows.Foundation.Uri(tempFolderAppDataBasePath, uri.rawUri.replace(tempFolderFullPath, '').replace(/^[\\/]{1,2}/, ''));
} else {
throw new Error('Not supported file uri: ' + uri.rawUri);
}
Expand All @@ -343,7 +344,7 @@ function fullPathToAppData(uri) {
* @param {Object} uri Input cdvfile scheme Windows.Foundation.Uri
* @return {Object} Windows.Foundation.Uri based on App data path
*/
function cdvfileToAppData(uri) {
function cdvfileToAppData (uri) {
var cdvFsRoot;

if (uri.schemeName === 'cdvfile') {
Expand All @@ -365,12 +366,12 @@ function cdvfileToAppData(uri) {
* @param {String} src Input media path
* @return {Object} Windows.Foundation.Uri
*/
function processUri(src) {
function processUri (src) {
// Collapse double slashes (File plugin issue): ms-appdata:///temp//recs/memos/media.m4a => ms-appdata:///temp/recs/memos/media.m4a
src = src.replace(/([^\/:])(\/\/)([^\/])/g, '$1/$3');
src = src.replace(/([^/:])(\/\/)([^/])/g, '$1/$3');

// Remove beginning slashes
src = src.replace(/^[\\\/]{1,2}/, '');
src = src.replace(/^[\\/]{1,2}/, '');

var uri = setTemporaryFsByDefault(src);

Expand All @@ -385,7 +386,7 @@ function processUri(src) {
* @param {Object} uri Windows.Foundation.Uri
* @return {Object} Object containing path, filename and filesystem type
*/
function parseUriToPathAndFilename(uri) {
function parseUriToPathAndFilename (uri) {
// Removing scheme and location, using backslashes: ms-appdata:///local/path/to/file.m4a -> path\\to\\file.m4a
var normalizedSrc = uri.path.split('/').slice(2).join('\\');

Expand All @@ -407,4 +408,4 @@ function parseUriToPathAndFilename(uri) {
};
}

require("cordova/exec/proxy").add("Media",module.exports);
require('cordova/exec/proxy').add('Media', module.exports);
19 changes: 19 additions & 0 deletions tests/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

env:
jasmine: true
Loading

0 comments on commit 97c5db9

Please sign in to comment.