diff --git a/htdocs/css/openwebrx.css b/htdocs/css/openwebrx.css
index a253c644..15f4d8d2 100644
--- a/htdocs/css/openwebrx.css
+++ b/htdocs/css/openwebrx.css
@@ -314,7 +314,7 @@ input[type=range]:disabled {
width: 100%;
}
-#openwebrx-messages .nickname {
+#openwebrx-messages .chatname {
color: #bbb;
font-weight: bold;
}
diff --git a/htdocs/css/themes.css b/htdocs/css/themes.css
index 4385cd21..eb20a6a8 100644
--- a/htdocs/css/themes.css
+++ b/htdocs/css/themes.css
@@ -136,13 +136,3 @@ body.has-theme #openwebrx-digimode-content-container .gradient {
box-shadow: 0px 10px 10px inset var(--theme-color2);
background: initial;
}
-
-/* these need more work */
-body.has-theme input[type=range] {
- /* --track-background: #001727; */
-}
-
-body.has-theme input[type=range]::-webkit-slider-runnable-track,
-body.has-theme input[type=range]:focus::-webkit-slider-runnable-track {
- /* background: #001727; */
-}
diff --git a/htdocs/index.html b/htdocs/index.html
index 1e37404a..9d5de04b 100644
--- a/htdocs/index.html
+++ b/htdocs/index.html
@@ -178,9 +178,9 @@
diff --git a/htdocs/lib/Chat.js b/htdocs/lib/Chat.js
new file mode 100644
index 00000000..a58b10c7
--- /dev/null
+++ b/htdocs/lib/Chat.js
@@ -0,0 +1,57 @@
+//
+// Built-in Chat
+//
+
+function Chat() {}
+
+// We start with these values
+Chat.nickname = '';
+
+// Load chat settings from local storage.
+Chat.loadSettings = function() {
+ this.setNickname(LS.has('chatname')? LS.loadStr('chatname') : '');
+};
+
+// Set chat nickname.
+Chat.setNickname = function(nickname) {
+ if (this.nickname !== nickname) {
+ this.nickname = nickname;
+ LS.save('chatname', nickname);
+ $('#openwebrx-chat-name').val(nickname);
+ }
+};
+
+Chat.recvMessage = function(nickname, text, color = 'white') {
+ // Show chat panel
+ toggle_panel('openwebrx-panel-log', true);
+
+ divlog(
+ '['
+ + Utils.htmlEscape(nickname) + ']: '
+ + '' + Utils.htmlEscape(text)
+ + ''
+ );
+};
+
+Chat.sendMessage = function(text, nickname = '') {
+ ws.send(JSON.stringify({
+ 'type': 'sendmessage', 'name': nickname, 'text': text
+ }));
+};
+
+// Collect nick and message from controls and send message.
+Chat.send = function() {
+ this.setNickname($('#openwebrx-chat-name').val().trim());
+
+ var msg = $('#openwebrx-chat-message').val().trim();
+ if (msg.length > 0) this.sendMessage(msg, this.nickname);
+ $('#openwebrx-chat-message').val('');
+};
+
+// Attach events to chat controls.
+Chat.keyPress = function(event) {
+ if (event.key === 'Enter') {
+ event.preventDefault();
+ this.send();
+ }
+};
diff --git a/htdocs/lib/UI.js b/htdocs/lib/UI.js
index 5a99541d..237fcbc4 100644
--- a/htdocs/lib/UI.js
+++ b/htdocs/lib/UI.js
@@ -14,7 +14,6 @@ UI.nrThreshold = 0;
UI.nrEnabled = false;
UI.wheelSwap = false;
UI.spectrum = false;
-UI.nickname = '';
// Foldable UI sections and their initial states
UI.sections = {
@@ -28,7 +27,6 @@ UI.sections = {
UI.loadSettings = function() {
this.setTheme(LS.has('ui_theme')? LS.loadStr('ui_theme') : 'default');
this.setOpacity(LS.has('ui_opacity')? LS.loadInt('ui_opacity') : 100);
- this.setNickname(LS.has('nickname')? LS.loadStr('nickname') : '');
this.toggleFrame(LS.has('ui_frame')? LS.loadBool('ui_frame') : false);
this.toggleWheelSwap(LS.has('ui_wheel')? LS.loadBool('ui_wheel') : false);
this.toggleSpectrum(LS.has('ui_spectrum')? LS.loadBool('ui_spectrum') : false);
@@ -239,51 +237,3 @@ UI.setTheme = function(theme) {
$('body').addClass('has-theme');
}
};
-
-//
-// Chat
-//
-
-// Set chat nickname.
-UI.setNickname = function(nickname) {
- if (this.nickname !== nickname) {
- this.nickname = nickname;
- LS.save('nickname', nickname);
- $('#chatNickname').val(nickname);
- }
-};
-
-UI.recvChatMessage = function(nickname, text, color = 'white') {
- // Show chat panel
- toggle_panel('openwebrx-panel-log', true);
-
- divlog(
- '['
- + Utils.htmlEscape(nickname) + ']: '
- + '' + Utils.htmlEscape(text)
- + ''
- );
-};
-
-UI.sendChatMessage = function(text, nickname = '') {
- ws.send(JSON.stringify({
- 'type': 'sendmessage', 'name': nickname, 'text': text
- }));
-};
-
-// Collect nick and message from controls and send message.
-UI.chatSend = function() {
- this.setNickname($('#chatNickname').val().trim());
-
- var msg = $('#chatMessage').val().trim();
- if (msg.length > 0) this.sendChatMessage(msg, this.nickname);
- $('#chatMessage').val('');
-};
-
-// Attach events to chat controls.
-UI.chatKeyPress = function(event) {
- if (event.key === 'Enter') {
- event.preventDefault();
- this.chatSend();
- }
-};
diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js
index 945e6f31..296153a0 100644
--- a/htdocs/openwebrx.js
+++ b/htdocs/openwebrx.js
@@ -1168,7 +1168,7 @@ function on_ws_recv(evt) {
divlog(json['value'], true);
break;
case 'chat_message':
- UI.recvChatMessage(json['sender'], json['text'], json['color']);
+ Chat.recvMessage(json['name'], json['text'], json['color']);
break;
case 'backoff':
divlog("Server is currently busy: " + json['reason'], true);
@@ -1326,6 +1326,7 @@ function onAudioStart(apiType){
// Load user interface settings from local storage
UI.loadSettings();
+ Chat.loadSettings();
}
var reconnect_timeout = false;
diff --git a/owrx/client.py b/owrx/client.py
index 8e1ef813..49765d8d 100644
--- a/owrx/client.py
+++ b/owrx/client.py
@@ -71,9 +71,15 @@ class ClientRegistry(object):
# Broadcast chat message to all connected clients.
def broadcastChatMessage(self, client, text: str, name: str = None):
- # Names can only include alphanumerics
if name is not None:
+ # Names can only include alphanumerics
name = re.sub("\W+", "", name)
+ # Cannot have duplicate names
+ if client not in self.chat or name != self.chat[client]["name"]:
+ for c in self.chat:
+ if name == self.chat[c]["name"]:
+ name = None
+ break
# If we have seen this client chatting before...
if client in self.chat:
# Rename existing client as needed, keep color
diff --git a/owrx/connection.py b/owrx/connection.py
index 375bfd04..0144f24f 100644
--- a/owrx/connection.py
+++ b/owrx/connection.py
@@ -491,11 +491,10 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
def write_backoff_message(self, reason):
self.send({"type": "backoff", "reason": reason})
- def write_chat_message(self, sender, text, color = "white"):
- logger.debug("Sending {0}".format({"type": "chat_message", "sender": sender, "text": text}))
+ def write_chat_message(self, name, text, color = "white"):
self.send({
"type": "chat_message",
- "sender": sender,
+ "name": name,
"text": text,
"color": color
})
diff --git a/owrx/controllers/assets.py b/owrx/controllers/assets.py
index 37b36880..055740f3 100644
--- a/owrx/controllers/assets.py
+++ b/owrx/controllers/assets.py
@@ -141,6 +141,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController):
"lib/Scanner.js",
"lib/Utils.js",
"lib/Clock.js",
+ "lib/Chat.js",
"lib/UI.js",
],
"map-google.js": [