Compare commits
13 Commits
215efcd63f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
001fef8bbc | ||
|
|
a9004c38af | ||
|
|
b34c980ea5 | ||
|
|
78fd4fd28b | ||
|
|
b89d8e3d3f | ||
|
|
c4a21861cd | ||
|
|
d5c3a52215 | ||
|
|
bc1f7779d7 | ||
|
|
49880c837d | ||
|
|
4dd5a40dfe | ||
|
|
13b583a77e | ||
|
|
c9c4800d68 | ||
|
|
d793e13361 |
@@ -57,7 +57,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ws = new WebSocket(`${window.location.protocol == "https:" ? "wss" : "ws"}://${window.location.host}/ws${window.location.search}`);
|
ws = new WebSocket("ws://"+window.location.host+"/ws"+window.location.search);
|
||||||
ws.onopen = function(evt) {
|
ws.onopen = function(evt) {
|
||||||
print("READY");
|
print("READY");
|
||||||
}
|
}
|
||||||
@@ -69,25 +69,21 @@
|
|||||||
console.log("evt.data:", evt.data)
|
console.log("evt.data:", evt.data)
|
||||||
const data = JSON.parse(evt.data);
|
const data = JSON.parse(evt.data);
|
||||||
|
|
||||||
if (data.Text) {
|
const utterThis = new SpeechSynthesisUtterance(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,10 +1,9 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
type message struct {
|
type message struct {
|
||||||
Text string
|
Text string
|
||||||
QuietText string
|
Pitch int
|
||||||
Pitch int
|
Rate float64
|
||||||
Rate float64
|
VoiceIdx int
|
||||||
VoiceIdx int
|
room string
|
||||||
room string
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@@ -32,6 +31,9 @@ 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 {
|
||||||
@@ -44,42 +46,8 @@ func (s *Server) WS(w http.ResponseWriter, r *http.Request) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func() {
|
s.sessions = append(s.sessions, sess)
|
||||||
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