Compare commits

..

5 Commits

Author SHA1 Message Date
Bel LaPointe
001fef8bbc ?room s 2025-10-15 00:12:19 -06:00
Bel LaPointe
a9004c38af remove quote file 2025-10-14 23:59:46 -06:00
bel
b34c980ea5 fade old text 2025-10-14 23:46:48 -06:00
bel
78fd4fd28b not sure what is left but ship 2025-10-14 23:37:15 -06:00
bel
b89d8e3d3f no log 2025-10-14 23:30:04 -06:00
4 changed files with 29 additions and 12 deletions

View File

@@ -13,7 +13,7 @@
var print = function(message) { var print = function(message) {
var before = output.innerHTML.split("<br>"); var before = output.innerHTML.split("<br>");
before.unshift(`${new Date().toLocaleTimeString()} | ${message}`); before.unshift(`<span>${new Date().toLocaleTimeString()} | ${message}</span>`);
if (before.length > 20) { if (before.length > 20) {
before = before.slice(0, 20); before = before.slice(0, 20);
} }
@@ -57,7 +57,7 @@
} }
} }
ws = new WebSocket("ws://"+window.location.host+"/ws"); ws = new WebSocket("ws://"+window.location.host+"/ws"+window.location.search);
ws.onopen = function(evt) { ws.onopen = function(evt) {
print("READY"); print("READY");
} }
@@ -83,7 +83,7 @@
} }
window.speechSynthesis.speak(utterThis); window.speechSynthesis.speak(utterThis);
print("RESPONSE: " + evt.data); print(data.Text);
} }
ws.onerror = function(evt) { ws.onerror = function(evt) {
print("ERROR: " + evt.data); print("ERROR: " + evt.data);
@@ -117,6 +117,19 @@
}; };
}); });
</script> </script>
<style>
#output > span {
opacity: 0.33;
}
#output > span:nth-child(1) {
opacity: 1;
}
#output > span:nth-child(2)
, #output > span:nth-child(3)
{
opacity: 0.66;
}
</style>
</head> </head>
<body> <body>
<div style="width: 80%; height: 80%; margin: auto; display: flex; flex-direction: row;"> <div style="width: 80%; height: 80%; margin: auto; display: flex; flex-direction: row;">

View File

@@ -5,4 +5,5 @@ type message struct {
Pitch int Pitch int
Rate float64 Rate float64
VoiceIdx int VoiceIdx int
room string
} }

View File

@@ -31,10 +31,12 @@ func (s *Server) WS(w http.ResponseWriter, r *http.Request) error {
} }
defer sess.Close() defer sess.Close()
log.Println("someone has joined", sess.room)
defer log.Println("someone has left", sess.room)
sess.cb = func(m message) error { sess.cb = func(m message) error {
log.Printf("cbing to all other sessions %+v", m)
for i := range s.sessions { for i := range s.sessions {
if s.sessions[i].id != sess.id { if s.sessions[i].id != sess.id && s.sessions[i].room == sess.room {
select { select {
case s.sessions[i].scatterc <- m: case s.sessions[i].scatterc <- m:
case <-s.sessions[i].ctx.Done(): case <-s.sessions[i].ctx.Done():

View File

@@ -20,6 +20,7 @@ type session struct {
cb func(message) error cb func(message) error
id string id string
scatterc chan (message) scatterc chan (message)
room string
} }
var upgrader = websocket.Upgrader{} var upgrader = websocket.Upgrader{}
@@ -34,6 +35,7 @@ func newSession(w http.ResponseWriter, r *http.Request, cb func(message) error)
cb: cb, cb: cb,
id: uuid.New().String(), id: uuid.New().String(),
scatterc: make(chan message, 20), scatterc: make(chan message, 20),
room: r.URL.Query().Get("room"),
}, err }, err
} }
@@ -70,8 +72,8 @@ func (s *session) gather() {
if err := json.Unmarshal(msg, &m); err != nil { if err := json.Unmarshal(msg, &m); err != nil {
return err return err
} }
m.room = s.room
log.Printf("gathered %+v (%s)", m, msg)
return s.cb(m) return s.cb(m)
}) })
} }
@@ -80,7 +82,6 @@ func (s *session) scatter() {
s.while(func() error { s.while(func() error {
select { select {
case m := <-s.scatterc: case m := <-s.scatterc:
log.Printf("scattering %+v", m)
b, _ := json.Marshal(m) b, _ := json.Marshal(m)
return s.ws.WriteMessage(1, b) return s.ws.WriteMessage(1, b)
case <-s.ctx.Done(): case <-s.ctx.Done():