chat: chore codes

Kim committed Oct 21, 2025 at 18:31 UTC 6da3dd4081185efacb6805e5df4b63e973c7565e
2 files changed +12 -4
cmd/example_chat/main.go
+6 -2
@@ -26,6 +26,8 @@ var (
26 flagBootstraps []string
27 flagAddr string
28 flagName string
29 + flagProtocol string
30 + flagTopic string
31 )
32
33 func init() {
@@ -34,6 +36,8 @@ func init() {
36 flags.StringSliceVar(&flagBootstraps, "bootstrap", nil, "multiaddrs with /p2p/ (supports /dnsaddr/ that resolves to /p2p/)")
37 flags.StringVar(&flagAddr, "addr", ":8091", "local chat HTTP listen address")
38 flags.StringVar(&flagName, "name", "demo-chat", "backend display name")
39 + flags.StringVar(&flagProtocol, "protocol", "/relaydns/http/1.0", "libp2p protocol id for streams (must match server)")
40 + flags.StringVar(&flagTopic, "topic", "relaydns.backends", "pubsub topic for backend adverts")
41 }
42
43 func main() {
@@ -66,8 +70,8 @@ func runChat(cmd *cobra.Command, args []string) error {
70
71 // 2) advertise over RelayDNS (HTTP tunneled via server /peer route)
72 client, err := relaydns.NewClient(ctx, relaydns.ClientConfig{
69 - Protocol: "/relaydns/http/1.0",
70 - Topic: "relaydns.backends",
73 + Protocol: flagProtocol,
74 + Topic: flagTopic,
75 AdvertiseEvery: 3 * time.Second,
76 Name: flagName,
77 TargetTCP: relaydns.AddrToTarget(flagAddr),
cmd/example_chat/view.go
+6 -2
@@ -194,8 +194,12 @@ var indexTmpl = template.Must(template.New("chat").Parse(`<!DOCTYPE html>
194 user.focus();
195 });
196
197 - // Stable color per nickname
198 - const PALETTE = ['#60a5fa','#22c55e','#f59e0b','#ef4444','#a78bfa','#14b8a6','#eab308','#f472b6','#8b5cf6','#06b6d4'];
197 + // Stable color per nickname (expanded palette)
198 + const PALETTE = [
199 + '#60a5fa','#22c55e','#f59e0b','#ef4444','#a78bfa','#14b8a6','#eab308','#f472b6','#8b5cf6','#06b6d4',
200 + '#34d399','#fb7185','#c084fc','#f97316','#84cc16','#10b981','#38bdf8','#f43f5e','#e879f9','#fde047',
201 + '#93c5fd','#4ade80','#fca5a5','#a3e635','#67e8f9','#f0abfc','#fbbf24','#86efac'
202 + ];
203 function hashNick(s){
204 let h = 0;
205 for (let i = 0; i < s.length; i++) { h = ((h << 5) - h) + s.charCodeAt(i); h |= 0; }