mirror of
https://github.com/owncast/owncast.git
synced 2024-11-22 04:40:37 +03:00
Make IDs for chat messages generated server-side, not client. For #26
This commit is contained in:
parent
5dffaf215b
commit
a297e33eff
8 changed files with 11 additions and 19 deletions
|
@ -10,6 +10,8 @@ import (
|
|||
|
||||
"github.com/gabek/owncast/models"
|
||||
"github.com/gabek/owncast/utils"
|
||||
|
||||
"github.com/teris-io/shortid"
|
||||
)
|
||||
|
||||
const channelBufSize = 100
|
||||
|
@ -102,6 +104,12 @@ func (c *Client) listenRead() {
|
|||
// read data from websocket connection
|
||||
default:
|
||||
var msg models.ChatMessage
|
||||
id, err := shortid.Generate()
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
msg.ID = id
|
||||
|
||||
if err := websocket.JSON.Receive(c.ws, &msg); err == io.EOF {
|
||||
c.doneCh <- true
|
||||
|
|
|
@ -69,8 +69,6 @@ func (s *server) sendAll(msg models.ChatMessage) {
|
|||
}
|
||||
|
||||
func (s *server) ping() {
|
||||
// fmt.Println("Start pinging....", len(s.clients))
|
||||
|
||||
ping := models.PingMessage{MessageType: "PING"}
|
||||
for _, c := range s.Clients {
|
||||
c.pingch <- ping
|
||||
|
|
|
@ -3,8 +3,6 @@ package core
|
|||
import (
|
||||
"errors"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/gabek/owncast/core/chat"
|
||||
"github.com/gabek/owncast/models"
|
||||
)
|
||||
|
@ -24,7 +22,6 @@ func (cl ChatListenerImpl) ClientRemoved(clientID string) {
|
|||
|
||||
//MessageSent is for when a message is sent
|
||||
func (cl ChatListenerImpl) MessageSent(message models.ChatMessage) {
|
||||
log.Printf("Message sent to all: %s", message.String())
|
||||
}
|
||||
|
||||
//SendMessageToChat sends a message to the chat server
|
||||
|
|
1
go.mod
1
go.mod
|
@ -13,6 +13,7 @@ require (
|
|||
github.com/multiformats/go-multiaddr v0.2.2
|
||||
github.com/radovskyb/watcher v1.0.7
|
||||
github.com/sirupsen/logrus v1.6.0
|
||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf
|
||||
github.com/yutopp/go-flv v0.2.0
|
||||
github.com/yutopp/go-rtmp v0.0.0-20191212152852-4e41609a99bb
|
||||
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
|
||||
|
|
2
go.sum
2
go.sum
|
@ -920,6 +920,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
|
|||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf h1:Z2X3Os7oRzpdJ75iPqWZc0HeJWFYNCvKsfpQwFpRNTA=
|
||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0=
|
||||
github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e/go.mod h1:XDKHRm5ThF8YJjx001LtgelzsoaEcvnA7lVWz9EeX3g=
|
||||
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c h1:u6SKchux2yDvFQnDHS3lPnIRmfVJ5Sxy3ao2SIdysLQ=
|
||||
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM=
|
||||
|
|
|
@ -11,12 +11,6 @@ type ChatMessage struct {
|
|||
MessageType string `json:"type"`
|
||||
}
|
||||
|
||||
//String converts the chat message to string
|
||||
//TODO: is this required? or can we remove it
|
||||
func (s ChatMessage) String() string {
|
||||
return s.Author + " says " + s.Body
|
||||
}
|
||||
|
||||
//Valid checks to ensure the message is valid
|
||||
func (s ChatMessage) Valid() bool {
|
||||
return s.Author != "" && s.Body != "" && s.ID != ""
|
||||
|
|
|
@ -207,7 +207,6 @@ class Messaging {
|
|||
var message = new Message({
|
||||
body: content,
|
||||
author: this.username,
|
||||
id: uuidv4(),
|
||||
});
|
||||
const messageJSON = JSON.stringify(message);
|
||||
if (window && window.ws) {
|
||||
|
|
|
@ -35,13 +35,6 @@ function jumpToBottom(element) {
|
|||
}, 50, element);
|
||||
}
|
||||
|
||||
function uuidv4() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
// convert newlines to <br>s
|
||||
function addNewlines(str) {
|
||||
return str.replace(/(?:\r\n|\r|\n)/g, '<br />');
|
||||
|
|
Loading…
Reference in a new issue