2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
21 var output = $('#peerBroadcastSection');
28 function setPopupService(_popupService) {
29 popupService = _popupService;
32 function socketSetup(initialPageVisit,_currentUser, _remoteUser, _f) {
38 var href = window.location.href;
39 var hostPatt = new RegExp(window.location.host +"/[^/]*");
40 var res = hostPatt.exec(href);
41 var protocol = window.location.protocol.replace("http","ws");
43 var signalingServerPath = protocol + "//" + res + "/contact";
44 var wsUri = signalingServerPath;
45 console.log("Connecting to " + wsUri);
46 websocket = new WebSocket(wsUri);
47 //localStorage.notifySocket = JSON.stringify(websocket);
48 //window.top.notifySocket = websocket;
50 currentUser = _currentUser;
51 remoteUser = _remoteUser;
57 //var websocket = JSON.parse(localStorage.notifySocket || "{}") ;
58 if( websocket != null) {
59 websocket.onopen = function(evt) { onOpen(evt); };
60 websocket.onmessage = function(evt) { onMessage(evt); };
61 websocket.onerror = function(evt) { onError(evt); };
68 //window.top.notifySocket.send("");
72 function socketSend(currentUser, remoteUser) {
76 websocket.send(JSON.stringify({
81 //window.top.notifySocket.send("");
87 function onOpen(evt) {
88 console.log("onOpen");
89 //writeToScreen("CONNECTED");
92 f(currentUser, remoteUser);
96 function onMessage(evt) {
97 if (typeof evt.data == "string") {
98 writeToScreen("RECEIVED (text): " + evt.data);
100 if(popupService != undefined) {
101 popupService.showMessage("Call Request","You are being contacted by " + JSON.parse(evt.data).from + ". Please click on the online icon and then click view");
104 //if (confirm("You are being contacted by " + JSON.parse(evt.data).from )) {
109 writeToScreen("RECEIVED (binary): " + evt.data);
113 function onError(evt) {
114 writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
117 function writeToScreen(message) {
118 var pre = document.createElement("p");
119 pre.style.wordWrap = "break-word";
120 pre.innerHTML = message;