######## Websocket module ######## tcp_accept_no_cl=yes ######## Basic HTTP request handling ######## loadmodule "xhttp.so" ######## Websocket module ######## loadmodule "websocket.so" modparam("websocket", "keepalive_mechanism", 1) modparam("websocket", "keepalive_timeout", 30) modparam("websocket", "keepalive_processes", 1) modparam("websocket", "keepalive_interval", 1) modparam("websocket", "ping_application_data", "Kazoo encourages you to keep alive") modparam("websocket", "sub_protocols", 1) route[HANDLE_WEBSOCKETS] { # Do NAT traversal stuff for requests from a WebSocket # connection - even if it is not behind a NAT! # This won't be needed in the future if Kamailio and the # WebSocket client support Outbound and Path. if (nat_uac_test(64)) { xlog("L_INFO", "$ci|log|this is a websocket request\n"); force_rport(); if (is_method("REGISTER")) { fix_nated_register(); } else { if (!add_contact_alias()) { xlog("L_INFO", "$ci|stop|error aliasing contact <$ct>\n"); sl_send_reply("400", "Bad Request"); exit; } } } } route[NAT_WEBSOCKETS_CORRECT] { # Do NAT traversal stuff for replies to a WebSocket connection # - even if it is not behind a NAT! # This won't be needed in the future if Kamailio and the # WebSocket client support Outbound and Path. if (nat_uac_test(64)) { xlog("L_INFO", "$ci|log|this is a websocket request\n"); add_contact_alias(); } } event_route[xhttp:request] { xlog("L_INFO", "HTTP Request Received\n"); set_reply_close(); set_reply_no_connect(); if ($hdr(Upgrade) =~ "websocket" && $hdr(Connection) =~ "Upgrade" && $rm =~ "GET") { xlog("L_INFO", "websocket request from $si:$sp received\n"); # Validate Host - make sure the client is using the correct # alias for WebSockets if ($hdr(Host) == $null || !is_myself("sip:" + $hdr(Host))) { xlog("L_WARN", "websocket request had bad host $hdr(Host)\n"); xhttp_reply("403", "Forbidden", "", ""); exit; } # ws_handle_handshake() exits (no further configuration file # processing of the request) when complete. if (ws_handle_handshake()) { exit; } } xhttp_reply("404", "Not Found", "", ""); } event_route[websocket:closed] { xlog("L_INFO", "websocket connection from $si:$sp has closed\n"); }