/* * Copyright 2016 Google Inc. All Rights Reserved. * Licensed 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. */ var Util = require('../util'); var CAMEL_TO_UNDERSCORE = { video: 'video', image: 'image', preview: 'preview', loop: 'loop', volume: 'volume', muted: 'muted', isStereo: 'is_stereo', defaultYaw: 'default_yaw', isYawOnly: 'is_yaw_only', isDebug: 'is_debug', isVROff: 'is_vr_off', isAutopanOff: 'is_autopan_off', hideFullscreenButton: 'hide_fullscreen_button' }; /** * Contains all information about a given scene. */ function SceneInfo(opt_params) { var params = opt_params || {}; params.player = { loop: opt_params.loop, volume: opt_params.volume, muted: opt_params.muted }; this.image = params.image !== undefined ? encodeURI(params.image) : undefined; this.preview = params.preview !== undefined ? encodeURI(params.preview) : undefined; this.video = params.video !== undefined ? encodeURI(params.video) : undefined; this.defaultYaw = THREE.Math.degToRad(params.defaultYaw || 0); this.isStereo = Util.parseBoolean(params.isStereo); this.isYawOnly = Util.parseBoolean(params.isYawOnly); this.isDebug = Util.parseBoolean(params.isDebug); this.isVROff = Util.parseBoolean(params.isVROff); this.isAutopanOff = Util.parseBoolean(params.isAutopanOff); this.loop = Util.parseBoolean(params.player.loop); this.volume = parseFloat( params.player.volume ? params.player.volume : '1'); this.muted = Util.parseBoolean(params.player.muted); this.hideFullscreenButton = Util.parseBoolean(params.hideFullscreenButton); } SceneInfo.loadFromGetParams = function() { var params = {}; for (var camelCase in CAMEL_TO_UNDERSCORE) { var underscore = CAMEL_TO_UNDERSCORE[camelCase]; params[camelCase] = Util.getQueryParameter(underscore) || ((window.WebVRConfig && window.WebVRConfig.PLAYER) ? window.WebVRConfig.PLAYER[underscore] : ""); } var scene = new SceneInfo(params); if (!scene.isValid()) { console.warn('Invalid scene: %s', scene.errorMessage); } return scene; }; SceneInfo.loadFromAPIParams = function(underscoreParams) { var params = {}; for (var camelCase in CAMEL_TO_UNDERSCORE) { var underscore = CAMEL_TO_UNDERSCORE[camelCase]; if (underscoreParams[underscore]) { params[camelCase] = underscoreParams[underscore]; } } var scene = new SceneInfo(params); if (!scene.isValid()) { console.warn('Invalid scene: %s', scene.errorMessage); } return scene; }; SceneInfo.prototype.isValid = function() { // Either it's an image or a video. if (!this.image && !this.video) { this.errorMessage = 'Either image or video URL must be specified.'; return false; } if (this.image && !this.isValidImage_(this.image)) { this.errorMessage = 'Invalid image URL: ' + this.image; return false; } this.errorMessage = null; return true; }; /** * Generates a URL to reflect this scene. */ SceneInfo.prototype.getCurrentUrl = function() { var url = location.protocol + '//' + location.host + location.pathname + '?'; for (var camelCase in CAMEL_TO_UNDERSCORE) { var underscore = CAMEL_TO_UNDERSCORE[camelCase]; var value = this[camelCase]; if (value !== undefined) { url += underscore + '=' + value + '&'; } } // Chop off the trailing ampersand. return url.substring(0, url.length - 1); }; SceneInfo.prototype.isValidImage_ = function(imageUrl) { return true; }; module.exports = SceneInfo;