-
Notifications
You must be signed in to change notification settings - Fork 73
/
rtmp.go
47 lines (41 loc) · 1.32 KB
/
rtmp.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
package bootstrap
import (
"context"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/synctv-org/synctv/internal/op"
"github.com/synctv-org/synctv/internal/rtmp"
"github.com/synctv-org/synctv/internal/settings"
rtmps "github.com/zijiren233/livelib/server"
)
func InitRtmp(ctx context.Context) error {
s := rtmps.NewRtmpServer(auth)
rtmp.Init(s)
return nil
}
func auth(ReqAppName, ReqChannelName string, IsPublisher bool) (*rtmps.Channel, error) {
if IsPublisher {
channelName, err := rtmp.AuthRtmpPublish(ReqChannelName)
if err != nil {
log.Errorf("rtmp: publish auth to %s error: %v", ReqAppName, err)
return nil, err
}
log.Infof("rtmp: publisher login success: %s/%s", ReqAppName, channelName)
r, err := op.LoadOrInitRoomByID(ReqAppName)
if err != nil {
log.Errorf("rtmp: get room by id error: %v", err)
return nil, err
}
return r.Value().GetChannel(channelName)
}
if !settings.RtmpPlayer.Get() {
log.Warnf("rtmp: dial to %s/%s error: %s", ReqAppName, ReqChannelName, "rtmp player is not enabled")
return nil, fmt.Errorf("rtmp: dial to %s/%s error: %s", ReqAppName, ReqChannelName, "rtmp player is not enabled")
}
r, err := op.LoadOrInitRoomByID(ReqAppName)
if err != nil {
log.Errorf("rtmp: get room by id error: %v", err)
return nil, err
}
return r.Value().GetChannel(ReqChannelName)
}