@@ -1745,3 +1745,77 @@ func Test_ProxyPublisherToken(t *testing.T) {
17451745
17461746 defer sub .Close (context .Background ())
17471747}
1748+
1749+ func Test_ProxyUpdateBandwidth (t * testing.T ) {
1750+ t .Parallel ()
1751+ require := require .New (t )
1752+ assert := assert .New (t )
1753+ server := testserver .NewProxyServerForTest (t , "DE" )
1754+ mcu , _ := newMcuProxyForTestWithOptions (t , testserver.ProxyTestOptions {
1755+ Servers : []testserver.ProxyTestServer {server },
1756+ }, 0 , nil )
1757+
1758+ connections := mcu .getSortedConnections (nil )
1759+ require .Len (connections , 1 )
1760+
1761+ ctx , cancel := context .WithTimeout (t .Context (), testTimeout )
1762+ defer cancel ()
1763+
1764+ pubId := api .PublicSessionId ("the-publisher" )
1765+ pubSid := "1234567890"
1766+ pubListener := mock .NewListener (pubId + "-public" )
1767+ pubInitiator := mock .NewInitiator ("DE" )
1768+
1769+ pub , err := mcu .NewPublisher (ctx , pubListener , pubId , pubSid , sfu .StreamTypeVideo , sfu.NewPublisherSettings {
1770+ MediaTypes : sfu .MediaTypeVideo | sfu .MediaTypeAudio ,
1771+ }, pubInitiator )
1772+ require .NoError (err )
1773+
1774+ defer pub .Close (context .Background ())
1775+
1776+ pubBw , ok := pub .(sfu.ClientWithBandwidth )
1777+ require .True (ok )
1778+
1779+ assert .Nil (pubBw .Bandwidth ())
1780+
1781+ client := server .GetSingleClient ()
1782+ require .NotNil (client )
1783+
1784+ client .SendMessage (& proxy.ServerMessage {
1785+ Type : "event" ,
1786+ Event : & proxy.EventServerMessage {
1787+ Type : "update-load" ,
1788+ ClientBandwidths : map [string ]proxy.EventServerBandwidth {
1789+ pub .Id (): {
1790+ Sent : 1000 ,
1791+ Received : 2000 ,
1792+ },
1793+ },
1794+ },
1795+ })
1796+
1797+ // Wait until message has been processed
1798+ bw := pubBw .Bandwidth ()
1799+ for bw == nil {
1800+ require .NoError (ctx .Err ())
1801+ time .Sleep (time .Millisecond )
1802+ bw = pubBw .Bandwidth ()
1803+ }
1804+
1805+ if assert .NotNil (bw ) {
1806+ assert .EqualValues (1000 , bw .Sent )
1807+ assert .EqualValues (2000 , bw .Received )
1808+ }
1809+
1810+ if assert .NoError (pubBw .SetBandwidth (ctx , 3000 )) {
1811+ if serverPub := server .GetPublisher (api .PublicSessionId (pub .Id ())); assert .NotNil (serverPub ) {
1812+ bw := serverPub .Bandwidth ()
1813+ for bw == 0 {
1814+ require .NoError (ctx .Err ())
1815+ time .Sleep (time .Millisecond )
1816+ bw = serverPub .Bandwidth ()
1817+ }
1818+ assert .EqualValues (3000 , bw )
1819+ }
1820+ }
1821+ }
0 commit comments