chan_websocket: Handle incoming CONTINUATION frames.

chan_websocket now tells res_http_websocket to accumulate incoming CONTINUATION
frames into 1024 byte TEXT or BINARY frames.

Resolves: #1941
This commit is contained in:
George Joseph
2026-05-20 09:16:48 -06:00
parent d1ad891488
commit ca2c45dabb

View File

@@ -1096,7 +1096,14 @@ static int read_from_ws_and_queue(struct websocket_pvt *instance)
return process_text_message(instance, payload, payload_len);
}
if (opcode == AST_WEBSOCKET_OPCODE_PING || opcode == AST_WEBSOCKET_OPCODE_PONG) {
/*
* PINGs and PONGs will have been handled by res_http_websocket.
* We also need to ignore CONTINUATION frames as they will be accumulated
* by res_http_websocket until the threshold set in websocket_handoff_to_channel()
* is reached, then it will send us a TEXT or BINARY frame.
*/
if (opcode == AST_WEBSOCKET_OPCODE_PING || opcode == AST_WEBSOCKET_OPCODE_PONG
|| opcode == AST_WEBSOCKET_OPCODE_CONTINUATION) {
return 0;
}
@@ -1139,6 +1146,13 @@ static int websocket_handoff_to_channel(struct websocket_pvt *instance)
ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on websocket connection: %s\n", strerror(errno));
}
/*
* Tell res_http_websocket to accumulate incoming WebSocket CONTINUATION frames
* into chunks of 1024 bytes and send us a TEXT or BINARY frame when the threshold
* is reached.
*/
ast_websocket_reconstruct_enable(instance->websocket, 1024);
ast_channel_set_fd(instance->channel, WS_WEBSOCKET_FDNO, ast_websocket_fd(instance->websocket));
res = send_event(instance, MEDIA_START);