
Capture browser user-agent & other useful information for a WebRTC session in Wowza
Capturing browser information (User-Agent string) is sometimes vital for logging system usage statistics as well as sometimes for security purposes. Along with this, there are many other useful pieces of information provided by browser headers. While other protocols such as RTMP, RTSP can provide limited information about the client, HLS & WebRTC can make use of default browser headers to pass in all that. The snippet given below demonstrates how to read headers from a Wowza WebRTC session via the WebSocket session.
if(session.isWebRTC()) { Map<String, String> headers = session.getWebRTCSession().getCommandRequest().getWebSocketSession().getHeaderMap(); for (Entry<String, String> header : headers.entrySet()) { String key = header.getKey(); String value = header.getValue(); getLogger().info("key = " + key + ":" + "value = " + value); } }
This code can be used inside the onRTPSessionCreate handler of or in the publish/play handlers (provided you get the RTPSession object from the IMediaStream).
SAMPLE OUTPUT FROM THE SNIPPET ABOVE
INFO server comment - key = method:value = GET INFO server comment - key = upgrade:value = websocket INFO server comment - key = accept-language:value = en-IN,en;q=0.9,bn-IN;q=0.8,bn;q=0.7,en-GB;q=0.6,en-US;q=0.5 INFO server comment - key = sec-websocket-extensions:value = permessage-deflate; client_max_window_bits INFO server comment - key = origin:value = https://www.wowza.com INFO server comment - key = sec-websocket-version:value = 13 INFO server comment - key = uri:value = GET /webrtc-session.json HTTP/1.1 INFO server comment - key = pragma:value = no-cache INFO server comment - key = protocol:value = HTTP/1.1 INFO server comment - key = context:value = webrtc-session.json INFO server comment - key = host:value = example.domain.com:1443 INFO server comment - key = connection:value = Upgrade INFO server comment - key = sec-websocket-key:value = KCTC2+45k2TlJNtQSn+d6Q== INFO server comment - key = cache-control:value = no-cache INFO server comment - key = accept-encoding:value = gzip, deflate, br INFO server comment - key = user-agent:value = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36