a800c009c5dd002edf124db7bc1cb6c5e2a873bb
[portal/sdk.git] /
1
2
3 appDS2.controller('collaborationControllerDS2', function ($scope,$http, $modal) { 
4         console.log("modal", $modal);
5         var popupModalService;
6                    
7                 });
8         
9
10         $(document).ready(function () {
11
12                 // OUTER-LAYOUT
13                 panelLayout = $('body').layout({
14                         center__paneSelector:   ".outer-center"
15                 ,       west__paneSelector:             ".outer-west"
16                 ,       east__paneSelector:             ".outer-east"
17                 //,     west__size:                             800
18                 //,     east__size:                             125
19                 ,       spacing_open:                   8  // ALL panes
20                 ,       spacing_closed:                 12 // ALL panes
21         
22                 ,       center__childOptions: {
23                         center__paneSelector:   ".inner-center"
24                 ,       west__paneSelector:             ".inner-west"
25                 ,       east__paneSelector:             ".inner-east"
26                 ,       west__size:                             75
27                 ,       east__size:                             75
28                 ,       spacing_open:                   8  // ALL panes
29                 ,       spacing_closed:                 8  // ALL panes
30                 ,       west__spacing_closed:   12
31                 ,       east__spacing_closed:   12
32                 }
33
34                  
35
36                 
37                 });
38                 
39         
40                 function initializeConnections() {
41                 
42                 var channelId = null;
43                         channelId = location.href.replace(/\/|:|#|%|\.|\[|\]/g, '');
44                         var videoChannelId = channelId.concat("video");
45                         var screenChannelId = channelId.concat("screen");
46                         
47                         videoConnection = new RTCMultiConnection(videoChannelId);
48                         screenConnection = new RTCMultiConnection(screenChannelId);
49                         
50                         configConnection(videoConnection,true,true,false,true,false);
51                     configConnection(screenConnection,false,false,true,false,true);
52                 
53             };
54             
55             function configConnection(_connection, _audio, _video, _screen, _data, _oneway) {
56                  _connection.session = {
57                          audio:     _audio, // by default, it is true
58                          video:     _video, // by default, it is true
59                          screen:    _screen,
60                          data:      _data,
61                          oneway:    _oneway,
62                          broadcast: false
63                     };
64                  
65                  _connection.direction = "one-to-one";
66                  
67                  if( _data == true ) {
68                  _connection.onmessage = function(e) {
69                      appendDIV(e.data);
70
71                      console.debug(e.userid, 'posted', e.data);
72                      console.log('latency:', e.latency, 'ms');
73                  };
74                  }
75             
76              
77             }; 
78             
79             function assignStreamToDom() {
80                 
81                 
82                 screenConnection.screenbody = document.querySelector('.screenContainer1'); 
83                 screenConnection.videobody = document.querySelector('.videoContainer2'); 
84                 
85                 videoConnection.screenbody = document.querySelector('.screenContainer2'); 
86                 videoConnection.videobody = document.querySelector('.videoContainer1'); 
87             };
88             
89                 function maximizeLayout() {
90                 
91                         // open the panes and maximize the window.
92                      top.window.resizeTo(screen.availWidth,screen.availHeight);
93                      panelLayout.open('west');
94                      // panelLayout.open('south'); is not working due to state initialization problem; debug to find out. so replacing the call with work around below - hack.
95                  $(".ui-layout-toggler-south-closed").first().click();
96                      
97                  };
98             
99            function minimizeLayout() {
100                 
101                         // close the panes and minimize the window.
102                      top.window.resizeTo(screen.availWidth - 2*screen.availWidth/3, screen.availHeight - screen.availHeight/2);
103                      panelLayout.close('west');
104                      // panelLayout.close('south'); is not working due to state initialization problem; debug to find out. so replacing the call with work around below - hack.
105                  $(".ui-layout-toggler-south-opened").first().click();
106             };
107             
108             function emptyContainers() {
109                  $('.screenContainer1').empty(); 
110                      $('.videoContainer2').empty(); 
111                         
112                      $('.screenContainer2').empty();  
113                      $('.videoContainer1').empty(); 
114             };
115             
116             function appendDIV(div, parent) {
117                 if (typeof div === 'string') {
118                     var content = div;
119                     div = document.createElement('div');
120                     div.innerHTML =  content;
121                   };
122                   
123                   var chatOutput = document.getElementById('chat-output'),
124                     fileProgress = document.getElementById('file-progress');
125             
126                   if (!parent) chatOutput.insertBefore(div, chatOutput.firstChild);
127                     else fileProgress.insertBefore(div, fileProgress.firstChild);
128
129                     div.tabIndex = 0;
130                     $('#chat-input').focus();
131              };
132              
133              function confirmClose() {
134                  var message = "Are you sure you want to close the session?";
135                  
136                 /* if(popupModalService != undefined) {
137                          popupModalService.popupConfirmWin("Confirm", message, function(){ location.reload();});
138                  }
139                  
140                  else */
141                  if (confirm(message) == true) {
142                              location.reload();
143                             //window.opener.location.reload(); // go to the parent window
144                                 //close();
145                     } else {
146                         // do nothing
147                     }
148                  
149              };
150              
151              function notifyOthers() {
152                  
153                 // var websocket = localStorage.getItem('notifySocket');
154                  //if( websocket != null) {
155                          // handling websocket peer broadcast session 
156                          var currentUser = "${sessionScope.user.sbcid}";
157                          var initialPageVisit = "${sessionScope.initialPageVisit}";
158                          var remoteUser = '';
159                          
160                          var userList = location.search.split('chat_id=')[1].split('-');
161                          for(var i=0;i<userList.length;i++) {
162                                  if(userList[i] !== currentUser) {
163                                          remoteUser = userList[i];
164                                          break;
165                                  }
166                          }
167                         
168                         socketSetup(initialPageVisit, currentUser, remoteUser,"socketSend");
169                         
170                          
171                          
172                          
173                 
174                  
175              };
176              
177              function makeChatVisible() {
178                  
179                  $('#chat-input').css("visibility", 'visible');          
180              };
181             
182             
183             
184              /* on click button enabled*/
185              window.onload = function () {
186              document.getElementById('share-screen').onclick = function() {
187             
188              emptyContainers();  
189              videoConnection.close();
190                  screenConnection.close();       
191              
192              maximizeLayout();
193              emptyContainers();
194              makeChatVisible();
195              
196              videoConnection.open();
197              screenConnection.open();
198              
199              
200              notifyOthers();
201              
202             
203             
204                 };
205              };
206
207                  document.getElementById('stop-share-screen').onclick = function() {
208                  
209                  emptyContainers();
210                  
211                  videoConnection.close();
212                  screenConnection.close();
213                  
214                  confirmClose();
215                  
216                 };
217
218                  document.getElementById('view-screen').onclick = function() {
219                 
220                  maximizeLayout();
221                  emptyContainers();
222                  makeChatVisible();
223                  
224                  // timeout is required for the sharing to properly work
225                  setTimeout(function() { 
226                          screenConnection.connect();
227                  },2000);
228                  setTimeout(function() { 
229                          videoConnection.connect();
230                  },1000);
231                 
232                  
233                 };
234                 
235                 document.getElementById('chat-input').onkeypress = function(e) {
236                 if (e.keyCode !== 13 || !this.value) return;
237                 var message = "<b>${model.name}</b>: " + this.value;
238                 appendDIV(message);
239
240                 // sending text message
241                 videoConnection.send(message);
242
243                 this.value = '';
244             };
245             
246             /*
247             document.getElementById('file').onchange = function() {
248                 videoConnection.send(this.files[0]);
249         };
250                 */
251                 
252                 
253                 //document.querySelector('.screenContainerPane').appenChild(document.querySelector('.screenContainer'));
254                 //document.querySelector('.videoContainerPane').appendChild(document.querySelector('.videoContainer'));
255                 
256                 //panelLayout.bindButton($('#share-screen'), 'open', 'outer-west');
257                 //panelLayout.bindButton($('#stop-share-screen'), 'close', 'outer-west');
258                 var videoConnection = null, screenConnection = null;
259                 initializeConnections();
260                 assignStreamToDom();
261                 
262                 // start the share
263                 //document.getElementById('share-screen').click();
264                 //
265                 });
266