Apply video policy on proxy

This commit is contained in:
Pierre HUBERT 2020-04-12 17:36:27 +02:00
parent a98a65936f
commit 50bb04af5e
3 changed files with 20 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import (
type callConfig struct { type callConfig struct {
iceServers []webrtc.ICEServer iceServers []webrtc.ICEServer
allowVideo bool
} }
// This configuration is intialized as soon as // This configuration is intialized as soon as
@ -28,4 +29,7 @@ func setCallConfig(data map[string]interface{}) {
URLs: []string{server.(string)}, URLs: []string{server.(string)},
}) })
} }
// Update allow video status
callConf.allowVideo = data["allowVideo"].(bool)
} }

View File

@ -261,12 +261,14 @@ func newCall(mainOffer receivedSignal, r *activeRelay) {
}) })
// Allow us to receive 1 audio & 1 video track // Allow us to receive 1 audio & 1 video track
if callConf.allowVideo {
if _, err = mainPeerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo, if _, err = mainPeerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo,
webrtc.RtpTransceiverInit{Direction: webrtc.RTPTransceiverDirectionRecvonly}); err != nil { webrtc.RtpTransceiverInit{Direction: webrtc.RTPTransceiverDirectionRecvonly}); err != nil {
log.Println("Error: could not prepare to receive video track!", err) log.Println("Error: could not prepare to receive video track!", err)
askForClose(r) askForClose(r)
return return
} }
}
if _, err = mainPeerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio, if _, err = mainPeerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio,
webrtc.RtpTransceiverInit{Direction: webrtc.RTPTransceiverDirectionRecvonly}); err != nil { webrtc.RtpTransceiverInit{Direction: webrtc.RTPTransceiverDirectionRecvonly}); err != nil {
@ -304,6 +306,13 @@ func newCall(mainOffer receivedSignal, r *activeRelay) {
trackID := "audio" trackID := "audio"
trackLabel := "pion" // We need only one track label trackLabel := "pion" // We need only one track label
if remoteTrack.Kind() == webrtc.RTPCodecTypeVideo { 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 trackID = "video" // We need two different track ids
} }

2
ws.go
View File

@ -6,6 +6,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
"log" "log"
"os" "os"
"os/signal" "os/signal"
@ -76,6 +77,7 @@ func openWs(conf *Config) {
case "config": case "config":
println("Got call configuration") println("Got call configuration")
setCallConfig(msg.Data.(map[string]interface{})) setCallConfig(msg.Data.(map[string]interface{}))
fmt.Println("Enable video calls:", callConf.allowVideo)
break break
// Remote signal // Remote signal