-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.go
55 lines (46 loc) · 1.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"blive/src/database"
"blive/src/globals"
"blive/src/routers"
"blive/src/services"
"blive/src/services/music"
"embed"
"encoding/json"
"fmt"
"github.com/gofiber/fiber/v2"
"log"
)
//go:embed front/dist/*
var frontFS embed.FS
func main() {
database.Connect()
app := fiber.New()
danmuChannel := make(chan services.DanmuCommand, 10)
musicChannel := make(chan string, 500)
encodeChannel := make(chan music.SongDetail, 500)
handleCommand(&danmuChannel, &musicChannel)
danmuService := services.NewDanmuService(&danmuChannel)
globals.DanmuService = &danmuService
musicService := services.NewMusicService(&musicChannel, &encodeChannel)
go musicService.Start()
routers.AppRouter(app, frontFS)
log.Fatal(app.Listen(":18000"))
}
func handleCommand(danmuChannel *chan services.DanmuCommand, musicChannel *chan string) {
go func() {
for {
command, ok := <-*danmuChannel
if !ok {
fmt.Printf("test: false")
break
}
commandJson, _ := json.Marshal(command)
fmt.Printf("收到指令: %s\n", commandJson)
if command.CommandName == "点歌" {
*musicChannel <- command.Arg1
}
routers.SendWebsocketBroadcast(routers.WebsocketMessage[services.DanmuCommand]{"danmu_command", command})
}
}()
}