bstkchat 2.3.0__tar.gz → 2.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bstkchat-2.3.0 → bstkchat-2.4.0}/PKG-INFO +4 -2
- {bstkchat-2.3.0 → bstkchat-2.4.0}/README.md +3 -1
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat/cli.py +246 -17
- bstkchat-2.4.0/bstkchat/web.py +256 -0
- bstkchat-2.4.0/bstkchat/web_ui.html +589 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat.egg-info/PKG-INFO +4 -2
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat.egg-info/SOURCES.txt +4 -1
- {bstkchat-2.3.0 → bstkchat-2.4.0}/pyproject.toml +5 -1
- {bstkchat-2.3.0 → bstkchat-2.4.0}/setup.py +2 -1
- bstkchat-2.4.0/tests/test_web.py +71 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat/__init__.py +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat/chain.py +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat/config.py +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat/crypto.py +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat.egg-info/dependency_links.txt +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat.egg-info/entry_points.txt +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat.egg-info/requires.txt +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/bstkchat.egg-info/top_level.txt +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/setup.cfg +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/tests/test_chain.py +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/tests/test_cli.py +0 -0
- {bstkchat-2.3.0 → bstkchat-2.4.0}/tests/test_crypto.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bstkchat
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: A real-time Terminal-based Chatting Application using unique room IDs.
|
|
5
5
|
Author: BSTK Developers
|
|
6
6
|
Project-URL: Homepage, https://github.com/BTKcreations/BSTKCHAT
|
|
@@ -25,7 +25,8 @@ Dynamic: requires-python
|
|
|
25
25
|
|
|
26
26
|
## Features
|
|
27
27
|
|
|
28
|
-
- **
|
|
28
|
+
- **Browser Web UI (`--web` / `/web`):** Launch a local, token-authenticated browser interface (`bstkchat --web`) with Dark/Light themes, live peer sidebar, file drag-and-drop, and SSE real-time updates—while keeping all E2EE and decentralized chain storage locally on your machine.
|
|
29
|
+
- **Zero Configuration + CLI Flags:** Connects automatically over MQTT (`broker.hivemq.com`) with TLS (`8883`) enabled by default, or use `--nick`, `--room`, `--password`, `--broker`, `--port`, `--no-tls`, `--web`, and `--web-port`.
|
|
29
30
|
- **End-to-End Encryption (E2EE):** Protect rooms with a password using `scrypt` key derivation, per-message random 96-bit nonces, **AES-256-GCM** authenticated encryption, and topic-bound AAD.
|
|
30
31
|
- **Encrypted File Sharing:** Send files up to 512 KB with `/send <filepath>`, verified with SHA-256 and saved safely via `/accept [id]`.
|
|
31
32
|
- **Modern Terminal UI/UX:**
|
|
@@ -135,6 +136,7 @@ Alice > /log off
|
|
|
135
136
|
| `/compact` | Toggles compact single-line message rendering |
|
|
136
137
|
| `/multiline` | Toggles multi-line input (`Enter` = newline, `Alt+Enter` = send) |
|
|
137
138
|
| `/theme <dark\|light\|ansi>` | Switches the bottom status bar theme |
|
|
139
|
+
| `/web` | Opens the local browser Web UI for the active session |
|
|
138
140
|
| `/clear` | Clears the terminal screen and redraws the room banner |
|
|
139
141
|
| `/exit` or `/quit` | Announces departure and exits cleanly |
|
|
140
142
|
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
|
-
- **
|
|
9
|
+
- **Browser Web UI (`--web` / `/web`):** Launch a local, token-authenticated browser interface (`bstkchat --web`) with Dark/Light themes, live peer sidebar, file drag-and-drop, and SSE real-time updates—while keeping all E2EE and decentralized chain storage locally on your machine.
|
|
10
|
+
- **Zero Configuration + CLI Flags:** Connects automatically over MQTT (`broker.hivemq.com`) with TLS (`8883`) enabled by default, or use `--nick`, `--room`, `--password`, `--broker`, `--port`, `--no-tls`, `--web`, and `--web-port`.
|
|
10
11
|
- **End-to-End Encryption (E2EE):** Protect rooms with a password using `scrypt` key derivation, per-message random 96-bit nonces, **AES-256-GCM** authenticated encryption, and topic-bound AAD.
|
|
11
12
|
- **Encrypted File Sharing:** Send files up to 512 KB with `/send <filepath>`, verified with SHA-256 and saved safely via `/accept [id]`.
|
|
12
13
|
- **Modern Terminal UI/UX:**
|
|
@@ -116,6 +117,7 @@ Alice > /log off
|
|
|
116
117
|
| `/compact` | Toggles compact single-line message rendering |
|
|
117
118
|
| `/multiline` | Toggles multi-line input (`Enter` = newline, `Alt+Enter` = send) |
|
|
118
119
|
| `/theme <dark\|light\|ansi>` | Switches the bottom status bar theme |
|
|
120
|
+
| `/web` | Opens the local browser Web UI for the active session |
|
|
119
121
|
| `/clear` | Clears the terminal screen and redraws the room banner |
|
|
120
122
|
| `/exit` or `/quit` | Announces departure and exits cleanly |
|
|
121
123
|
|
|
@@ -3,6 +3,7 @@ import base64
|
|
|
3
3
|
import hashlib
|
|
4
4
|
import json
|
|
5
5
|
import os
|
|
6
|
+
import queue
|
|
6
7
|
import random
|
|
7
8
|
import re
|
|
8
9
|
import shlex
|
|
@@ -10,8 +11,10 @@ import sys
|
|
|
10
11
|
import threading
|
|
11
12
|
import time
|
|
12
13
|
import uuid
|
|
14
|
+
import webbrowser
|
|
15
|
+
from collections import deque
|
|
13
16
|
from datetime import datetime
|
|
14
|
-
from typing import Dict, List, Optional
|
|
17
|
+
from typing import Any, Dict, List, Optional
|
|
15
18
|
|
|
16
19
|
import paho.mqtt.client as mqtt
|
|
17
20
|
|
|
@@ -54,7 +57,7 @@ from bstkchat.crypto import (
|
|
|
54
57
|
sanitize_room_id,
|
|
55
58
|
)
|
|
56
59
|
|
|
57
|
-
APP_VERSION = "2.
|
|
60
|
+
APP_VERSION = "2.4.0"
|
|
58
61
|
AUTO_AWAY_SECONDS = 300
|
|
59
62
|
TYPING_TTL_SECONDS = 5.0
|
|
60
63
|
TYPING_THROTTLE_SECONDS = 3.0
|
|
@@ -108,6 +111,7 @@ COMMANDS = [
|
|
|
108
111
|
("/compact", "Toggle compact single-line messages"),
|
|
109
112
|
("/multiline", "Toggle multi-line Enter behavior"),
|
|
110
113
|
("/theme", "Switch toolbar theme: /theme <dark|light|ansi>"),
|
|
114
|
+
("/web", "Open the local browser Web UI for this session"),
|
|
111
115
|
("/clear", "Clear the terminal screen"),
|
|
112
116
|
("/exit", "Disconnect and exit"),
|
|
113
117
|
("/quit", "Alias for /exit"),
|
|
@@ -275,6 +279,8 @@ class ChatClient:
|
|
|
275
279
|
self._lock = threading.Lock()
|
|
276
280
|
self._print_lock = threading.Lock()
|
|
277
281
|
self._stop_event = threading.Event()
|
|
282
|
+
self._web_listeners: List[queue.Queue] = []
|
|
283
|
+
self._recent_events: deque = deque(maxlen=150)
|
|
278
284
|
|
|
279
285
|
self.console = Console(force_terminal=True)
|
|
280
286
|
self.client: Optional[mqtt.Client] = None
|
|
@@ -287,6 +293,72 @@ class ChatClient:
|
|
|
287
293
|
self.presence_topic = f"{self.base_topic}/presence"
|
|
288
294
|
self.sync_topic = f"{self.base_topic}/sync"
|
|
289
295
|
|
|
296
|
+
def register_web_listener(self) -> queue.Queue:
|
|
297
|
+
q: queue.Queue = queue.Queue(maxsize=200)
|
|
298
|
+
with self._lock:
|
|
299
|
+
self._web_listeners.append(q)
|
|
300
|
+
return q
|
|
301
|
+
|
|
302
|
+
def unregister_web_listener(self, q: queue.Queue) -> None:
|
|
303
|
+
with self._lock:
|
|
304
|
+
if q in self._web_listeners:
|
|
305
|
+
self._web_listeners.remove(q)
|
|
306
|
+
|
|
307
|
+
def _emit_event(self, event_type: str, data: Dict[str, Any], record_history: bool = False) -> None:
|
|
308
|
+
event = {"event": event_type, "data": data}
|
|
309
|
+
with self._lock:
|
|
310
|
+
if record_history:
|
|
311
|
+
self._recent_events.append(event)
|
|
312
|
+
listeners = list(self._web_listeners)
|
|
313
|
+
for q in listeners:
|
|
314
|
+
try:
|
|
315
|
+
q.put_nowait(event)
|
|
316
|
+
except queue.Full:
|
|
317
|
+
pass
|
|
318
|
+
|
|
319
|
+
def get_web_state(self) -> Dict[str, Any]:
|
|
320
|
+
now = time.time()
|
|
321
|
+
valid, count = self.chain.verify_integrity()
|
|
322
|
+
with self._lock:
|
|
323
|
+
peers_list = [
|
|
324
|
+
{"name": name, "status": str(info["status"]), "color": get_user_color(name)}
|
|
325
|
+
for name, info in sorted(self.peers.items(), key=lambda x: x[0].lower())
|
|
326
|
+
]
|
|
327
|
+
typers = [
|
|
328
|
+
name
|
|
329
|
+
for name, ts in self.typing_peers.items()
|
|
330
|
+
if now - ts <= TYPING_TTL_SECONDS
|
|
331
|
+
]
|
|
332
|
+
pending = [
|
|
333
|
+
{
|
|
334
|
+
"id": fid,
|
|
335
|
+
"sender": str(info["sender"]),
|
|
336
|
+
"filename": str(info["filename"]),
|
|
337
|
+
"size": int(info["size"]),
|
|
338
|
+
}
|
|
339
|
+
for fid, info in self.pending_files.items()
|
|
340
|
+
]
|
|
341
|
+
recent = list(self._recent_events)
|
|
342
|
+
return {
|
|
343
|
+
"version": APP_VERSION,
|
|
344
|
+
"nickname": self.nickname,
|
|
345
|
+
"status": self.status,
|
|
346
|
+
"room_id": self.room_id,
|
|
347
|
+
"e2ee": bool(self.password),
|
|
348
|
+
"use_tls": self.use_tls,
|
|
349
|
+
"connected": self.connected,
|
|
350
|
+
"peers": peers_list,
|
|
351
|
+
"typing": typers,
|
|
352
|
+
"chain": {
|
|
353
|
+
"enabled": self.chain.enabled,
|
|
354
|
+
"valid": valid,
|
|
355
|
+
"count": count,
|
|
356
|
+
"filepath": self.chain.filepath,
|
|
357
|
+
},
|
|
358
|
+
"pending_files": pending,
|
|
359
|
+
"recent_events": recent,
|
|
360
|
+
}
|
|
361
|
+
|
|
290
362
|
def record_activity(self) -> None:
|
|
291
363
|
"""Records local user activity and restores Active status if Auto-Away."""
|
|
292
364
|
self._last_activity = time.time()
|
|
@@ -416,11 +488,13 @@ class ChatClient:
|
|
|
416
488
|
self.client.subscribe(sync_topic)
|
|
417
489
|
self.send_presence("join")
|
|
418
490
|
self.request_sync()
|
|
491
|
+
self._emit_event("state_update", self.get_web_state())
|
|
419
492
|
|
|
420
493
|
def on_disconnect(self, client, userdata, rc, *args, **kwargs) -> None:
|
|
421
494
|
"""Handles disconnection events gracefully."""
|
|
422
495
|
with self._lock:
|
|
423
496
|
self.connected = False
|
|
497
|
+
self._emit_event("state_update", self.get_web_state())
|
|
424
498
|
if self.running:
|
|
425
499
|
self.print_system("Connection lost. Reconnecting...")
|
|
426
500
|
|
|
@@ -471,6 +545,8 @@ class ChatClient:
|
|
|
471
545
|
log_text=f"{sender} joined the room.",
|
|
472
546
|
)
|
|
473
547
|
self.send_presence("heartbeat")
|
|
548
|
+
self._emit_event("system", {"text": f"{sender} joined the room.", "time": datetime.now().strftime("%H:%M:%S")}, record_history=True)
|
|
549
|
+
self._emit_event("state_update", self.get_web_state())
|
|
474
550
|
|
|
475
551
|
elif msg_type == "leave":
|
|
476
552
|
removed = False
|
|
@@ -484,15 +560,19 @@ class ChatClient:
|
|
|
484
560
|
f"❌ [bold {color}]{safe_sender}[/] left the room.",
|
|
485
561
|
log_text=f"{sender} left the room.",
|
|
486
562
|
)
|
|
563
|
+
self._emit_event("system", {"text": f"{sender} left the room.", "time": datetime.now().strftime("%H:%M:%S")}, record_history=True)
|
|
564
|
+
self._emit_event("state_update", self.get_web_state())
|
|
487
565
|
|
|
488
566
|
elif msg_type == "heartbeat":
|
|
489
567
|
with self._lock:
|
|
490
568
|
self.peers[sender] = {"last_seen": now, "status": peer_status}
|
|
569
|
+
self._emit_event("state_update", self.get_web_state())
|
|
491
570
|
|
|
492
571
|
elif msg_type == "typing":
|
|
493
572
|
with self._lock:
|
|
494
573
|
self.peers[sender] = {"last_seen": now, "status": peer_status}
|
|
495
574
|
self.typing_peers[sender] = now
|
|
575
|
+
self._emit_event("state_update", self.get_web_state())
|
|
496
576
|
|
|
497
577
|
elif msg_type == "rename":
|
|
498
578
|
old_name = str(payload.get("old", sender))
|
|
@@ -506,6 +586,8 @@ class ChatClient:
|
|
|
506
586
|
f"changed nickname to [bold {get_user_color(new_name)}]{escape_markup(new_name)}[/]",
|
|
507
587
|
log_text=f"{old_name} changed nickname to {new_name}",
|
|
508
588
|
)
|
|
589
|
+
self._emit_event("system", {"text": f"{old_name} changed nickname to {new_name}", "time": datetime.now().strftime("%H:%M:%S")}, record_history=True)
|
|
590
|
+
self._emit_event("state_update", self.get_web_state())
|
|
509
591
|
|
|
510
592
|
def _render_incoming_text(
|
|
511
593
|
self, timestamp: str, sender: str, text: str, is_mention: bool = False, is_dm: bool = False
|
|
@@ -581,6 +663,19 @@ class ChatClient:
|
|
|
581
663
|
if target == self.nickname:
|
|
582
664
|
self._render_incoming_text(timestamp, sender, decrypted_text, is_dm=True)
|
|
583
665
|
self.write_to_log(f"DM from {sender}: {decrypted_text}")
|
|
666
|
+
self._emit_event(
|
|
667
|
+
"message",
|
|
668
|
+
{
|
|
669
|
+
"sender": sender,
|
|
670
|
+
"color": color,
|
|
671
|
+
"text": decrypted_text,
|
|
672
|
+
"time": timestamp,
|
|
673
|
+
"dm": True,
|
|
674
|
+
"target": target,
|
|
675
|
+
"own": False,
|
|
676
|
+
},
|
|
677
|
+
record_history=True,
|
|
678
|
+
)
|
|
584
679
|
self._ring_bell()
|
|
585
680
|
return
|
|
586
681
|
|
|
@@ -592,6 +687,19 @@ class ChatClient:
|
|
|
592
687
|
else:
|
|
593
688
|
self.write_to_log(f"<{sender}>: {decrypted_text}")
|
|
594
689
|
|
|
690
|
+
self._emit_event(
|
|
691
|
+
"message",
|
|
692
|
+
{
|
|
693
|
+
"sender": sender,
|
|
694
|
+
"color": color,
|
|
695
|
+
"text": decrypted_text,
|
|
696
|
+
"time": timestamp,
|
|
697
|
+
"mention": mentioned,
|
|
698
|
+
"own": False,
|
|
699
|
+
},
|
|
700
|
+
record_history=True,
|
|
701
|
+
)
|
|
702
|
+
|
|
595
703
|
if msg_type == "message":
|
|
596
704
|
msg_id = str(
|
|
597
705
|
payload.get("id")
|
|
@@ -599,6 +707,7 @@ class ChatClient:
|
|
|
599
707
|
)
|
|
600
708
|
ts = float(payload.get("ts") or time.time())
|
|
601
709
|
self.chain.append_message(msg_id, ts, timestamp, sender, "message", encrypted_text)
|
|
710
|
+
self._emit_event("state_update", self.get_web_state())
|
|
602
711
|
|
|
603
712
|
def request_sync(self, limit: int = 100) -> None:
|
|
604
713
|
"""Broadcasts a decentralized history sync request to online room peers."""
|
|
@@ -663,11 +772,26 @@ class ChatClient:
|
|
|
663
772
|
for block in added:
|
|
664
773
|
ok, text = decrypt_message(str(block.get("ciphertext", "")), key, aad=aad)
|
|
665
774
|
if ok:
|
|
775
|
+
b_sender = str(block.get("sender", "Peer"))
|
|
776
|
+
b_time = str(block.get("time", "--:--:--"))
|
|
666
777
|
self._render_incoming_text(
|
|
667
|
-
escape_markup(
|
|
668
|
-
|
|
778
|
+
escape_markup(b_time),
|
|
779
|
+
b_sender,
|
|
669
780
|
text,
|
|
670
781
|
)
|
|
782
|
+
self._emit_event(
|
|
783
|
+
"message",
|
|
784
|
+
{
|
|
785
|
+
"sender": b_sender,
|
|
786
|
+
"color": get_user_color(b_sender),
|
|
787
|
+
"text": text,
|
|
788
|
+
"time": b_time,
|
|
789
|
+
"synced": True,
|
|
790
|
+
"own": b_sender == self.nickname,
|
|
791
|
+
},
|
|
792
|
+
record_history=True,
|
|
793
|
+
)
|
|
794
|
+
self._emit_event("state_update", self.get_web_state())
|
|
671
795
|
|
|
672
796
|
def replay_recent_chain(self, limit: int = 10) -> None:
|
|
673
797
|
"""Displays recent decrypted blocks from the local room chain on join."""
|
|
@@ -733,6 +857,18 @@ class ChatClient:
|
|
|
733
857
|
f"Type [bold cyan]/accept {file_id}[/] to save.",
|
|
734
858
|
log_text=f"{sender} sent file {filename} ({len(raw_bytes)} bytes)",
|
|
735
859
|
)
|
|
860
|
+
self._emit_event(
|
|
861
|
+
"file_offer",
|
|
862
|
+
{
|
|
863
|
+
"id": file_id,
|
|
864
|
+
"sender": sender,
|
|
865
|
+
"filename": filename,
|
|
866
|
+
"size": len(raw_bytes),
|
|
867
|
+
"time": datetime.now().strftime("%H:%M:%S"),
|
|
868
|
+
},
|
|
869
|
+
record_history=True,
|
|
870
|
+
)
|
|
871
|
+
self._emit_event("state_update", self.get_web_state())
|
|
736
872
|
self._ring_bell()
|
|
737
873
|
|
|
738
874
|
def accept_file(self, file_id: Optional[str] = None, target_dir: str = "") -> Optional[str]:
|
|
@@ -758,6 +894,37 @@ class ChatClient:
|
|
|
758
894
|
)
|
|
759
895
|
return saved_path
|
|
760
896
|
|
|
897
|
+
def send_file_bytes(self, filename: str, raw_bytes: bytes) -> bool:
|
|
898
|
+
"""Checksums, encrypts, and broadcasts raw file bytes up to MAX_FILE_BYTES."""
|
|
899
|
+
if len(raw_bytes) > MAX_FILE_BYTES:
|
|
900
|
+
self.print_system(
|
|
901
|
+
f"File too large ({len(raw_bytes) // 1024} KB). Max allowed is {MAX_FILE_BYTES // 1024} KB."
|
|
902
|
+
)
|
|
903
|
+
return False
|
|
904
|
+
|
|
905
|
+
clean_name = os.path.basename(filename.strip()) or "file.bin"
|
|
906
|
+
payload_json = json.dumps({
|
|
907
|
+
"filename": clean_name,
|
|
908
|
+
"sha256": hashlib.sha256(raw_bytes).hexdigest(),
|
|
909
|
+
"data": base64.b64encode(raw_bytes).decode("ascii"),
|
|
910
|
+
})
|
|
911
|
+
if self._publish_encrypted("file", payload_json):
|
|
912
|
+
self.print_system(
|
|
913
|
+
f"📤 Sent encrypted file [bold white]{escape_markup(clean_name)}[/] "
|
|
914
|
+
f"({len(raw_bytes) / 1024:.1f} KB).",
|
|
915
|
+
log_text=f"Sent file {clean_name}",
|
|
916
|
+
)
|
|
917
|
+
self._emit_event(
|
|
918
|
+
"system",
|
|
919
|
+
{
|
|
920
|
+
"text": f"You sent encrypted file {clean_name} ({len(raw_bytes) / 1024:.1f} KB).",
|
|
921
|
+
"time": datetime.now().strftime("%H:%M:%S"),
|
|
922
|
+
},
|
|
923
|
+
record_history=True,
|
|
924
|
+
)
|
|
925
|
+
return True
|
|
926
|
+
return False
|
|
927
|
+
|
|
761
928
|
def send_file(self, filepath: str) -> bool:
|
|
762
929
|
"""Reads, checksums, encrypts, and broadcasts a file up to MAX_FILE_BYTES."""
|
|
763
930
|
expanded = os.path.expanduser(filepath)
|
|
@@ -779,19 +946,7 @@ class ChatClient:
|
|
|
779
946
|
self.print_system(f"Could not read file: {escape_markup(str(exc))}")
|
|
780
947
|
return False
|
|
781
948
|
|
|
782
|
-
|
|
783
|
-
"filename": os.path.basename(expanded),
|
|
784
|
-
"sha256": hashlib.sha256(raw_bytes).hexdigest(),
|
|
785
|
-
"data": base64.b64encode(raw_bytes).decode("ascii"),
|
|
786
|
-
})
|
|
787
|
-
if self._publish_encrypted("file", payload_json):
|
|
788
|
-
self.print_system(
|
|
789
|
-
f"📤 Sent encrypted file [bold white]{escape_markup(os.path.basename(expanded))}[/] "
|
|
790
|
-
f"({len(raw_bytes) / 1024:.1f} KB).",
|
|
791
|
-
log_text=f"Sent file {os.path.basename(expanded)}",
|
|
792
|
-
)
|
|
793
|
-
return True
|
|
794
|
-
return False
|
|
949
|
+
return self.send_file_bytes(os.path.basename(expanded), raw_bytes)
|
|
795
950
|
|
|
796
951
|
def send_presence(self, status_type: str, extra_data: Optional[dict] = None) -> None:
|
|
797
952
|
"""Broadcasts a presence payload."""
|
|
@@ -863,6 +1018,18 @@ class ChatClient:
|
|
|
863
1018
|
Markdown(text),
|
|
864
1019
|
)
|
|
865
1020
|
self.write_to_log(f"<You>: {text}")
|
|
1021
|
+
self._emit_event(
|
|
1022
|
+
"message",
|
|
1023
|
+
{
|
|
1024
|
+
"sender": self.nickname,
|
|
1025
|
+
"color": get_user_color(self.nickname),
|
|
1026
|
+
"text": text,
|
|
1027
|
+
"time": timestamp,
|
|
1028
|
+
"own": True,
|
|
1029
|
+
},
|
|
1030
|
+
record_history=True,
|
|
1031
|
+
)
|
|
1032
|
+
self._emit_event("state_update", self.get_web_state())
|
|
866
1033
|
|
|
867
1034
|
def send_private_message(self, target: str, text: str) -> None:
|
|
868
1035
|
"""Sends an encrypted Direct Message to a specific user in the room."""
|
|
@@ -879,6 +1046,19 @@ class ChatClient:
|
|
|
879
1046
|
Markdown(text),
|
|
880
1047
|
)
|
|
881
1048
|
self.write_to_log(f"DM to {target}: {text}")
|
|
1049
|
+
self._emit_event(
|
|
1050
|
+
"message",
|
|
1051
|
+
{
|
|
1052
|
+
"sender": self.nickname,
|
|
1053
|
+
"color": get_user_color(self.nickname),
|
|
1054
|
+
"text": text,
|
|
1055
|
+
"time": timestamp,
|
|
1056
|
+
"dm": True,
|
|
1057
|
+
"target": target,
|
|
1058
|
+
"own": True,
|
|
1059
|
+
},
|
|
1060
|
+
record_history=True,
|
|
1061
|
+
)
|
|
882
1062
|
|
|
883
1063
|
def switch_room(self, new_room_id: str, new_password: str = "") -> None:
|
|
884
1064
|
"""Gracefully disconnects from the current room and enters a new one."""
|
|
@@ -925,6 +1105,7 @@ class ChatClient:
|
|
|
925
1105
|
self.print_room_banner()
|
|
926
1106
|
self.replay_recent_chain(10)
|
|
927
1107
|
self.request_sync()
|
|
1108
|
+
self._emit_event("state_update", self.get_web_state())
|
|
928
1109
|
|
|
929
1110
|
def print_room_banner(self) -> None:
|
|
930
1111
|
"""Displays a clean metadata panel for the current active room."""
|
|
@@ -1105,6 +1286,8 @@ def build_arg_parser() -> argparse.ArgumentParser:
|
|
|
1105
1286
|
parser.add_argument("--compact", action="store_true", help="Use compact single-line messages")
|
|
1106
1287
|
parser.add_argument("--no-log", action="store_true", help="Disable local session logging")
|
|
1107
1288
|
parser.add_argument("--no-store", action="store_true", help="Disable decentralized room chain storage")
|
|
1289
|
+
parser.add_argument("--web", action="store_true", help="Launch the local browser Web UI")
|
|
1290
|
+
parser.add_argument("--web-port", type=int, default=0, help="Port for local Web UI (default: auto)")
|
|
1108
1291
|
parser.add_argument("--version", action="version", version=f"bstkchat {APP_VERSION}")
|
|
1109
1292
|
return parser
|
|
1110
1293
|
|
|
@@ -1246,6 +1429,36 @@ def main(argv: Optional[List[str]] = None) -> None:
|
|
|
1246
1429
|
chat.setup_mqtt()
|
|
1247
1430
|
chat.start_background_tasks()
|
|
1248
1431
|
|
|
1432
|
+
web_server = None
|
|
1433
|
+
if args.web:
|
|
1434
|
+
from bstkchat.web import WebServer
|
|
1435
|
+
|
|
1436
|
+
web_server = WebServer(chat, port=args.web_port)
|
|
1437
|
+
url = web_server.start()
|
|
1438
|
+
chat.safe_print(
|
|
1439
|
+
Panel(
|
|
1440
|
+
f"[bold green]🌐 Web UI running at:[/]\n[bold cyan]{escape_markup(url)}[/]\n\n"
|
|
1441
|
+
"[dim white]Press Ctrl+C to stop the server and exit.[/]",
|
|
1442
|
+
title=f"[bold cyan]BSTK Chat Web UI v{APP_VERSION}[/]",
|
|
1443
|
+
box=box.ROUNDED,
|
|
1444
|
+
border_style="cyan",
|
|
1445
|
+
expand=False,
|
|
1446
|
+
)
|
|
1447
|
+
)
|
|
1448
|
+
try:
|
|
1449
|
+
webbrowser.open(url)
|
|
1450
|
+
except Exception:
|
|
1451
|
+
pass
|
|
1452
|
+
try:
|
|
1453
|
+
while chat.running:
|
|
1454
|
+
chat._stop_event.wait(1)
|
|
1455
|
+
except KeyboardInterrupt:
|
|
1456
|
+
pass
|
|
1457
|
+
finally:
|
|
1458
|
+
web_server.stop()
|
|
1459
|
+
chat.close()
|
|
1460
|
+
return
|
|
1461
|
+
|
|
1249
1462
|
chat.clear_screen()
|
|
1250
1463
|
chat.print_room_banner()
|
|
1251
1464
|
chat.replay_recent_chain(10)
|
|
@@ -1462,6 +1675,20 @@ def main(argv: Optional[List[str]] = None) -> None:
|
|
|
1462
1675
|
save_config(cfg)
|
|
1463
1676
|
chat.print_system(f"Toolbar theme set to [bold]{chat.theme}[/].")
|
|
1464
1677
|
|
|
1678
|
+
elif cmd == "/web":
|
|
1679
|
+
if web_server is None:
|
|
1680
|
+
from bstkchat.web import WebServer
|
|
1681
|
+
|
|
1682
|
+
web_server = WebServer(chat, port=args.web_port)
|
|
1683
|
+
url = web_server.start()
|
|
1684
|
+
else:
|
|
1685
|
+
url = web_server.url
|
|
1686
|
+
chat.print_system(f"🌐 Web UI running at [bold cyan]{escape_markup(url)}[/]")
|
|
1687
|
+
try:
|
|
1688
|
+
webbrowser.open(url)
|
|
1689
|
+
except Exception:
|
|
1690
|
+
pass
|
|
1691
|
+
|
|
1465
1692
|
elif cmd == "/clear":
|
|
1466
1693
|
chat.clear_screen()
|
|
1467
1694
|
chat.print_room_banner()
|
|
@@ -1493,6 +1720,8 @@ def main(argv: Optional[List[str]] = None) -> None:
|
|
|
1493
1720
|
except EOFError:
|
|
1494
1721
|
break
|
|
1495
1722
|
|
|
1723
|
+
if web_server is not None:
|
|
1724
|
+
web_server.stop()
|
|
1496
1725
|
chat.close()
|
|
1497
1726
|
|
|
1498
1727
|
|