2* @fileoverview Dynamic interface to MeshCentral2
3* @author Ylian Saint-Hilaire
7var createMeshConnection = function (connectionId) {
9 obj.connectionId = connectionId;
12 obj.onStateChanged = null;
15 obj.connect = function () {
17 obj.websocket = new WebSocket(window.location.protocol.replace('http', 'ws') + '//' + window.location.host + '/meshrelay.ashx?id=' + obj.connectionId);
18 obj.websocket.binaryType = "arraybuffer";
19 obj.websocket.onopen = function (e) { console.log('WebSocket Connected', e); };
20 obj.websocket.onmessage = function (e) {
21 console.log('WebSocket Message', e);
22 if ((obj.state = 1) && (e.data == 'c')) {
24 if (obj.onStateChanged) { onStateChanged(obj, 2); }
25 console.log('WebSocket Peer Connection', e);
28 if (obj.onData != null) { obj.onData(obj, e.data); }
31 obj.websocket.onclose = function (e) {
32 console.log('WebSocket Closed', e);
34 if (obj.onStateChanged) { onStateChanged(obj, 0); }
36 obj.websocket.onerror = function (e) { console.log('WebSocket Error', e); };
38 if (obj.onStateChanged) { onStateChanged(obj, 1); }
43 obj.send = function (data) {
44 if ((obj.state == 2) && (obj.websocket != null)) { obj.websocket.send(data); }