client to handle publishing tracks on connection

This commit is contained in:
David Zhao
2020-11-13 12:52:20 -08:00
parent c618f8c42f
commit 606e1ec70c
+32 -9
View File
@@ -28,12 +28,21 @@ var (
roomFlag,
rtcHostFlag,
&cli.StringFlag{
Name: "token",
Name: "token",
Usage: "room token, not required in dev mode",
},
&cli.StringFlag{
Name: "peer-id",
Value: "peer",
},
&cli.StringFlag{
Name: "audio",
Usage: "an ogg file to publish upon connection",
},
&cli.StringFlag{
Name: "video",
Usage: "an ivf file to publish upon connection",
},
},
},
}
@@ -65,15 +74,17 @@ func joinRoom(c *cli.Context) error {
return err
}
// signal to stop client
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
handleSignals(rc)
go func() {
sig := <-sigChan
log.Infow("exit requested, shutting down", "signal", sig)
rc.Stop()
}()
// add tracks if needed
audioFile := c.String("audio")
videoFile := c.String("video")
if audioFile != "" {
rc.AddTrack(audioFile, webrtc.RTPCodecTypeAudio, "audio", filepath.Base(audioFile))
}
if videoFile != "" {
rc.AddTrack(videoFile, webrtc.RTPCodecTypeVideo, "video", filepath.Base(videoFile))
}
// start loop to detect input
go func() {
@@ -184,3 +195,15 @@ func handleAddMedia(rc *client.RTCClient, isAudio bool) error {
}
return err
}
func handleSignals(rc *client.RTCClient) {
// signal to stop client
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
sig := <-sigChan
logger.GetLogger().Infow("exit requested, shutting down", "signal", sig)
rc.Stop()
}()
}