From 50bb04af5e2a0f1076d9f779a8cebf51f9a9a6c9 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 12 Apr 2020 17:36:27 +0200 Subject: [PATCH] Apply video policy on proxy --- callconfig.go | 4 ++++ relay.go | 19 ++++++++++++++----- ws.go | 2 ++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/callconfig.go b/callconfig.go index 95075f3..dc9cb89 100644 --- a/callconfig.go +++ b/callconfig.go @@ -12,6 +12,7 @@ import ( type callConfig struct { iceServers []webrtc.ICEServer + allowVideo bool } // This configuration is intialized as soon as @@ -28,4 +29,7 @@ func setCallConfig(data map[string]interface{}) { URLs: []string{server.(string)}, }) } + + // Update allow video status + callConf.allowVideo = data["allowVideo"].(bool) } diff --git a/relay.go b/relay.go index 7822a04..82d05cf 100644 --- a/relay.go +++ b/relay.go @@ -261,11 +261,13 @@ func newCall(mainOffer receivedSignal, r *activeRelay) { }) // Allow us to receive 1 audio & 1 video track - if _, err = mainPeerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo, - webrtc.RtpTransceiverInit{Direction: webrtc.RTPTransceiverDirectionRecvonly}); err != nil { - log.Println("Error: could not prepare to receive video track!", err) - askForClose(r) - return + if callConf.allowVideo { + if _, err = mainPeerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo, + webrtc.RtpTransceiverInit{Direction: webrtc.RTPTransceiverDirectionRecvonly}); err != nil { + log.Println("Error: could not prepare to receive video track!", err) + askForClose(r) + return + } } if _, err = mainPeerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio, @@ -304,6 +306,13 @@ func newCall(mainOffer receivedSignal, r *activeRelay) { trackID := "audio" trackLabel := "pion" // We need only one track label if remoteTrack.Kind() == webrtc.RTPCodecTypeVideo { + + // Check if video calls are allowed + if !callConf.allowVideo { + log.Printf("Blocked a video stream! Call hash: %s", r.callHash) + return + } + trackID = "video" // We need two different track ids } diff --git a/ws.go b/ws.go index ba5929f..fdc694f 100644 --- a/ws.go +++ b/ws.go @@ -6,6 +6,7 @@ package main import ( "encoding/json" + "fmt" "log" "os" "os/signal" @@ -76,6 +77,7 @@ func openWs(conf *Config) { case "config": println("Got call configuration") setCallConfig(msg.Data.(map[string]interface{})) + fmt.Println("Enable video calls:", callConf.allowVideo) break // Remote signal