nexus site path corrected
[portal.git] / ecomp-portal-BE / war / static / fusion / webrtc / js / peerBroadcast.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 var output = $('#peerBroadcastSection');
21 var websocket = '';
22 var currentUser = '';
23 var remoteUser = '';
24 var f = '';
25
26
27
28 function socketSetup(initialPageVisit,_currentUser, _remoteUser, _f) {
29         
30     
31
32         if( true) {
33                   
34                 var href = window.location.href;
35             var hostPatt = new RegExp(window.location.host +"/[^/]*");
36             var res = hostPatt.exec(href);
37             var protocol = window.location.protocol.replace("http","ws");
38             
39             var signalingServerPath = protocol + "//" + res + "/opencontact";
40                   var wsUri = signalingServerPath;
41                   console.log("Connecting to " + wsUri);
42                   websocket = new WebSocket(wsUri);
43                   //localStorage.notifySocket = JSON.stringify(websocket);
44                   //window.top.notifySocket = websocket;
45                   
46                   currentUser = _currentUser;
47                   remoteUser = _remoteUser;
48                   f = socketSend;
49                  
50                   
51         }
52         
53         //var websocket = JSON.parse(localStorage.notifySocket || "{}") ;
54         if( websocket != null) {
55                 websocket.onopen = function(evt) { onOpen(evt); };
56                 websocket.onmessage = function(evt) { onMessage(evt); };
57                 websocket.onerror = function(evt) { onError(evt); };
58         
59         }
60         
61         //if(f != undefined)
62          // f();
63         
64         //window.top.notifySocket.send("");
65 }
66
67
68 function socketSend(currentUser, remoteUser) {
69         
70
71
72          websocket.send(JSON.stringify({
73          from: currentUser,
74          to: remoteUser
75      }));
76         
77         //window.top.notifySocket.send("");
78 }
79
80
81
82
83 function onOpen(evt) {
84     console.log("onOpen");
85     //writeToScreen("CONNECTED");
86     
87     if(f != undefined)
88                 f(currentUser, remoteUser);
89     
90 }
91
92 function onMessage(evt) {
93     if (typeof evt.data == "string") {
94         writeToScreen("RECEIVED (text): " + evt.data);
95         
96         confirm("You are being contacted by " + JSON.parse(evt.data).from + ". Please click on the online icon and then click view");
97
98         //if (confirm("You are being contacted by " + JSON.parse(evt.data).from )) {
99            
100             //}
101         
102     } else {
103         writeToScreen("RECEIVED (binary): " + evt.data);
104     }
105 }
106
107 function onError(evt) {
108     writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
109 }
110
111 function writeToScreen(message) {
112         console.log(message);
113 }