-
Notifications
You must be signed in to change notification settings - Fork 4
/
cast-away.min.js
1 lines (1 loc) · 15.1 KB
/
cast-away.min.js
1
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){(function(){var CastAway,CustomReceiver,EventEmitter,MediaControls,Session,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child},__slice=[].slice;EventEmitter=require("./event_emitter");Session=require("./session");MediaControls=require("./media-controls");CustomReceiver=require("./custom-receiver");CastAway=function(_super){__extends(CastAway,_super);function CastAway(_arg){var _ref;_ref=_arg!=null?_arg:{},this.applicationID=_ref.applicationID,this.namespace=_ref.namespace;if(!((typeof chrome!=="undefined"&&chrome!==null?chrome.cast:void 0)||cast)){throw"chrome.cast namespace not found"}this.cast=(typeof chrome!=="undefined"&&chrome!==null?chrome.cast:void 0)||cast}CastAway.prototype.initialize=function(cb){var initializeCastApi,intervalId;initializeCastApi=function(_this){return function(){var apiConfig,app,error,sessionRequest,success;app=_this.applicationID||_this.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID;sessionRequest=new _this.cast.SessionRequest(app);apiConfig=new _this.cast.ApiConfig(sessionRequest,function(){var data;data=1<=arguments.length?__slice.call(arguments,0):[];return _this.sessionListener.apply(_this,data)},function(){var data;data=1<=arguments.length?__slice.call(arguments,0):[];return _this.receiverListener.apply(_this,data)});success=function(data){clearInterval(intervalId);return cb(null,data)};error=function(err){return cb(err)};return _this.cast.initialize(apiConfig,success,error)}}(this);return intervalId=setInterval(function(){if(chrome.cast&&chrome.cast.isAvailable&&chrome.cast.media&&chrome.cast.SessionRequest){return initializeCastApi()}},15)};CastAway.prototype.receive=function(config){if(config==null){config={}}this.receiver=new CustomReceiver(config,this);this.receiver.start();return this.receiver};CastAway.prototype.sessionListener=function(session){if(session.media.length!==0){this.currentSession=session;session.addUpdateListener(this.sessionUpdateListener);return this.emit("existingMediaFound",new Session(this.currentSession,this),new MediaControls(this.currentSession.media[0],this))}};CastAway.prototype.receiverListener=function(receiver){var available,state;available=this.cast.ReceiverAvailability.AVAILABLE;state=receiver===available?"available":"unavailable";return this.emit("receivers:"+state)};CastAway.prototype.sessionUpdateListener=function(isAlive){if(!isAlive){return this.currentSession=null}};CastAway.prototype.requestSession=function(cb){var onError,onSuccess;onSuccess=function(_this){return function(session){return cb(null,new Session(session,_this))}}(this);onError=function(err){return cb(err)};return this.cast.requestSession(onSuccess,onError)};return CastAway}(EventEmitter);window.CastAway=CastAway}).call(this)},{"./custom-receiver":2,"./event_emitter":3,"./media-controls":4,"./session":5}],2:[function(require,module,exports){(function(){var CustomReceiver,DEFAULT_MAX_INACTIVITY,DEFAULT_STATUS_TEXT,EventEmitter,__bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};EventEmitter=require("./event_emitter");DEFAULT_STATUS_TEXT="Ready";DEFAULT_MAX_INACTIVITY=60;module.exports=CustomReceiver=function(_super){__extends(CustomReceiver,_super);function CustomReceiver(config,castAway){this.castAway=castAway;this.onMessage=__bind(this.onMessage,this);this.namespace=this.castAway.namespace||"urn:x-cast:json";this.config=new cast.receiver.CastReceiverManager.Config;this.config.statusText=config.statusText||DEFAULT_STATUS_TEXT;this.config.maxInactivity=config.maxInactivity||DEFAULT_MAX_INACTIVITY}CustomReceiver.prototype.start=function(){var bus,manager;manager=cast.receiver.CastReceiverManager.getInstance();bus=manager.getCastMessageBus(this.namespace);bus.onMessage=this.onMessage;return manager.start(this.config)};CustomReceiver.prototype.onMessage=function(event){var data,msgName,payload;data=JSON.parse(event.data);msgName=data._name;payload=data._payload;return this.emit(msgName,payload)};return CustomReceiver}(EventEmitter)}).call(this)},{"./event_emitter":3}],3:[function(require,module,exports){(function(){"use strict";function EventEmitter(){}var proto=EventEmitter.prototype;var exports=this;var originalGlobalValue=exports.EventEmitter;function indexOfListener(listeners,listener){var i=listeners.length;while(i--){if(listeners[i].listener===listener){return i}}return-1}function alias(name){return function aliasClosure(){return this[name].apply(this,arguments)}}proto.getListeners=function getListeners(evt){var events=this._getEvents();var response;var key;if(evt instanceof RegExp){response={};for(key in events){if(events.hasOwnProperty(key)&&evt.test(key)){response[key]=events[key]}}}else{response=events[evt]||(events[evt]=[])}return response};proto.flattenListeners=function flattenListeners(listeners){var flatListeners=[];var i;for(i=0;i<listeners.length;i+=1){flatListeners.push(listeners[i].listener)}return flatListeners};proto.getListenersAsObject=function getListenersAsObject(evt){var listeners=this.getListeners(evt);var response;if(listeners instanceof Array){response={};response[evt]=listeners}return response||listeners};proto.addListener=function addListener(evt,listener){var listeners=this.getListenersAsObject(evt);var listenerIsWrapped=typeof listener==="object";var key;for(key in listeners){if(listeners.hasOwnProperty(key)&&indexOfListener(listeners[key],listener)===-1){listeners[key].push(listenerIsWrapped?listener:{listener:listener,once:false})}}return this};proto.on=alias("addListener");proto.addOnceListener=function addOnceListener(evt,listener){return this.addListener(evt,{listener:listener,once:true})};proto.once=alias("addOnceListener");proto.defineEvent=function defineEvent(evt){this.getListeners(evt);return this};proto.defineEvents=function defineEvents(evts){for(var i=0;i<evts.length;i+=1){this.defineEvent(evts[i])}return this};proto.removeListener=function removeListener(evt,listener){var listeners=this.getListenersAsObject(evt);var index;var key;for(key in listeners){if(listeners.hasOwnProperty(key)){index=indexOfListener(listeners[key],listener);if(index!==-1){listeners[key].splice(index,1)}}}return this};proto.off=alias("removeListener");proto.addListeners=function addListeners(evt,listeners){return this.manipulateListeners(false,evt,listeners)};proto.removeListeners=function removeListeners(evt,listeners){return this.manipulateListeners(true,evt,listeners)};proto.manipulateListeners=function manipulateListeners(remove,evt,listeners){var i;var value;var single=remove?this.removeListener:this.addListener;var multiple=remove?this.removeListeners:this.addListeners;if(typeof evt==="object"&&!(evt instanceof RegExp)){for(i in evt){if(evt.hasOwnProperty(i)&&(value=evt[i])){if(typeof value==="function"){single.call(this,i,value)}else{multiple.call(this,i,value)}}}}else{i=listeners.length;while(i--){single.call(this,evt,listeners[i])}}return this};proto.removeEvent=function removeEvent(evt){var type=typeof evt;var events=this._getEvents();var key;if(type==="string"){delete events[evt]}else if(evt instanceof RegExp){for(key in events){if(events.hasOwnProperty(key)&&evt.test(key)){delete events[key]}}}else{delete this._events}return this};proto.removeAllListeners=alias("removeEvent");proto.emitEvent=function emitEvent(evt,args){var listeners=this.getListenersAsObject(evt);var listener;var i;var key;var response;for(key in listeners){if(listeners.hasOwnProperty(key)){i=listeners[key].length;while(i--){listener=listeners[key][i];if(listener.once===true){this.removeListener(evt,listener.listener)}response=listener.listener.apply(this,args||[]);if(response===this._getOnceReturnValue()){this.removeListener(evt,listener.listener)}}}}return this};proto.trigger=alias("emitEvent");proto.emit=function emit(evt){var args=Array.prototype.slice.call(arguments,1);return this.emitEvent(evt,args)};proto.setOnceReturnValue=function setOnceReturnValue(value){this._onceReturnValue=value;return this};proto._getOnceReturnValue=function _getOnceReturnValue(){if(this.hasOwnProperty("_onceReturnValue")){return this._onceReturnValue}else{return true}};proto._getEvents=function _getEvents(){return this._events||(this._events={})};EventEmitter.noConflict=function noConflict(){exports.EventEmitter=originalGlobalValue;return EventEmitter};if(typeof define==="function"&&define.amd){define(function(){return EventEmitter})}else if(typeof module==="object"&&module.exports){module.exports=EventEmitter}else{this.EventEmitter=EventEmitter}module.exports=EventEmitter}).call(this)},{}],4:[function(require,module,exports){(function(){var MediaControls;MediaControls=function(){function MediaControls(session,castAway){this.session=session;this.castAway=castAway;if(!this.session){throw"No session passed"}if(!this.castAway.cast){throw"CastAway instance not found"}this.cast=this.castAway.cast}MediaControls.prototype.play=function(cb){if(cb==null){cb=function(){}}return this.session.play(null,function(data){return cb(null,data)},function(err){return cb(err)})};MediaControls.prototype.pause=function(cb){if(cb==null){cb=function(){}}return this.session.pause(null,function(data){return cb(null,data)},function(err){return cb(err)})};MediaControls.prototype.stop=function(cb){if(cb==null){cb=function(){}}return this.session.stop(null,function(data){return cb(null,data)},function(err){return cb(err)})};MediaControls.prototype.seek=function(time,cb){var seekRequest;if(cb==null){cb=function(){}}seekRequest=this.cast.session.SeekRequest(time);return this.session.seek(seekRequest,function(data){return cb(null,data)},function(err){return cb(err)})};return MediaControls}();module.exports=MediaControls}).call(this)},{}],5:[function(require,module,exports){(function(){var EventEmitter,MediaControls,Session,assignMetadata,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};EventEmitter=require("./event_emitter");MediaControls=require("./media-controls");Session=function(_super){__extends(Session,_super);function Session(session,castAway){this.session=session;this.castAway=castAway;if(!this.castAway.cast){throw"CastAway instance not found"}this.cast=this.castAway.cast;this.namespace=this.castAway.namespace||"urn:x-cast:json";if(this.session.media[0]){this.session.media[0].addUpdateListener(function(_this){return function(){return _this.sessionUpdateListener()}}(this))}}Session.prototype.displayName=function(){return this.session.displayName};Session.prototype.receiverName=function(){return this.session.receiver.friendlyName};Session.prototype.send=function(name,payload,cb){var data,onError,onSuccess;if(payload==null){payload={}}if(cb==null){cb=function(){}}onSuccess=function(data){return cb(null,data)};onError=function(err){return cb(err)};data=JSON.stringify({_name:name,_payload:payload});return this.session.sendMessage(this.namespace,data,onSuccess,onError)};Session.prototype.load=function(mediaInfo,cb){var onError,onSuccess,request;if(cb==null){cb=function(){}}request=new chrome.cast.media.LoadRequest(mediaInfo);onSuccess=function(_this){return function(media){var controls;media.addUpdateListener(function(){return _this.sessionUpdateListener()});controls=new MediaControls(media,_this.castAway);return cb(null,controls)}}(this);onError=function(err){return cb(err)};return this.session.loadMedia(request,onSuccess,onError)};Session.prototype.sessionUpdateListener=function(){var event,media;media=this.session.media[0];event=function(){switch(media.playerState){case"PLAYING":return"play";case"PAUSED":return"pause";case"STOPPED":return"stop";case"SEEKING":return"seek";case"ERROR":return"error";case"IDLE":return"idle";case"LOADING":return"load"}}();return this.emit(event)};Session.prototype.music=function(config,cb){var mediaInfo,metadata;if(config==null){config={}}if(cb==null){cb=function(){}}if(!config.url){throw"Url required for music"}if(!config.contentType){throw"Content-type required for music"}mediaInfo=new chrome.cast.media.MediaInfo(config.url,config.contentType);metadata=new chrome.cast.media.MusicTrackMediaMetadata;metadata.metadataType=chrome.cast.media.MetadataType.MUSIC_TRACK;mediaInfo.metadata=assignMetadata(metadata,config);return this.load(mediaInfo,cb)};Session.prototype.tvShow=function(config,cb){var mediaInfo,metadata;if(config==null){config={}}if(cb==null){cb=function(){}}if(!config.url){throw"Url required for tv show"}if(!config.contentType){throw"Content-type required for tv show"}mediaInfo=new chrome.cast.media.MediaInfo(config.url,config.contentType);metadata=new chrome.cast.media.TvShowMediaMetadata;metadata.metadataType=chrome.cast.media.MetadataType.TV_SHOW;mediaInfo.metadata=assignMetadata(metadata,config);return this.load(mediaInfo,cb)};Session.prototype.movie=function(config,cb){var mediaInfo,metadata;if(config==null){config={}}if(cb==null){cb=function(){}}if(!config.url){throw"Url required for movie"}if(!config.contentType){throw"Content-type required for movie"}mediaInfo=new chrome.cast.media.MediaInfo(config.url,config.contentType);metadata=new chrome.cast.media.MovieMediaMetadata;metadata.metadataType=chrome.cast.media.MetadataType.MOVIE;mediaInfo.metadata=assignMetadata(metadata,config);return this.load(mediaInfo,cb)};Session.prototype.photo=function(config,cb){var mediaInfo,metadata;if(config==null){config={}}if(cb==null){cb=function(){}}if(!config.url){throw"Url required for photo"}if(!config.contentType){throw"Content-type required for photo"}mediaInfo=new chrome.cast.media.MediaInfo(config.url,config.contentType);metadata=new chrome.cast.media.PhotoMediaMetadata;metadata.metadataType=chrome.cast.media.MetadataType.PHOTO;mediaInfo.metadata=assignMetadata(metadata,config);return this.load(mediaInfo,cb)};Session.prototype.release=function(cb){if(cb==null){cb=function(){}}if(!this.session){return}this.emit("release");return this.session.stop(function(data){return cb(null,data)},function(err){return cb(err)})};return Session}(EventEmitter);assignMetadata=function(metadata,config){var image,key,value;for(key in config){value=config[key];if(key==="images"){value=function(){var _i,_len,_results;_results=[];for(_i=0,_len=value.length;_i<_len;_i++){image=value[_i];_results.push(new chrome.cast.Image(image))}return _results}()}metadata[key]=value}return metadata};module.exports=Session}).call(this)},{"./event_emitter":3,"./media-controls":4}]},{},[1]);