Support setting bandwidth for proxy publishers.

This commit is contained in:
Joachim Bauch 2025-11-06 12:58:57 +01:00
commit 29361d4681
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
3 changed files with 50 additions and 0 deletions

View file

@ -1231,6 +1231,37 @@ func (s *ProxyServer) processCommand(ctx context.Context, client *ProxyClient, s
client.Close(context.Background())
}()
response := &proxy.ServerMessage{
Id: message.Id,
Type: "command",
Command: &proxy.CommandServerMessage{
Id: cmd.ClientId,
},
}
session.sendMessage(response)
case "update-bandwidth":
client := s.GetClient(cmd.ClientId)
if client == nil {
session.sendMessage(message.NewErrorServerMessage(UnknownClient))
return
}
clientWithBandwidth, ok := client.(sfu.ClientWithBandwidth)
if !ok {
session.sendMessage(message.NewErrorServerMessage(UnknownClient))
return
}
if cmd.Bandwidth != 0 {
ctx2, cancel := context.WithTimeout(ctx, s.mcuTimeout)
defer cancel()
if err := clientWithBandwidth.SetBandwidth(ctx2, cmd.Bandwidth); err != nil {
session.sendMessage(message.NewWrappedErrorServerMessage(err))
return
}
}
response := &proxy.ServerMessage{
Id: message.Id,
Type: "command",

View file

@ -219,6 +219,9 @@ type CommandClientMessage struct {
Hostname string `json:"hostname,omitempty"`
Port int `json:"port,omitempty"`
RtcpPort int `json:"rtcpPort,omitempty"`
// Bandwidth is set if Type is "update-bandwidth"
Bandwidth api.Bandwidth `json:"bandwidth,omitempty"`
}
func (m *CommandClientMessage) CheckValid() error {

View file

@ -139,6 +139,22 @@ func (c *proxyPubSubCommon) Bandwidth() *sfu.ClientBandwidthInfo {
return c.bandwidth.Load()
}
func (c *proxyPubSubCommon) SetBandwidth(ctx context.Context, bandwidth api.Bandwidth) error {
_, _, err := c.conn.performSyncRequest(ctx, &proxy.ClientMessage{
Type: "command",
Command: &proxy.CommandClientMessage{
ClientId: c.proxyId,
Type: "update-bandwidth",
Bandwidth: bandwidth,
},
})
if err != nil {
return err
}
return nil
}
func (c *proxyPubSubCommon) doSendMessage(ctx context.Context, msg *proxy.ClientMessage, callback func(error, api.StringMap)) {
c.conn.performAsyncRequest(ctx, msg, func(err error, response *proxy.ServerMessage) {
if err != nil {