#include "testlib.h" DValue websocket_suite_event(Request& context, String type, String nonce) { DValue event; event["type"] = type; event["nonce"] = nonce; event["connection_id"] = ws_connection_id(); event["scope"] = first(context.params["DOCUMENT_URI"], ws_scope()); event["online"] = (f64)ws_connection_count(); event["opcode"] = (f64)ws_opcode(); event["binary"] = ws_is_binary() ? "true" : "false"; return(event); } RENDER(Request& context) { String ws_url = context.params["DOCUMENT_URI"]; site_tests_page_start("WebSockets", "Browser-driven handshake and broadcast checks for ws_* helpers on the current .ws.uce endpoint."); ?>
This page self-tests in the browser: it opens a socket to itself, waits for a targeted hello acknowledgment, then verifies a broadcast acknowledgment from the same endpoint.
hello acknowledgmentWAIT
connecting...
broadcast acknowledgmentWAIT
waiting...
connection stateWAIT
opening websocket...