2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
43 constructor(userProfileService,userbarUpdateService, $log, $rootScope , $interval,$scope,$timeout,dashboardService) {
46 this.userProfileService = userProfileService;
47 this.$rootScope = $rootScope;
48 $rootScope.isAdminPortalAdmin = false;
49 $scope.updateRate = 10000; //default online user bar refreshing rate
50 var intervalPromise = null;
51 $scope.myservice = userbarUpdateService;
52 $scope.userList=this.userLists;
59 function socketSetup(initialPageVisit,_currentUser, _remoteUser, _f) {
65 var href = window.location.href;
66 var hostPatt = new RegExp(window.location.host +"/[^/]*");
67 var res = hostPatt.exec(href);
68 var protocol = window.location.protocol.replace("http","ws");
69 var signalingServerPath = protocol + "//" + res + "/opencontact";
70 var wsUri = signalingServerPath;
71 console.log("Connecting to " + wsUri);
72 websocket = new WebSocket(wsUri);
73 //localStorage.notifySocket = JSON.stringify(websocket);
74 //window.top.notifySocket = websocket;
76 currentUser = _currentUser;
77 remoteUser = _remoteUser;
83 //var websocket = JSON.parse(localStorage.notifySocket || "{}") ;
84 if( websocket != null) {
85 websocket.onopen = function(evt) { onOpen(evt); };
86 websocket.onmessage = function(evt) { onMessage(evt); };
87 websocket.onerror = function(evt) { onError(evt); };
94 //window.top.notifySocket.send("");
97 function socketSend(currentUser, remoteUser) {
101 websocket.send(JSON.stringify({
106 //window.top.notifySocket.send("");
112 function onOpen(evt) {
113 console.log("onOpen");
114 //writeToScreen("CONNECTED");
117 f(currentUser, remoteUser);
121 function onMessage(evt) {
122 if (typeof evt.data == "string") {
123 writeToScreen("RECEIVED (text): " + evt.data);
124 var chatObject = JSON.parse(evt.data);
125 if(confirm("User " + chatObject.from + " is requesting a chat session with you. Please click ok to accept")== true) {
127 var url = userProfileService.getSortedUserIdCombination(chatObject.from, chatObject.to);
128 var win = window.open(url, '_blank');
136 writeToScreen("RECEIVED (binary): " + evt.data);
140 function onError(evt) {
141 writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
144 function writeToScreen(message) {
145 console.log(message);
148 function updateActiveUsers() {
149 // $log.debug('UserbarCtrl::updateActiveUsers: intervalPromise is ' + intervalPromise);
150 // $log.info("UserbarCtrl:updateActiveUsers invoked.")
151 // decrement the counter every time updateActiveUser is called;
152 userbarUpdateService.decrementRefreshCount();
153 userProfileService.getActiveUser()
156 $log.debug('UserbarCtrl::updateActiveUsers: service returned ' + JSON.stringify(res));
158 $log.error('UserbarCtrl::updateActiveUsers: failed to get active user');
161 $scope.userList = [];
162 // defend against huge list that should never happen.
164 if (res.length < maxItems)
165 maxItems = res.length;
166 for (var i=0; i < maxItems; i++) {
169 linkQ:userProfileService.getSortedUserIdCombination(userProfileService.userProfile.orgUserId , res[i])
171 $scope.userList.push(data);
174 $log.debug('UserbarCtrl::updateActiveUsers: user list ' + JSON.stringify($scope.userList));
177 $log.error('UserbarCtrl::updateActiveUsers: caught exception: ' + err);
178 // Do not show stale result
179 $scope.userList = [];
182 var footerOff = $('#online-userbar').offset().top;
183 var headOff = $('#footer').offset().top;
184 var userbarHeight= parseInt($(".online-user-container").css('height'),10);
185 var defaultOffSet = 45;
186 $(".online-user-container").css({
187 "height" : headOff - footerOff-defaultOffSet
192 $scope.start = function(rate) {
193 // stops any running interval to avoid two intervals running at the same time
195 // store the interval promise
196 intervalPromise = $interval(updateActiveUsers, rate);
199 $scope.stop = function() {
200 if (intervalPromise != null) {
201 $interval.cancel(intervalPromise);
202 intervalPromise = null;
206 $scope.$watch('myservice.getRefreshCount()', function (newVal,oldVal) {
207 //$log.info("refresh "+$scope.myservice.refreshCount + " more time(s)");
209 // $log.info("UserbarCtrl: stopped refreshing online users");
211 } else if (newVal== $scope.myservice.maxCount){
212 // $log.info("UserbarCtrl: start refreshing online users at every "+($scope.updateRate/1000)+" sec");
213 // initial update of activate users
215 $scope.start($scope.updateRate);
219 // Load the active users.
220 //updateActiveUsers();
221 dashboardService.getOnlineUserUpdateRate().then(res=> {
222 // $log.info('getting Online User Update Rate init***********************', res);
223 if (res == null || res.response == null) {
224 $log.error('UserbarCtlr: failed to get online user update rate or duration, check system.properties file.');
226 // $log.debug('UserbarCtlr: got online User Update Rate ' + res.response);
227 var rate = parseInt(res.response.onlineUserUpdateRate);
228 // var updateRate = parseInt(res.response.onlineUserUpdateRate);
229 var duration = parseInt(res.response.onlineUserUpdateDuration);
230 userbarUpdateService.setMaxRefreshCount(parseInt(duration/rate)+1);
231 userbarUpdateService.setRefreshCount(userbarUpdateService.maxCount);
232 // $scope.refreshCount = userbarUpdateService.getRefreshCount();
234 if (rate != NaN && duration != NaN) {
235 // $log.debug('UserbarCtlr: scheduling function at interval ' + millis);
236 $scope.updateRate=rate;
237 $scope.start($scope.updateRate);
241 $log.error('UserbarCtlr: getOnlineUserUpdateRate() failed: ' + err);
245 UserbarCtrl.$inject = ['userProfileService', 'userbarUpdateService', '$log', '$rootScope','$interval','$scope','$timeout','dashboardService'];
246 angular.module('ecompApp').controller('UserbarCtrl', UserbarCtrl);