'use strict'; /** * @ngdoc directive * @name netvueApp.directive:NVPlayer * @description * # NVPlayer */ angular.module('netvueApp') .directive('nvPlayer', ['$cookieStore', '$rootScope', function ($cookieStore, $rootScope) { return { templateUrl: '/views/modals/player.html', restrict: 'EA', scope:{//isolate scope camera:'=camera' }, link: function postLink(scope, element, attrs) { scope.pid = attrs.pid; scope.playerw = attrs.playerw; //scope.playerh = attrs.playerh; scope.lang = $rootScope.lang; scope.username = $cookieStore.get('username'); scope.initWithCam = function(cf) { var t = cf.substring(0, 2); var s = parseInt(t, 10); if (s >= 7) { scope.playerVersion = 3; scope.playerh = scope.playerw * 9 / 16; } else { scope.playerVersion = 2; scope.playerh = scope.playerw * 3 / 4; } var tf = cf.substring(6, 10); var sf = parseInt(tf, 10); if (s < 8 && sf < 839) { scope.needFirmwareUpgrade = true; } else { scope.needFirmwareUpgrade = false; } if (scope.camera && scope.camera.OE) scope.playerstatus = scope.lang.pstatus[0]; else scope.playerstatus = scope.lang.pstatus[16]; scope.swfname = 'video/netvue' + scope.playerVersion + 'player.swf'; scope.showPlayback = false; console.log('player verision int=' + s + ' pver=' + scope.playerVersion); console.log(scope.camera); console.log('pid=' + scope.pid + ',w=' + scope.playerw + ",h=" + scope.playerh); } function getNetvuePlayer() { var playerName = scope.pid + '-' + scope.playerVersion; return element.find('.'+playerName)[0]; } // below are functions to communicate with flash player function setPlayerSize(w, h) { getNetvuePlayer().setPlayerSize(w, h); } function startPlayLive() { setPlayerSize(scope.playerw, scope.playerh); if (scope.playerVersion == 3) { getNetvuePlayer().playLive(scope.pid, scope.username, $cookieStore.get('passmd5'), scope.camera.DSN, scope.camera.KEY, scope.camera.DA.split(':')[0], scope.camera.DA.split(':')[1], scope.camera.KEY, scope.camera.SA.split(':')[0], scope.camera.SA.split(':')[1]); } else if (scope.playerVersion == 2) { getNetvuePlayer().playLive(scope.pid, scope.username, $cookieStore.get('passmd5'), scope.camera.DSN, scope.camera.SA.split(':')[0], scope.camera.SA.split(':')[1]); } } function startPlayRecord(longStart, longStop) { setPlayerSize(scope.playerw, scope.playerh); if (scope.playerVersion == 3) { getNetvuePlayer().playRecord(scope.pid, scope.username, $cookieStore.get('passmd5'), scope.camera.DSN, scope.camera.KEY, scope.camera.DA.split(':')[0], scope.camera.DA.split(':')[1], scope.camera.KEY, scope.camera.SA.split(':')[0], scope.camera.SA.split(':')[1], longStart.getTime(), longStop.getTime()); } else if (scope.playerVersion == 2) { getNetvuePlayer().playRecord(scope.pid, scope.username, $cookieStore.get('passmd5'), scope.camera.DSN, scope.camera.SA.split(':')[0], scope.camera.SA.split(':')[1], longStart.getTime(), longStop.getTime()); } } scope.stopPlay = function () { getNetvuePlayer().stopPlay(); }; scope.startPlay = function() { scope.playerstatus = scope.lang.pstatus[1]; //TODO debug remove it console.log('player version=' + getNetvuePlayer().getVersion()); //end if (scope.showPlayback) startPlayRecord(); else startPlayLive(); }; scope.playing = false; scope.togglePlay = function() { if (scope.playing) { scope.stopPlay(); } else { if (!scope.playerVersion) { return; } if (!scope.camera || !scope.camera.OE) return; if (scope.needFirmwareUpgrade) { //unsupport player scope.$emit('showInfoModal', { 'langcontent': 'unsupported_firmware_to_play' }); scope.playing = false; return; } scope.startPlay(); } scope.playing = !scope.playing; } if (scope.camera) { scope.initWithCam(scope.camera.CF); } else if (scope.cf) { scope.initWithCam(camera.CF); } else { scope.$on(scope.pid, function(event, action, camera){ console.log('on recv, actione=' + action); console.log(camera); if (action === 'start') { scope.camera = camera; scope.initWithCam(camera.CF); } else if (action === 'stop') { scope.stopPlay(); scope.playerVersion = undefined; scope.playerstatus = ''; } }); } scope.$on(scope.pid+'-playrecord', function(event, params){ console.log('recv playrecord'); console.log(params); startPlayRecord(params.stDate, params.edDate); }); scope.$on(scope.pid+'-updatestatus', function(event, params) { console.log('recv updatestatus'); console.log(params); scope.$apply(function() { var ps = ''; if (params.msg == 71) ps = scope.lang.pstatus[2]; else if (params.msg == 72) ps = scope.lang.pstatus[3]; else if (params.msg == 73) ps = scope.lang.pstatus[4]; else if (params.msg == 75) ps = scope.lang.pstatus[5]; else if (params.msg == 76) ps = scope.lang.pstatus[6]; else if (params.msg == 77) ps = scope.lang.pstatus[7]; else if (params.msg == 78) ps = scope.lang.pstatus[8]; else if (params.msg == -2) ps = scope.lang.pstatus[9]; else if (params.msg == -3) ps = scope.lang.pstatus[10]; else if (params.msg == -4) ps = scope.lang.pstatus[11]; else if (params.msg == -5) ps = scope.lang.pstatus[12]; else if (params.msg == -6) ps = scope.lang.pstatus[13]; else if (params.msg == -7) ps = scope.lang.pstatus[14]; else if (params.msg == 17) ps = scope.lang.pstatus[15]; else if (params.msg == 18) ps = scope.lang.pstatus[16]; else if (params.msg == 42) ps = scope.lang.pstatus[17]; scope.playerstatus = ps; }); }); //var flashbox = element.find('#flash_box')[0]; //flashbox.style.width = scope.playerw+'px'; //flashbox.style.height = scope.playerh+'px'; //element.find('#status')[0].style.top = 5+'px'; } }; }]);