Compare commits
3 Commits
master
...
215efcd63f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
215efcd63f | ||
|
|
58d8b03c59 | ||
|
|
9a44380d45 |
@@ -57,7 +57,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ws = new WebSocket("ws://"+window.location.host+"/ws"+window.location.search);
|
ws = new WebSocket(`${window.location.protocol == "https:" ? "wss" : "ws"}://${window.location.host}/ws${window.location.search}`);
|
||||||
ws.onopen = function(evt) {
|
ws.onopen = function(evt) {
|
||||||
print("READY");
|
print("READY");
|
||||||
}
|
}
|
||||||
@@ -69,21 +69,25 @@
|
|||||||
console.log("evt.data:", evt.data)
|
console.log("evt.data:", evt.data)
|
||||||
const data = JSON.parse(evt.data);
|
const data = JSON.parse(evt.data);
|
||||||
|
|
||||||
const utterThis = new SpeechSynthesisUtterance(data.Text);
|
if (data.Text) {
|
||||||
|
const utterThis = new SpeechSynthesisUtterance(data.Text);
|
||||||
|
|
||||||
const idx = data.VoiceIdx || 0;
|
const idx = data.VoiceIdx || 0;
|
||||||
utterThis.voice = voices[idx];
|
utterThis.voice = voices[idx];
|
||||||
|
|
||||||
if (data.Pitch) {
|
if (data.Pitch) {
|
||||||
utterThis.pitch = data.Pitch
|
utterThis.pitch = data.Pitch
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.Rate) {
|
||||||
|
utterThis.rate = data.Rate
|
||||||
|
}
|
||||||
|
|
||||||
|
window.speechSynthesis.speak(utterThis);
|
||||||
|
print(data.Text);
|
||||||
|
} else if (data.QuietText) {
|
||||||
|
print(data.QuietText);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.Rate) {
|
|
||||||
utterThis.rate = data.Rate
|
|
||||||
}
|
|
||||||
|
|
||||||
window.speechSynthesis.speak(utterThis);
|
|
||||||
print(data.Text);
|
|
||||||
}
|
}
|
||||||
ws.onerror = function(evt) {
|
ws.onerror = function(evt) {
|
||||||
print("ERROR: " + evt.data);
|
print("ERROR: " + evt.data);
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
type message struct {
|
type message struct {
|
||||||
Text string
|
Text string
|
||||||
Pitch int
|
QuietText string
|
||||||
Rate float64
|
Pitch int
|
||||||
VoiceIdx int
|
Rate float64
|
||||||
room string
|
VoiceIdx int
|
||||||
|
room string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@@ -31,9 +32,6 @@ 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 {
|
||||||
for i := range s.sessions {
|
for i := range s.sessions {
|
||||||
if s.sessions[i].id != sess.id && s.sessions[i].room == sess.room {
|
if s.sessions[i].id != sess.id && s.sessions[i].room == sess.room {
|
||||||
@@ -46,8 +44,42 @@ func (s *Server) WS(w http.ResponseWriter, r *http.Request) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s.sessions = append(s.sessions, sess)
|
func() {
|
||||||
|
s.sessions = append(s.sessions, sess)
|
||||||
|
|
||||||
|
n := 0
|
||||||
|
for i := range s.sessions {
|
||||||
|
if s.sessions[i].room == sess.room {
|
||||||
|
n += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := range s.sessions {
|
||||||
|
if s.sessions[i].room == sess.room {
|
||||||
|
if s.sessions[i].id == sess.id {
|
||||||
|
s.sessions[i].scatterc <- message{QuietText: fmt.Sprintf("you have joined %v people", n-1)}
|
||||||
|
} else {
|
||||||
|
s.sessions[i].scatterc <- message{QuietText: fmt.Sprintf("there is now %v people", n)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
defer func() {
|
defer func() {
|
||||||
|
n := 0
|
||||||
|
for i := range s.sessions {
|
||||||
|
if s.sessions[i].room == sess.room {
|
||||||
|
n += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n -= 1
|
||||||
|
for i := range s.sessions {
|
||||||
|
if s.sessions[i].room == sess.room {
|
||||||
|
if s.sessions[i].id == sess.id {
|
||||||
|
} else {
|
||||||
|
s.sessions[i].scatterc <- message{QuietText: fmt.Sprintf("there is now %v people", n)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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 = append(s.sessions[:i], s.sessions[i+1:]...)
|
s.sessions = append(s.sessions[:i], s.sessions[i+1:]...)
|
||||||
|
|||||||
Reference in New Issue
Block a user