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 * ================================================================================
20 var output = $('#peerBroadcastSection');
28 function socketSetup(initialPageVisit,_currentUser, _remoteUser, _f) {
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");
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;
46 currentUser = _currentUser;
47 remoteUser = _remoteUser;
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); };
64 //window.top.notifySocket.send("");
68 function socketSend(currentUser, remoteUser) {
72 websocket.send(JSON.stringify({
77 //window.top.notifySocket.send("");
83 function onOpen(evt) {
84 console.log("onOpen");
85 //writeToScreen("CONNECTED");
88 f(currentUser, remoteUser);
92 function onMessage(evt) {
93 if (typeof evt.data == "string") {
94 writeToScreen("RECEIVED (text): " + evt.data);
96 confirm("You are being contacted by " + JSON.parse(evt.data).from + ". Please click on the online icon and then click view");
98 //if (confirm("You are being contacted by " + JSON.parse(evt.data).from )) {
103 writeToScreen("RECEIVED (binary): " + evt.data);
107 function onError(evt) {
108 writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
111 function writeToScreen(message) {
112 console.log(message);