Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
4a52ec3d33 |
|||
|
68c05816dd |
9 changed files with 46 additions and 23 deletions
|
|
@ -12,6 +12,11 @@ const createWebSocketConnection = () => {
|
||||||
return new WebSocket(`${protocol}://${window.location.hostname}:${window.location.port}/ws/chat/messages`)
|
return new WebSocket(`${protocol}://${window.location.hostname}:${window.location.port}/ws/chat/messages`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isInViewport = (element) => {
|
||||||
|
const rect = element.getBoundingClientRect()
|
||||||
|
|
||||||
|
return (rect.top - 90) > 0
|
||||||
|
}
|
||||||
|
|
||||||
const runChat = () => {
|
const runChat = () => {
|
||||||
const ws = createWebSocketConnection()
|
const ws = createWebSocketConnection()
|
||||||
|
|
@ -33,6 +38,13 @@ const runChat = () => {
|
||||||
|
|
||||||
container.appendChild(message)
|
container.appendChild(message)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
getChat().querySelectorAll('.message').forEach((message) => {
|
||||||
|
if (!isInViewport(message)) {
|
||||||
|
message.classList.toggle('animate__fadeInUp', false)
|
||||||
|
message.classList.toggle('animate__fadeOutUp', true)
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
--theme-color-users-5: var(--color-owncast-user-5);
|
--theme-color-users-5: var(--color-owncast-user-5);
|
||||||
--theme-color-users-6: var(--color-owncast-user-6);
|
--theme-color-users-6: var(--color-owncast-user-6);
|
||||||
--theme-color-users-7: var(--color-owncast-user-7);
|
--theme-color-users-7: var(--color-owncast-user-7);
|
||||||
|
|
||||||
|
--animate-duration: 500ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
#chat {
|
#chat {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
|
||||||
|
|
||||||
rice "github.com/GeertJohan/go.rice"
|
rice "github.com/GeertJohan/go.rice"
|
||||||
"github.com/go-playground/validator"
|
"github.com/go-playground/validator"
|
||||||
|
|
@ -15,7 +14,7 @@ import (
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
"gitnet.fr/deblan/owncast-webhook/internal/client/twitch"
|
"gitnet.fr/deblan/owncast-webhook/internal/client/twitch"
|
||||||
"gitnet.fr/deblan/owncast-webhook/internal/config"
|
"gitnet.fr/deblan/owncast-webhook/internal/config"
|
||||||
"gitnet.fr/deblan/owncast-webhook/internal/store"
|
"gitnet.fr/deblan/owncast-webhook/internal/test"
|
||||||
"gitnet.fr/deblan/owncast-webhook/internal/web/router"
|
"gitnet.fr/deblan/owncast-webhook/internal/web/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -46,12 +45,7 @@ func main() {
|
||||||
router.RegisterControllers(e)
|
router.RegisterControllers(e)
|
||||||
|
|
||||||
if conf.Test.Enable {
|
if conf.Test.Enable {
|
||||||
go func() {
|
test.GenerateFakeMessages()
|
||||||
for {
|
|
||||||
store.GetMessageStore().Add(store.TestMessage{})
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.Twitch.Enable {
|
if conf.Twitch.Enable {
|
||||||
|
|
|
||||||
5
go.mod
5
go.mod
|
|
@ -6,6 +6,7 @@ require (
|
||||||
github.com/GeertJohan/go.rice v1.0.3
|
github.com/GeertJohan/go.rice v1.0.3
|
||||||
github.com/gempir/go-twitch-irc/v4 v4.2.0
|
github.com/gempir/go-twitch-irc/v4 v4.2.0
|
||||||
github.com/go-playground/validator v9.31.0+incompatible
|
github.com/go-playground/validator v9.31.0+incompatible
|
||||||
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/labstack/echo/v4 v4.12.0
|
github.com/labstack/echo/v4 v4.12.0
|
||||||
gopkg.in/ini.v1 v1.67.0
|
gopkg.in/ini.v1 v1.67.0
|
||||||
maragu.dev/gomponents v1.2.0
|
maragu.dev/gomponents v1.2.0
|
||||||
|
|
@ -13,10 +14,10 @@ require (
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/daaku/go.zipexe v1.0.2 // indirect
|
github.com/daaku/go.zipexe v1.0.2 // indirect
|
||||||
|
github.com/go-faker/faker/v4 v4.6.1 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
||||||
github.com/gorilla/websocket v1.5.3 // indirect
|
|
||||||
github.com/labstack/gommon v0.4.2 // indirect
|
github.com/labstack/gommon v0.4.2 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
|
@ -27,7 +28,7 @@ require (
|
||||||
golang.org/x/crypto v0.27.0 // indirect
|
golang.org/x/crypto v0.27.0 // indirect
|
||||||
golang.org/x/net v0.28.0 // indirect
|
golang.org/x/net v0.28.0 // indirect
|
||||||
golang.org/x/sys v0.25.0 // indirect
|
golang.org/x/sys v0.25.0 // indirect
|
||||||
golang.org/x/text v0.18.0 // indirect
|
golang.org/x/text v0.28.0 // indirect
|
||||||
golang.org/x/time v0.5.0 // indirect
|
golang.org/x/time v0.5.0 // indirect
|
||||||
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
|
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
6
go.sum
6
go.sum
|
|
@ -8,6 +8,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/gempir/go-twitch-irc/v4 v4.2.0 h1:OCeff+1aH4CZIOxgKOJ8dQjh+1ppC6sLWrXOcpGZyq4=
|
github.com/gempir/go-twitch-irc/v4 v4.2.0 h1:OCeff+1aH4CZIOxgKOJ8dQjh+1ppC6sLWrXOcpGZyq4=
|
||||||
github.com/gempir/go-twitch-irc/v4 v4.2.0/go.mod h1:QsOMMAk470uxQ7EYD9GJBGAVqM/jDrXBNbuePfTauzg=
|
github.com/gempir/go-twitch-irc/v4 v4.2.0/go.mod h1:QsOMMAk470uxQ7EYD9GJBGAVqM/jDrXBNbuePfTauzg=
|
||||||
|
github.com/go-faker/faker/v4 v4.6.1 h1:xUyVpAjEtB04l6XFY0V/29oR332rOSPWV4lU8RwDt4k=
|
||||||
|
github.com/go-faker/faker/v4 v4.6.1/go.mod h1:arSdxNCSt7mOhdk8tEolvHeIJ7eX4OX80wXjKKvkKBY=
|
||||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||||
|
|
@ -48,8 +50,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
|
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
package store
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/gempir/go-twitch-irc/v4"
|
"github.com/gempir/go-twitch-irc/v4"
|
||||||
|
"github.com/go-faker/faker/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestMessage struct {
|
type TestMessage struct {
|
||||||
|
|
@ -12,7 +10,7 @@ type TestMessage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o TestMessage) ID() string {
|
func (o TestMessage) ID() string {
|
||||||
return fmt.Sprintf("%f", rand.Float64())
|
return faker.Sentence()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o TestMessage) Visible() bool {
|
func (o TestMessage) Visible() bool {
|
||||||
|
|
@ -24,9 +22,9 @@ func (o TestMessage) Origin() MessageOrigin {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o TestMessage) Author() string {
|
func (o TestMessage) Author() string {
|
||||||
return fmt.Sprintf("%f", rand.Float64())
|
return faker.Username()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o TestMessage) Content() string {
|
func (o TestMessage) Content() string {
|
||||||
return fmt.Sprintf("%f", rand.Float64())
|
return faker.Sentence()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
internal/test/fake.go
Normal file
17
internal/test/fake.go
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gitnet.fr/deblan/owncast-webhook/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GenerateFakeMessages() {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
store.GetMessageStore().Add(store.TestMessage{})
|
||||||
|
time.Sleep(time.Duration(rand.Intn(3000-100)+100) * time.Millisecond)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
@ -77,10 +77,7 @@ func (ctrl *Controller) Messages(c echo.Context) error {
|
||||||
},
|
},
|
||||||
Body: []Node{
|
Body: []Node{
|
||||||
ID("chat"),
|
ID("chat"),
|
||||||
Div(
|
Div(Class("messages")),
|
||||||
Class("messages"),
|
|
||||||
Map(store.GetMessageStore().All(), CreateMessageView),
|
|
||||||
),
|
|
||||||
Group(assets.EntrypointJs("main")),
|
Group(assets.EntrypointJs("main")),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ func CreateMessageView(message store.MessageInterface) Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
return Div(
|
return Div(
|
||||||
Class("message animate__animated animate__fadeInRight"),
|
Class("message animate__animated animate__fadeInUp"),
|
||||||
ID(message.ID()),
|
ID(message.ID()),
|
||||||
containerStyle,
|
containerStyle,
|
||||||
Div(
|
Div(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue