Exemplo n.º 1
0
func InitServer() error {
	if len(config.Config.Apps) == 0 {
		return errors.New("empty app list.")
	}
	for n, application := range config.Config.Apps {
		var (
			// first we should to make a source manage.
			sources = source.NewSourcerManage()
			// second init a lua.
			cb = initLua(application.LuaPath)

			enbleIM  bool
			imServer *im.IMServer
		)

		// IM & HTTP use one port, by default.
		mux := http.NewServeMux()
		// start http server listen.
		for _, addr := range application.HTTP.Listen {
			go http.ListenAndServe(addr, mux)
		}
		if application.HTTP.Flv.Enble {
			glog.Infof("Load HTTP-FLV serve:%v", n)
			serverHttp.InitHTTPFlv(mux, application.Name, sources, cb)
		}
		if application.HTTP.Im.Enble {
			enbleIM = true
			glog.Infof("Load IM serve:%v", n)
			imServer = im.NewIMServer(cb)
			imServer.Init(mux)
		}
		if application.DemoServer.Enble {
			serverHttp.InitHTTP(mux, sources, imServer)
		}

		if application.RTMP.Enble {
			glog.Infof("Load RTMP serve:%v", n)
			// start rtmp publisher server
			for _, addr := range application.RTMP.Listen {
				s := rtmpServer.NewSrsServer(addr, cb, sources, enbleIM, imServer)
				go s.Serve()
			}
		} else {
			// should throws a panic.
			panic("App not has rtmp.")
		}
	}
	return nil
}
Exemplo n.º 2
0
func main() {
	flag.Parse()
	defer glog.Flush()
	if err := flag.Set("logtostderr", "true"); err != nil {
		panic(err)
	}
	r := NewSrsServer()
	r.PrintInfo()
	// init http server
	if err := myhttp.InitHTTP(); err != nil {
		panic(err)
	}
	go func() {
		if err := http.ListenAndServe(":9090", nil); err != nil {
			panic(err)
		}
	}()
	r.Serve()
}