Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
Make IDs for chat messages generated server-side, not client. For #26
Gabe Kangascb0245ae55fb
diff --git a/core/chat/client.go b/core/chat/client.goindex 91f8265f30..2ec56c7232 100644--- a/core/chat/client.go+++ b/core/chat/client.go@@ -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 connectiondefault:var msg models.ChatMessage+ id, err := shortid.Generate()+ if err != nil {+ log.Panicln(err)+ }++ msg.ID = idif err := websocket.JSON.Receive(c.ws, &msg); err == io.EOF {c.doneCh <- truediff --git a/core/chat/server.go b/core/chat/server.goindex 40d395f95c..366f4a1db4 100644--- a/core/chat/server.go+++ b/core/chat/server.go@@ -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 <- pingdiff --git a/core/chatListener.go b/core/chatListener.goindex 576d524270..e9328c9327 100644--- a/core/chatListener.go+++ b/core/chatListener.go@@ -3,8 +3,6 @@ package coreimport ("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 sentfunc (cl ChatListenerImpl) MessageSent(message models.ChatMessage) {- log.Printf("Message sent to all: %s", message.String())}//SendMessageToChat sends a message to the chat serverdiff --git a/go.mod b/go.modindex a58931127a..3d526edebb 100644--- a/go.mod+++ b/go.mod@@ -13,6 +13,7 @@ require (github.com/multiformats/go-multiaddr v0.2.2github.com/radovskyb/watcher v1.0.7github.com/sirupsen/logrus v1.6.0+ github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cfgithub.com/yutopp/go-flv v0.2.0github.com/yutopp/go-rtmp v0.0.0-20191212152852-4e41609a99bbgolang.org/x/net v0.0.0-20200602114024-627f9648deb9diff --git a/go.sum b/go.sumindex c0f980afb4..a5305f46c4 100644--- a/go.sum+++ b/go.sum@@ -920,6 +920,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5github.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=diff --git a/models/chatMessage.go b/models/chatMessage.goindex 3f2a4f1bdd..4a442f3115 100644--- a/models/chatMessage.go+++ b/models/chatMessage.go@@ -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 validfunc (s ChatMessage) Valid() bool {return s.Author != "" && s.Body != "" && s.ID != ""diff --git a/webroot/js/message.js b/webroot/js/message.jsindex e8f5d7a969..b8f37f1f70 100644--- a/webroot/js/message.js+++ b/webroot/js/message.js@@ -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) {diff --git a/webroot/js/utils.js b/webroot/js/utils.jsindex 6ef317bf89..4cd966c5be 100644--- a/webroot/js/utils.js+++ b/webroot/js/utils.js@@ -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>sfunction addNewlines(str) {return str.replace(/(?:\r\n|\r|\n)/g, '<br />');