mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-06 17:16:55 +08:00
开发提交
This commit is contained in:
39
main.go
39
main.go
@@ -2,13 +2,9 @@ package engine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/Monibuca/engine/v3/util"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time" // colorable
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
@@ -18,44 +14,27 @@ import (
|
||||
var (
|
||||
config = &struct {
|
||||
EnableWaitStream bool
|
||||
EnableAudio bool
|
||||
EnableVideo bool
|
||||
RingSize int
|
||||
EnableAudio bool
|
||||
EnableVideo bool
|
||||
PublishTimeout time.Duration
|
||||
}{true, true, true, 10, time.Minute}
|
||||
}{true, true, true, time.Minute}
|
||||
// ConfigRaw 配置信息的原始数据
|
||||
ConfigRaw []byte
|
||||
// Version 引擎版本号
|
||||
Version string
|
||||
// EngineInfo 引擎信息
|
||||
EngineInfo = &struct {
|
||||
Version *string
|
||||
StartTime time.Time //启动时间
|
||||
EnableWaitStream *bool
|
||||
RingSize *int
|
||||
}{&Version, time.Now(), &config.EnableWaitStream, &config.RingSize}
|
||||
StartTime time.Time //启动时间
|
||||
)
|
||||
|
||||
// Run 启动Monibuca引擎
|
||||
func Run(configFile string) (err error) {
|
||||
if runtime.GOOS == "windows" {
|
||||
ioutil.WriteFile("shutdown.bat", []byte(fmt.Sprintf("taskkill /pid %d -t -f", os.Getpid())), 0777)
|
||||
} else {
|
||||
ioutil.WriteFile("shutdown.sh", []byte(fmt.Sprintf("kill -9 %d", os.Getpid())), 0777)
|
||||
}
|
||||
_, enginePath, _, _ := runtime.Caller(0)
|
||||
if parts := strings.Split(filepath.Dir(enginePath), "@"); len(parts) > 1 {
|
||||
Version = parts[len(parts)-1]
|
||||
}
|
||||
err = util.CreateShutdownScript()
|
||||
StartTime = time.Now()
|
||||
if ConfigRaw, err = ioutil.ReadFile(configFile); err != nil {
|
||||
Print(Red("read config file error:"), err)
|
||||
return
|
||||
}
|
||||
Print(BgGreen(Black("Ⓜ start monibuca ")), BrightBlue(Version))
|
||||
go Summary.StartSummary()
|
||||
Print(BgGreen(Black("Ⓜ starting monibuca ")), BrightBlue(Version))
|
||||
var cg map[string]interface{}
|
||||
if _, err = toml.Decode(string(ConfigRaw), &cg); err == nil {
|
||||
if cfg, ok := cg["Monibuca"]; ok {
|
||||
if cfg, ok := cg["Engine"]; ok {
|
||||
b, _ := json.Marshal(cfg)
|
||||
if err = json.Unmarshal(b, config); err != nil {
|
||||
log.Println(err)
|
||||
|
Reference in New Issue
Block a user