Nexmo / wsbridge

Other
25 stars 18 forks source link

Sending audio from own application not working #10

Closed sk2andy closed 4 years ago

sk2andy commented 4 years ago

I want to write a simple echo bot and managed to receive audio with your provided bridge. Every time I receive binary data I directly return the same data which should lead to a hearable echo or am I wrong? Unfortunately I do not receive the echo with my SIP Softphone (Linphone)

Do I misunderstand the documentation?:

WSBridge expects data from the WebSocket correctly packetized, according to the content-type set on the connection.

here is my (CSharp Net Core) Code:

while (!result.CloseStatus.HasValue)
{
    result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);

    if(result.MessageType == WebSocketMessageType.Binary)
    {
        await webSocket.SendAsync(new ArraySegment<byte>(buffer, 0, buffer.Length), WebSocketMessageType.Binary, result.EndOfMessage, CancellationToken.None);
    }
}

excerpt from Freeswitch logs:

2020-08-20 11:28:10.323205 [DEBUG] mod_wsbridge.c:478 WebSockets client received frame of size [640]
2020-08-20 11:28:10.323205 [DEBUG] mod_wsbridge.c:248 8 lws_is_final_fragment: final 1, rx pk length 0, draining 0

2020-08-20 11:28:10.323205 [DEBUG] mod_wsbridge.c:545 RX FLOW CONTROL: [throttling] wsi [0x7fe78000ac30]
2020-08-20 11:28:10.323205 [DEBUG] mod_wsbridge.c:248 8 lws_rx_flow_control: 0x7fe78000ac30 0x0

2020-08-20 11:28:10.323205 [DEBUG] mod_wsbridge.c:248 8 lws_rx_flow_control: 0x0x7fe78000ac30: bitmap 0x1: en 0x4001, ch 0x2

2020-08-20 11:28:10.323205 [DEBUG] mod_wsbridge.c:248 8 rxflow: wsi 0x7fe78000ac30 change_to 0

2020-08-20 11:28:10.323205 [DEBUG] mod_wsbridge.c:248 8 lws_read: read_ok, used 644

2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:293 RX FLOW CONTROL: [enable receiving] wsi [0x7fe78000ac30]
2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:248 8 lws_rx_flow_control: 0x7fe78000ac30 0x1

2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:248 8 lws_rx_flow_control: 0x0x7fe78000ac30: bitmap 0x0: en 0x6001, ch 0x3

2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:248 8 rxflow: wsi 0x7fe78000ac30 change_to 1

2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:478 WebSockets client received frame of size [640]
2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:248 8 lws_is_final_fragment: final 1, rx pk length 0, draining 0

2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:545 RX FLOW CONTROL: [throttling] wsi [0x7fe78000ac30]
2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:248 8 lws_rx_flow_control: 0x7fe78000ac30 0x0

2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:248 8 lws_rx_flow_control: 0x0x7fe78000ac30: bitmap 0x1: en 0x4001, ch 0x2

2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:248 8 rxflow: wsi 0x7fe78000ac30 change_to 0

2020-08-20 11:28:10.343205 [DEBUG] mod_wsbridge.c:248 8 lws_read: read_ok, used 644

2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:293 RX FLOW CONTROL: [enable receiving] wsi [0x7fe78000ac30]
2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:248 8 lws_rx_flow_control: 0x7fe78000ac30 0x1

2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:248 8 lws_rx_flow_control: 0x0x7fe78000ac30: bitmap 0x0: en 0x6001, ch 0x3

2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:248 8 rxflow: wsi 0x7fe78000ac30 change_to 1

2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:478 WebSockets client received frame of size [640]
2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:248 8 lws_is_final_fragment: final 1, rx pk length 0, draining 0

2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:545 RX FLOW CONTROL: [throttling] wsi [0x7fe78000ac30]
2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:248 8 lws_rx_flow_control: 0x7fe78000ac30 0x0

2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:248 8 lws_rx_flow_control: 0x0x7fe78000ac30: bitmap 0x1: en 0x4001, ch 0x2

2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:248 8 rxflow: wsi 0x7fe78000ac30 change_to 0

2020-08-20 11:28:10.363205 [DEBUG] mod_wsbridge.c:248 8 lws_read: read_ok, used 644
csiwek commented 4 years ago

Hi, I'm not familiar with C# implementation of websocket but it should just work. Perhaps, because you are sending your packets asynchronously with SendAsync, you are triggering WS flow control. You should read the description of how WS flow-control.

Here is our Python WS echo example (which is connected to Vonage API NCCO but you can get an idea) https://github.com/Nexmo/python-websocket-echo-server/blob/master/server.py Feel free to try out if your code works with our API.

I also want to point out that this code is no longer maintained.

sk2andy commented 4 years ago

I believe the mod is not working with Freeswitch version 1.10. I tried 1.6.20 and it worked fine

csiwek commented 4 years ago

This is highly possible. this module was never tested with FS > 1.6.21