mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
Improved push messaging support.
This commit is contained in:
parent
8a81bd30f8
commit
0658d6e5a5
4 changed files with 162 additions and 20 deletions
|
@ -823,9 +823,10 @@
|
|||
</td>
|
||||
<td> </td>
|
||||
<td id="p15outputselecttd">
|
||||
<select id=p15outputselect>
|
||||
<option value=1>Agent</option>
|
||||
<option value=2>MQTT</option>
|
||||
<select id=p15outputselect onchange="setupConsole()">
|
||||
<option id="p15outputselect1" value=1>Agent</option>
|
||||
<option id="p15outputselect3" value=3>Push</option>
|
||||
<option id="p15outputselect2" value=2>MQTT</option>
|
||||
</select>
|
||||
</td>
|
||||
<td style="width:1%"><input id="id_p15consoleClear" type="button" class="bottombutton" value="Clear" onclick="p15consoleClear()" /></td>
|
||||
|
@ -5976,7 +5977,7 @@
|
|||
x += '<input type=button value="' + "Log Event" + '" title="' + "Write an event for this device" + '" onclick=writeDeviceEvent("' + encodeURIComponentEx(node._id) + '") />';
|
||||
if ((meshrights & 8) && ((connectivity & 1) || (node.pmt == 1))) { x += '<input type=button value="' + "Message" + '" title="' + "Display a text message on the remote device" + '" onclick=deviceMessageFunction() />'; }
|
||||
//if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += '<input type=button value=Toast title="' + "Display a text message of the remote device" + '" onclick=deviceToastFunction() />'; }
|
||||
if ((connectivity & 1) && (meshrights & 8) && (node.agent.id == 14)) { x += '<input type=button value="' + "Chat" + '" title="' + "Open chat window to this computer" + '" onclick=deviceChat(event) />'; }
|
||||
if ((meshrights & 8) && (connectivity & 1) || (node.pmt == 1)) { x += '<input type=button value="' + "Chat" + '" title="' + "Open chat window to this computer" + '" onclick=deviceChat(event) />'; }
|
||||
if ((serverinfo.guestdevicesharing !== false) && (node.agent != null) && (node.agent.caps & 3) && (connectivity & 1) && (meshrights & 0x80008) && ((meshrights == 0xFFFFFFFF) || ((meshrights & 0x1000) == 0))) { x += '<input type=button value="' + "Share" + '" title="' + "Create a link to share this device with a guest" + '" onclick=showShareDevice() />'; }
|
||||
|
||||
// Custom UI
|
||||
|
@ -6302,6 +6303,7 @@
|
|||
if (xxdialogMode) return;
|
||||
var url = '/messenger?id=meshmessenger/' + encodeURIComponentEx(currentNode._id) + '/' + encodeURIComponentEx(userinfo._id) + '&title=' + currentNode.name;
|
||||
if ((authCookie != null) && (authCookie != '')) { url += '&auth=' + authCookie; }
|
||||
if (currentNode.pmt == 1) { url += '&pmt=1'; } // Push messaging is possible for this device
|
||||
if (e && (e.shiftKey == true)) {
|
||||
safeNewWindow(url, 'meshmessenger:' + currentNode._id);
|
||||
} else {
|
||||
|
@ -9333,9 +9335,20 @@
|
|||
var onlineText = ((consoleNode.conn & 1) != 0) ? "Agent is online" : "Agent is offline"
|
||||
if ((consoleNode.conn & 16) != 0) { onlineText += ", MQTT is online" }
|
||||
QH('p15statetext', onlineText);
|
||||
QE('p15consoleText', online);
|
||||
QE('p15uploadCore', ((consoleNode.conn & 1) != 0));
|
||||
QV('p15outputselecttd', (consoleNode.conn & 17) == 17);
|
||||
QV('p15outputselecttd', ((consoleNode.conn & 16) != 0) || (currentNode.pmt == 1));
|
||||
QV('p15outputselect2', ((consoleNode.conn & 16) != 0)); // MQTT channel
|
||||
QV('p15outputselect3', (currentNode.pmt == 1)); // Push Notification channel
|
||||
|
||||
var c = Q('p15outputselect').value;
|
||||
if (((consoleNode.conn & 16) == 0) && (c == 2)) { c = 1; Q('p15outputselect').value = 1; }
|
||||
if ((currentNode.pmt != 1) && (c == 3)) { c = 1; Q('p15outputselect').value = 1; }
|
||||
|
||||
var active = false;
|
||||
if (((consoleNode.conn & 1) != 0) && (c == 1)) { active = true; } // Agent
|
||||
if (((consoleNode.conn & 16) != 0) && (c == 2)) { active = true; } // MQTT
|
||||
if ((consoleNode.pmt == 1) && (c == 3)) { active = true; } // Push
|
||||
QE('p15consoleText', active);
|
||||
} else {
|
||||
QH('p15statetext', "Access Denied");
|
||||
QE('p15consoleText', false);
|
||||
|
@ -9368,12 +9381,17 @@
|
|||
consoleServerText += t;
|
||||
meshserver.send({ action: 'serverconsole', value: v });
|
||||
} else {
|
||||
if (((consoleNode.conn & 16) != 0) && ((Q('p15outputselect').value == 2) || ((consoleNode.conn & 1) == 0))) {
|
||||
if (((consoleNode.conn & 16) != 0) && (Q('p15outputselect').value == 2)) {
|
||||
// Send the command to MQTT
|
||||
t = '<div style=color:orange>' + "MQTT" + '> ' + EscapeHtml(v) + '<br/></div>';
|
||||
consoleNode.consoleText += t;
|
||||
meshserver.send({ action: 'sendmqttmsg', topic: 'console', nodeids: [ consoleNode._id ], msg: v });
|
||||
} else {
|
||||
} else if ((consoleNode.pmt == 1) && (Q('p15outputselect').value == 3)) {
|
||||
// Send the command using push notification
|
||||
t = '<div style=color:violet>' + "PUSH" + '> ' + EscapeHtml(v) + '<br/></div>';
|
||||
consoleNode.consoleText += t;
|
||||
meshserver.send({ action: 'pushconsole', nodeid: consoleNode._id, console: v });
|
||||
} else if ((consoleNode.conn & 1) == 0) {
|
||||
// Send the command to the mesh agent
|
||||
consoleNode.consoleText += t;
|
||||
meshserver.send({ action: 'msg', type: 'console', nodeid: consoleNode._id, value: v });
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
var args = XparseUriArgs();
|
||||
if (args.key && (isAlphaNumeric(args.key) == false)) { delete args.key; }
|
||||
if (args.locale && (isAlphaNumeric(args.locale) == false)) { delete args.locale; }
|
||||
var pushMessaging = (args.pmt == 1);
|
||||
|
||||
// WebRTC sessions and data, audio and video channels
|
||||
var random = Math.random(); // Selected random, larger value initiates WebRTC.
|
||||
|
@ -144,7 +145,7 @@
|
|||
document.onkeypress = function ondockeypress(e) {
|
||||
if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
|
||||
if (notification != null) { notification.close(); notification = null; }
|
||||
if (state == 2) {
|
||||
if ((state == 2) || pushMessaging) {
|
||||
if (e.keyCode == 13) {
|
||||
// Return
|
||||
xsend(e);
|
||||
|
@ -229,7 +230,7 @@
|
|||
chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Local" + '> ' + outtext + '\r\n');
|
||||
QA('xmsg', '<div style="clear:both"><div class="localBubble">' + EscapeHtml(outtext) + '</div><div></div></div>');
|
||||
Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
|
||||
send({ action: 'chat', msg: outtext });
|
||||
if ((state == 2) || pushMessaging) { send({ action: 'chat', msg: outtext }); }
|
||||
Q('xouttext').value = '';
|
||||
Q('xouttext').focus();
|
||||
}
|
||||
|
@ -239,9 +240,9 @@
|
|||
|
||||
// Update user controls
|
||||
function updateControls() {
|
||||
QE('sendButton', state == 2);
|
||||
QE('clearButton', state == 2);
|
||||
QE('xouttext', state == 2);
|
||||
QE('sendButton', (state == 2) || pushMessaging);
|
||||
QE('clearButton', (state == 2) || pushMessaging);
|
||||
QE('xouttext', (state == 2) || pushMessaging);
|
||||
QV('fileButton', state == 2);
|
||||
QV('camButton', webchannel && webchannel.ok && !localStream && (userMediaSupport == 2));
|
||||
QV('micButton', webchannel && webchannel.ok && !localStream && (userMediaSupport > 0));
|
||||
|
@ -348,7 +349,7 @@
|
|||
|
||||
// Send data over the current transport (WebRTC first)
|
||||
function send(data) {
|
||||
if (state != 2) return; // If not in connected state, ignore this.
|
||||
if ((state != 2) && (pushMessaging == false)) return; // If not in connected state, ignore this.
|
||||
if (typeof data == 'object') { data = JSON.stringify(data); } // If this is an object, convert it to a string.
|
||||
if (webchannel && webchannel.ok) { if (webchannel.xoutBuffer != null) { webchannel.xoutBuffer.push(data); } else { webchannel.send(data); } } // If WebRTC channel is possible, use it or hold until we can use it.
|
||||
else { if (socket != null) { try { socket.send(data); } catch (ex) { } } } // If a websocket channel is present, use that.
|
||||
|
@ -372,6 +373,12 @@
|
|||
//console.log('RECV', data);
|
||||
switch (data.action) {
|
||||
case 'chat': { displayRemote(data.msg); break; } // Incoming chat message.
|
||||
case 'ctrl': {
|
||||
if (data.value == 1) { displayControl("Sent as push notification."); }
|
||||
else if (data.value == 2) { displayControl("Push notification failed."); }
|
||||
if (data.msg != null) { displayControl(msg); }
|
||||
break;
|
||||
}
|
||||
case 'random': { if (random > data.random) { startWebRTC(0, true); } break; } // If we have a larger random value, we start WebRTC.
|
||||
case 'webRtcSdp': { if (!webrtcSessions[webRtcIdSwitch(data.id)]) { startWebRTC(webRtcIdSwitch(data.id), false); } webRtcHandleOffer(webRtcIdSwitch(data.id), data.sdp); break; } // Remote WebRTC offer or answer.
|
||||
case 'webRtcIce': { var webrtc = webrtcSessions[webRtcIdSwitch(data.id)]; if (webrtc) { try { webrtc.addIceCandidate(new RTCIceCandidate(data.ice)); } catch (ex) { } } break; } // Remote ICE candidate
|
||||
|
@ -683,7 +690,7 @@
|
|||
sendws({ action: 'random', random: random }); // Send a random number. Higher number starts the WebRTC session.
|
||||
return;
|
||||
}
|
||||
if (state == 2) { processMessage(msg.data, 1); }
|
||||
if (msg.data[0] == '{') { processMessage(msg.data, 1); }
|
||||
}
|
||||
} else {
|
||||
displayControl("Error: No connection key specified.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue