This commit is contained in:
Pierre Rudloff 2016-06-22 12:02:48 +02:00
parent c92573e3dc
commit 8b30070a86
3 changed files with 21 additions and 30 deletions

View file

@ -41,7 +41,9 @@ module.exports = function (grunt) {
}, },
tests: { tests: {
src: ['tests/*.php'] src: ['tests/*.php']
}
}, },
jslint: {
js: { js: {
src: ['js/*.js'] src: ['js/*.js']
}, },
@ -72,9 +74,10 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-phpcs'); grunt.loadNpmTasks('grunt-phpcs');
grunt.loadNpmTasks('grunt-phpunit'); grunt.loadNpmTasks('grunt-phpunit');
grunt.loadNpmTasks('grunt-contrib-compress'); grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-jslint');
grunt.registerTask('default', ['uglify', 'cssmin']); grunt.registerTask('default', ['uglify', 'cssmin']);
grunt.registerTask('lint', ['phpcs']); grunt.registerTask('lint', ['phpcs', 'jslint']);
grunt.registerTask('test', ['phpunit']); grunt.registerTask('test', ['phpunit']);
grunt.registerTask('release', ['default', 'githash', 'compress']); grunt.registerTask('release', ['default', 'githash', 'compress']);
}; };

View file

@ -3,14 +3,12 @@
var launchBtn, disabledBtn, stopBtn; var launchBtn, disabledBtn, stopBtn;
var session, currentMedia; var session, currentMedia;
function receiverListener(e) function receiverListener(e) {
{
'use strict'; 'use strict';
console.log('receiverListener', e); console.log('receiverListener', e);
} }
function onMediaDiscovered(how, media) function onMediaDiscovered(how, media) {
{
'use strict'; 'use strict';
console.log('onMediaDiscovered', how); console.log('onMediaDiscovered', how);
currentMedia = media; currentMedia = media;
@ -20,8 +18,7 @@ function onMediaDiscovered(how, media)
} }
} }
function sessionListener(e) function sessionListener(e) {
{
'use strict'; 'use strict';
session = e; session = e;
session.addMediaListener(onMediaDiscovered.bind(this, 'addMediaListener')); session.addMediaListener(onMediaDiscovered.bind(this, 'addMediaListener'));
@ -30,48 +27,41 @@ function sessionListener(e)
} }
} }
function onStopCast() function onStopCast() {
{
'use strict'; 'use strict';
stopBtn.classList.add('cast_hidden'); stopBtn.classList.add('cast_hidden');
launchBtn.classList.remove('cast_hidden'); launchBtn.classList.remove('cast_hidden');
} }
function stopCast() function stopCast() {
{
'use strict'; 'use strict';
session.stop(onStopCast); session.stop(onStopCast);
} }
function onMediaError() function onMediaError() {
{
'use strict'; 'use strict';
console.log('onMediaError'); console.log('onMediaError');
stopCast(); stopCast();
} }
function onRequestSessionSuccess(e) function onRequestSessionSuccess(e) {
{
'use strict'; 'use strict';
session = e; session = e;
var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo); var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo);
session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError); session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError);
} }
function onLaunchError(e) function onLaunchError(e) {
{
'use strict'; 'use strict';
console.log('onLaunchError', e.description); console.log('onLaunchError', e.description);
} }
function launchCast() function launchCast() {
{
'use strict'; 'use strict';
chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError); chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
} }
function onInitSuccess() function onInitSuccess() {
{
'use strict'; 'use strict';
launchBtn = document.getElementById('cast_btn_launch'); launchBtn = document.getElementById('cast_btn_launch');
disabledBtn = document.getElementById('cast_disabled'); disabledBtn = document.getElementById('cast_disabled');
@ -84,21 +74,18 @@ function onInitSuccess()
} }
} }
function onError() function onError() {
{
'use strict'; 'use strict';
console.log('onError'); console.log('onError');
} }
function initializeCastApi() function initializeCastApi() {
{
'use strict'; 'use strict';
var sessionRequest = new chrome.cast.SessionRequest(chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID), apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener, chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED); var sessionRequest = new chrome.cast.SessionRequest(chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID), apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener, chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED);
chrome.cast.initialize(apiConfig, onInitSuccess, onError); chrome.cast.initialize(apiConfig, onInitSuccess, onError);
} }
function loadCastApi(loaded, errorInfo) function loadCastApi(loaded, errorInfo) {
{
'use strict'; 'use strict';
if (loaded) { if (loaded) {
initializeCastApi(); initializeCastApi();
@ -107,4 +94,4 @@ function loadCastApi(loaded, errorInfo)
} }
} }
window['__onGCastApiAvailable'] = loadCastApi; window.__onGCastApiAvailable = loadCastApi;

View file

@ -12,7 +12,8 @@
"grunt-phpunit": "~0.3.6", "grunt-phpunit": "~0.3.6",
"grunt-contrib-compress": "~1.2.0", "grunt-contrib-compress": "~1.2.0",
"bower": "~1.7.1", "bower": "~1.7.1",
"grunt-githash": "~0.1.3" "grunt-githash": "~0.1.3",
"grunt-jslint": "~1.1.14"
}, },
"repository": { "repository": {
"type": "git", "type": "git",