home *** CD-ROM | disk | FTP | other *** search
- package com.althea.client.shufflr.model
- {
- import com.althea.client.shufflr.ApplicationFacade;
- import com.althea.client.shufflr.controller.errors.ApplicationError;
- import flash.events.TimerEvent;
- import flash.utils.Timer;
- import flash.utils.getQualifiedClassName;
- import mx.collections.ArrayCollection;
- import mx.logging.ILogger;
- import mx.logging.Log;
- import mx.logging.LogEventLevel;
- import mx.rpc.AsyncToken;
- import mx.rpc.Fault;
- import mx.rpc.IResponder;
- import mx.rpc.events.FaultEvent;
- import mx.rpc.http.HTTPService;
- import mx.utils.ObjectProxy;
- import org.puremvc.as3.multicore.patterns.proxy.Proxy;
-
- public class NavMapProxy extends Proxy implements IResponder
- {
- public static var serverUrl:String;
-
- public static var analyticServerUrl:String;
-
- public static const NAME:String = "NavMapProxy";
-
- private var navMapData:ArrayCollection = new ArrayCollection();
-
- private var msgData:Object = new Object();
-
- private var channelsOnHome:ArrayCollection = new ArrayCollection();
-
- private var initItems:ArrayCollection = new ArrayCollection();
-
- private var ticker:Timer;
-
- private var ctrlItems:ArrayCollection = new ArrayCollection();
-
- private var homeViewRefreshRate:ArrayCollection = new ArrayCollection();
-
- private var navMapVersion:Number = 0.1;
-
- private var writeLog:ILogger;
-
- private var service:HTTPService;
-
- private var _timerDuration:uint = 2000;
-
- private var read_Navmap_Once:Boolean = false;
-
- private var welcomeMsg:String;
-
- public function NavMapProxy(param1:Object = null)
- {
- super(NAME,param1);
- var _loc2_:String = getQualifiedClassName(this).replace("::",".");
- this.writeLog = Log.getLogger(_loc2_);
- this.service = new HTTPService();
- this.service.method = "GET";
- this.service.requestTimeout = 20;
- }
-
- private function startTimer() : void
- {
- this.ticker.start();
- }
-
- public function loadCtrlItems() : ArrayCollection
- {
- var _loc3_:Object = null;
- var _loc1_:ArrayCollection = new ArrayCollection();
- var _loc2_:int = 0;
- _loc2_ = 0;
- while(_loc2_ < this.ctrlItems.length)
- {
- _loc3_ = new Object();
- _loc3_.name = this.ctrlItems[_loc2_].name;
- _loc3_.title = this.ctrlItems[_loc2_].title;
- _loc3_.thumbnail = this.ctrlItems[_loc2_].thumbnail;
- _loc3_.thumbnail.url = this.ctrlItems[_loc2_].thumbnail.url;
- _loc3_.link = this.ctrlItems[_loc2_].link;
- _loc3_.notification = this.ctrlItems[_loc2_].notification;
- _loc3_.view = this.ctrlItems[_loc2_].view;
- _loc3_.dataType = this.ctrlItems[_loc2_].dataType;
- _loc1_.addItem(_loc3_);
- _loc2_++;
- }
- return _loc1_;
- }
-
- public function getChannelOnHome() : ArrayCollection
- {
- var _loc3_:Object = null;
- var _loc1_:ArrayCollection = new ArrayCollection();
- var _loc2_:int = 0;
- _loc2_ = 0;
- while(_loc2_ < this.channelsOnHome.length)
- {
- _loc3_ = new Object();
- _loc3_.name = this.channelsOnHome[_loc2_].name;
- _loc3_.title = this.channelsOnHome[_loc2_].title;
- _loc3_.description = this.channelsOnHome[_loc2_].description;
- _loc3_.sf_id = this.channelsOnHome[_loc2_].sf_id;
- _loc3_.thumbnail = this.channelsOnHome[_loc2_].thumbnail;
- _loc3_.thumbnail.url = this.channelsOnHome[_loc2_].thumbnail.url;
- _loc3_.link = this.channelsOnHome[_loc2_].link;
- _loc3_.view = this.channelsOnHome[_loc2_].view;
- _loc3_.dataType = this.channelsOnHome[_loc2_].dataType;
- _loc1_.addItem(_loc3_);
- _loc2_++;
- }
- return _loc1_;
- }
-
- private function setupInitItems() : void
- {
- var _loc2_:ArrayCollection = null;
- var _loc3_:String = null;
- var _loc1_:int = 0;
- while(_loc1_ < this.initItems.length)
- {
- _loc2_ = this.loadMenuData(this.initItems[_loc1_].link);
- _loc3_ = this.initItems[_loc1_].dataType;
- sendNotification(_loc3_,_loc2_);
- _loc1_++;
- }
- }
-
- public function loadNavMapData() : void
- {
- this.sendRequest();
- }
-
- private function get duration() : uint
- {
- return this._timerDuration;
- }
-
- public function result(param1:Object) : void
- {
- var rpcEvent:Object = param1;
- var menuBarItems:ArrayCollection = null;
- var ctrlBarItems:ArrayCollection = null;
- var msg:Object = null;
- try
- {
- this.navMapVersion = rpcEvent.result.navMap.version as Number;
- this.timerDuration = rpcEvent.result.navMap.expiryTime as uint;
- this.navMapData = rpcEvent.result.navMap.items.item as ArrayCollection;
- this.initItems = rpcEvent.result.navMap.initItems.item as ArrayCollection;
- this.homeViewRefreshRate = rpcEvent.result.navMap.homeViewRefreshRate.item as ArrayCollection;
- if(rpcEvent.result.navMap.channelsOnHome.item is ArrayCollection)
- {
- this.channelsOnHome = rpcEvent.result.navMap.channelsOnHome.item as ArrayCollection;
- }
- else if(rpcEvent.result.navMap.channelsOnHome.item is ObjectProxy)
- {
- this.channelsOnHome = new ArrayCollection();
- this.channelsOnHome.addItem(rpcEvent.result.navMap.channelsOnHome.item);
- }
- this.ctrlItems = rpcEvent.result.navMap.ctrlItems.item as ArrayCollection;
- serverUrl = rpcEvent.result.navMap.server as String;
- analyticServerUrl = rpcEvent.result.navMap.analyticServer as String;
- this.welcomeMsg = rpcEvent.result.navMap.welcomeMsg as String;
- this.msgData = rpcEvent.result.navMap.msg as Object;
- menuBarItems = this.loadMenuBarData();
- ctrlBarItems = this.loadCtrlItems();
- msg = this.loadMsg();
- this.sendNotification(ApplicationFacade.NAVMAP_READ);
- this.sendNotification(ApplicationFacade.LOAD_MENU_BAR,menuBarItems);
- this.sendNotification(ApplicationFacade.LOAD_CONTROL_BAR,ctrlBarItems);
- this.sendNotification(ApplicationFacade.SET_WELCOME_MSG,this.welcomeMsg);
- this.sendNotification(ApplicationFacade.SET_MSG,msg);
- this.setupInitItems();
- this.read_Navmap_Once = false;
- }
- catch(errObj:Error)
- {
- trace(errObj.message);
- }
- }
-
- public function getHomeRefreshRate() : ArrayCollection
- {
- var _loc3_:Object = null;
- var _loc1_:ArrayCollection = new ArrayCollection();
- var _loc2_:int = 0;
- _loc2_ = 0;
- while(_loc2_ < this.homeViewRefreshRate.length)
- {
- _loc3_ = new Object();
- _loc3_.name = this.homeViewRefreshRate[_loc2_].name;
- _loc3_.time = this.homeViewRefreshRate[_loc2_].time;
- _loc1_.addItem(_loc3_);
- _loc2_++;
- }
- return _loc1_;
- }
-
- public function fault(param1:Object) : void
- {
- var _loc2_:Fault = null;
- var _loc3_:ApplicationError = null;
- if(this.read_Navmap_Once == true)
- {
- this.sendRequestAgain();
- }
- else
- {
- _loc2_ = FaultEvent(param1).fault;
- this.writeLog.error(_loc2_.faultDetail);
- _loc3_ = new ApplicationError(LogEventLevel.ERROR,ApplicationFacade.ERR_NUM_NAVMAP,ApplicationFacade.ERR_NAVMAP);
- sendNotification(ApplicationFacade.ERROR,_loc3_,ApplicationFacade.ERR_NAVMAP);
- }
- }
-
- private function stopTimer() : void
- {
- this.ticker.stop();
- }
-
- private function fetchItems(param1:ArrayCollection, param2:Array) : ArrayCollection
- {
- var _loc3_:Object = null;
- var _loc4_:Object = null;
- if(param1 == null && param2.length != 0)
- {
- return null;
- }
- if(param1 == null && param2.length == 0)
- {
- return null;
- }
- if(param1 != null && param2.length == 0)
- {
- return param1;
- }
- var _loc5_:Number = 0;
- while(_loc5_ < param1.length)
- {
- _loc4_ = param1.getItemAt(_loc5_);
- if(_loc4_.name == param2[0])
- {
- _loc3_ = _loc4_;
- break;
- }
- _loc5_++;
- }
- if(_loc3_ != null && Boolean(_loc3_.items))
- {
- param1 = _loc3_.items.item;
- }
- else
- {
- param1 = null;
- }
- param2.shift();
- return this.fetchItems(param1,param2);
- }
-
- private function sendRequest() : void
- {
- this.service.url = "http://shufflr.s3.amazonaws.com/app/config/pre_alpha/0_83/NavMap.xml";
- var _loc1_:Object = {};
- _loc1_["version"] = this.navMapVersion;
- var _loc2_:AsyncToken = this.service.send(_loc1_);
- _loc2_.addResponder(this);
- this.read_Navmap_Once = true;
- }
-
- private function onTick(param1:TimerEvent) : void
- {
- this.sendRequest();
- }
-
- public function loadMenuData(param1:String) : ArrayCollection
- {
- var _loc2_:ArrayCollection = null;
- var _loc5_:int = 0;
- var _loc6_:Object = null;
- var _loc3_:Array = param1.split("/");
- _loc3_.shift();
- var _loc4_:ArrayCollection = this.fetchItems(this.navMapData,_loc3_);
- if(_loc4_ != null)
- {
- _loc2_ = new ArrayCollection();
- _loc5_ = 0;
- _loc5_ = 0;
- while(_loc5_ < _loc4_.length)
- {
- _loc6_ = new Object();
- _loc6_.name = _loc4_[_loc5_].name;
- _loc6_.title = _loc4_[_loc5_].title;
- _loc6_.sf_id = _loc4_[_loc5_].sf_id;
- _loc6_.thumbnail = _loc4_[_loc5_].thumbnail;
- _loc6_.thumbnail.url = _loc4_[_loc5_].thumbnail.url;
- _loc6_.link = _loc4_[_loc5_].link;
- _loc6_.notification = _loc4_[_loc5_].notification;
- _loc6_.view = _loc4_[_loc5_].view;
- _loc6_.dataType = _loc4_[_loc5_].dataType;
- _loc6_.description = _loc4_[_loc5_].description;
- _loc2_.addItem(_loc6_);
- _loc5_++;
- }
- }
- return _loc2_;
- }
-
- private function createTimer() : void
- {
- this.ticker = new Timer(this._timerDuration);
- this.ticker.addEventListener(TimerEvent.TIMER,this.onTick);
- }
-
- private function set timerDuration(param1:uint) : void
- {
- this._timerDuration = Math.floor(param1 * 1000);
- this.resetTimer();
- }
-
- private function resetTimer() : void
- {
- if(this.ticker != null && this.ticker.running)
- {
- this.stopTimer();
- this.ticker.reset();
- this.ticker.removeEventListener(TimerEvent.TIMER,this.onTick);
- }
- this.createTimer();
- }
-
- public function loadMenuBarData() : ArrayCollection
- {
- var _loc3_:Object = null;
- var _loc1_:ArrayCollection = new ArrayCollection();
- var _loc2_:int = 0;
- _loc2_ = 0;
- while(_loc2_ < this.navMapData.length)
- {
- _loc3_ = new Object();
- _loc3_.name = this.navMapData[_loc2_].name;
- _loc3_.title = this.navMapData[_loc2_].title;
- _loc3_.thumbnail = this.navMapData[_loc2_].thumbnail;
- _loc3_.thumbnail.url = this.navMapData[_loc2_].thumbnail.url;
- _loc3_.link = this.navMapData[_loc2_].link;
- _loc3_.notification = this.navMapData[_loc2_].notification;
- _loc3_.view = this.navMapData[_loc2_].view;
- _loc3_.dataType = this.navMapData[_loc2_].dataType;
- _loc1_.addItem(_loc3_);
- _loc2_++;
- }
- return _loc1_;
- }
-
- private function sendRequestAgain() : void
- {
- this.service.url = "http://ec2-184-73-30-243.compute-1.amazonaws.com/shufflr.tv/app/config/pre_alpha/0_83/NavMap.xml";
- var _loc1_:Object = {};
- _loc1_["version"] = this.navMapVersion;
- var _loc2_:AsyncToken = this.service.send(_loc1_);
- _loc2_.addResponder(this);
- this.read_Navmap_Once = false;
- }
-
- private function loadMsg() : Object
- {
- var _loc1_:Object = new Object();
- _loc1_.msgId = this.msgData.msgId;
- _loc1_.msgText1 = this.msgData.msgText1;
- _loc1_.msgText2 = this.msgData.msgText2;
- return _loc1_;
- }
- }
- }
-
-