1、修改janus的源码, 添加消息抓包打印代码:
Index: transports/janus_http.c
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- transports/janus_http.c (date 1557885542000)
+++ transports/janus_http.c (date 1558604642000)
@@ -1002,7 +1002,11 @@
}
int janus_http_send_message(janus_transport_session *transport, void *request_id, gboolean admin, json_t *message) {
- JANUS_LOG(LOG_HUGE, "Got a %s API %s to send (%p)\n", admin ? "admin" : "Janus", request_id ? "response" : "event", transport);
+ char *dumps = json_dumps(message, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
+ printf("response:%s\r\n",dumps);
+ free(dumps);
+
+ JANUS_LOG(LOG_HUGE, "Got a %s API %s to send (%p)\n", admin ? "admin" : "Janus", request_id ? "response" : "event", transport);
if(message == NULL) {
JANUS_LOG(LOG_ERR, "No message...\n");
return -1;
@@ -1363,7 +1367,11 @@
json_object_set_new(root, "apisecret", json_string(secret));
if(token)
json_object_set_new(root, "token", json_string(token));
- gateway->incoming_request(&janus_http_transport, ts, (void *)keepalive_id, FALSE, root, NULL);
+
+ char *dumps = json_dumps(root, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
+ printf("%s %s\r\n %s\r\n", method, url,dumps);
+ free(dumps);
+ gateway->incoming_request(&janus_http_transport, ts, (void *)keepalive_id, FALSE, root, NULL);
/* Ok, go on */
if(handle_path) {
char *location = g_malloc(strlen(ws_path) + strlen(session_path) + 2);
@@ -1477,6 +1485,10 @@
/* Suspend the connection and pass the ball to the core */
JANUS_LOG(LOG_HUGE, "Forwarding request to the core (%p)\n", ts);
+ char *dumps = json_dumps(root, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
+ printf("%s %s\r\n %s\r\n", method, url,dumps);
+ free(dumps);
+
gateway->incoming_request(&janus_http_transport, ts, ts, FALSE, root, &error);
/* Wait for a response (but not forever) */
#ifndef USE_PTHREAD_MUTEX
2、编译代码,运行janus
# -d 2目的是为了去除过多干扰日志
./janue -d 2
3、启动http文件服务器,并且设置http根目录至janus的html目录(以ZLMediaKit的test_server为例):
4、打开浏览器,访问http://127.0.0.1/echotest.html
5、点击start按钮开始测试:
6、点击stop按钮关闭测试:
7、在shell按Ctrl+C关闭服务器,刷新出日志:
POST /janus
{
"janus": "create",
"transaction": "6IyFGbTNQloR"
}
response:{
"janus": "success",
"transaction": "6IyFGbTNQloR",
"data": {
"id": 2171134171642143
}
}
GET /janus/2171134171642143
{
"janus": "keepalive",
"session_id": 2171134171642143,
"transaction": "bUoeIFsBKYJ"
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "bUoeIFsBKYJ"
}
POST /janus/2171134171642143
{
"janus": "attach",
"plugin": "janus.plugin.echotest",
"opaque_id": "echotest-raSB1GZPdBdj",
"transaction": "mGYLG93fdmTS",
"session_id": 2171134171642143
}
response:{
"janus": "success",
"session_id": 2171134171642143,
"transaction": "mGYLG93fdmTS",
"data": {
"id": 3157394748811091
}
}
POST /janus/2171134171642143/3157394748811091
{
"janus": "message",
"body": {
"audio": true,
"video": true
},
"transaction": "LhCrJHMyAYrm",
"session_id": 2171134171642143,
"handle_id": 3157394748811091
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "LhCrJHMyAYrm",
"hint": "I'm taking my time!"
}
response:{
"janus": "event",
"session_id": 2171134171642143,
"transaction": "LhCrJHMyAYrm",
"sender": 3157394748811091,
"plugindata": {
"plugin": "janus.plugin.echotest",
"data": {
"echotest": "event",
"result": "ok"
}
}
}
GET /janus/2171134171642143
{
"janus": "keepalive",
"session_id": 2171134171642143,
"transaction": "cvKVo8xJY96"
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "cvKVo8xJY96"
}
POST /janus/2171134171642143/3157394748811091
{
"janus": "message",
"body": {
"audio": true,
"video": true
},
"transaction": "cMGGqkzXTSiW",
"jsep": {
"type": "offer",
"sdp": "v=0\r\no=- 2425166536180571528 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0 1 2\r\na=msid-semantic: WMS Symce8HMZerlzVAh66olEPorWLU3PDiCsEWz\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:8bex\r\na=ice-pwd:rymrVtOg6B+FDy5NKkF8g+w7\r\na=ice-options:trickle\r\na=fingerprint:sha-256 7E:D4:79:F1:67:D1:75:DE:DF:59:A6:47:A7:5F:4B:0F:3C:98:0A:9F:5C:4A:44:80:3E:89:4D:86:8C:0C:0E:5A\r\na=setup:actpass\r\na=mid:0\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=extmap:2 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id\r\na=extmap:5 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id\r\na=sendrecv\r\na=msid:Symce8HMZerlzVAh66olEPorWLU3PDiCsEWz a3d03df7-f3d0-45ff-b996-903b7332ef22\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:112 telephone-event/32000\r\na=rtpmap:113 telephone-event/16000\r\na=rtpmap:126 telephone-event/8000\r\na=ssrc:2661603461 cname:8Y7yoj/LRGDlVnC5\r\na=ssrc:2661603461 msid:Symce8HMZerlzVAh66olEPorWLU3PDiCsEWz a3d03df7-f3d0-45ff-b996-903b7332ef22\r\na=ssrc:2661603461 mslabel:Symce8HMZerlzVAh66olEPorWLU3PDiCsEWz\r\na=ssrc:2661603461 label:a3d03df7-f3d0-45ff-b996-903b7332ef22\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 122 127 121 125 107 108 109 124 120 123 119 114 115 116\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:8bex\r\na=ice-pwd:rymrVtOg6B+FDy5NKkF8g+w7\r\na=ice-options:trickle\r\na=fingerprint:sha-256 7E:D4:79:F1:67:D1:75:DE:DF:59:A6:47:A7:5F:4B:0F:3C:98:0A:9F:5C:4A:44:80:3E:89:4D:86:8C:0C:0E:5A\r\na=setup:actpass\r\na=mid:1\r\na=extmap:14 urn:ietf:params:rtp-hdrext:toffset\r\na=extmap:13 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:12 urn:3gpp:video-orientation\r\na=extmap:2 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:11 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\na=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\na=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\na=extmap:8 http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07\r\na=extmap:9 http://www.webrtc.org/experiments/rtp-hdrext/color-space\r\na=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id\r\na=extmap:5 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id\r\na=sendrecv\r\na=msid:Symce8HMZerlzVAh66olEPorWLU3PDiCsEWz b8468134-af3d-4c17-a92e-f267d86c2061\r\na=rtcp-mux\r\na=rtcp-rsize\r\na=rtpmap:96 VP8/90000\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=rtpmap:98 VP9/90000\r\na=rtcp-fb:98 goog-remb\r\na=rtcp-fb:98 transport-cc\r\na=rtcp-fb:98 ccm fir\r\na=rtcp-fb:98 nack\r\na=rtcp-fb:98 nack pli\r\na=fmtp:98 profile-id=0\r\na=rtpmap:99 rtx/90000\r\na=fmtp:99 apt=98\r\na=rtpmap:100 VP9/90000\r\na=rtcp-fb:100 goog-remb\r\na=rtcp-fb:100 transport-cc\r\na=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 nack pli\r\na=fmtp:100 profile-id=2\r\na=rtpmap:101 rtx/90000\r\na=fmtp:101 apt=100\r\na=rtpmap:102 H264/90000\r\na=rtcp-fb:102 goog-remb\r\na=rtcp-fb:102 transport-cc\r\na=rtcp-fb:102 ccm fir\r\na=rtcp-fb:102 nack\r\na=rtcp-fb:102 nack pli\r\na=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\na=rtpmap:122 rtx/90000\r\na=fmtp:122 apt=102\r\na=rtpmap:127 H264/90000\r\na=rtcp-fb:127 goog-remb\r\na=rtcp-fb:127 transport-cc\r\na=rtcp-fb:127 ccm fir\r\na=rtcp-fb:127 nack\r\na=rtcp-fb:127 nack pli\r\na=fmtp:127 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f\r\na=rtpmap:121 rtx/90000\r\na=fmtp:121 apt=127\r\na=rtpmap:125 H264/90000\r\na=rtcp-fb:125 goog-remb\r\na=rtcp-fb:125 transport-cc\r\na=rtcp-fb:125 ccm fir\r\na=rtcp-fb:125 nack\r\na=rtcp-fb:125 nack pli\r\na=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\na=rtpmap:107 rtx/90000\r\na=fmtp:107 apt=125\r\na=rtpmap:108 H264/90000\r\na=rtcp-fb:108 goog-remb\r\na=rtcp-fb:108 transport-cc\r\na=rtcp-fb:108 ccm fir\r\na=rtcp-fb:108 nack\r\na=rtcp-fb:108 nack pli\r\na=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f\r\na=rtpmap:109 rtx/90000\r\na=fmtp:109 apt=108\r\na=rtpmap:124 H264/90000\r\na=rtcp-fb:124 goog-remb\r\na=rtcp-fb:124 transport-cc\r\na=rtcp-fb:124 ccm fir\r\na=rtcp-fb:124 nack\r\na=rtcp-fb:124 nack pli\r\na=fmtp:124 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d0032\r\na=rtpmap:120 rtx/90000\r\na=fmtp:120 apt=124\r\na=rtpmap:123 H264/90000\r\na=rtcp-fb:123 goog-remb\r\na=rtcp-fb:123 transport-cc\r\na=rtcp-fb:123 ccm fir\r\na=rtcp-fb:123 nack\r\na=rtcp-fb:123 nack pli\r\na=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640032\r\na=rtpmap:119 rtx/90000\r\na=fmtp:119 apt=123\r\na=rtpmap:114 red/90000\r\na=rtpmap:115 rtx/90000\r\na=fmtp:115 apt=114\r\na=rtpmap:116 ulpfec/90000\r\na=ssrc-group:FID 1696664830 2006713689\r\na=ssrc:1696664830 cname:8Y7yoj/LRGDlVnC5\r\na=ssrc:1696664830 msid:Symce8HMZerlzVAh66olEPorWLU3PDiCsEWz b8468134-af3d-4c17-a92e-f267d86c2061\r\na=ssrc:1696664830 mslabel:Symce8HMZerlzVAh66olEPorWLU3PDiCsEWz\r\na=ssrc:1696664830 label:b8468134-af3d-4c17-a92e-f267d86c2061\r\na=ssrc:2006713689 cname:8Y7yoj/LRGDlVnC5\r\na=ssrc:2006713689 msid:Symce8HMZerlzVAh66olEPorWLU3PDiCsEWz b8468134-af3d-4c17-a92e-f267d86c2061\r\na=ssrc:2006713689 mslabel:Symce8HMZerlzVAh66olEPorWLU3PDiCsEWz\r\na=ssrc:2006713689 label:b8468134-af3d-4c17-a92e-f267d86c2061\r\nm=application 9 DTLS/SCTP 5000\r\nc=IN IP4 0.0.0.0\r\na=ice-ufrag:8bex\r\na=ice-pwd:rymrVtOg6B+FDy5NKkF8g+w7\r\na=ice-options:trickle\r\na=fingerprint:sha-256 7E:D4:79:F1:67:D1:75:DE:DF:59:A6:47:A7:5F:4B:0F:3C:98:0A:9F:5C:4A:44:80:3E:89:4D:86:8C:0C:0E:5A\r\na=setup:actpass\r\na=mid:2\r\na=sctpmap:5000 webrtc-datachannel 1024\r\n"
},
"session_id": 2171134171642143,
"handle_id": 3157394748811091
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "cMGGqkzXTSiW",
"hint": "I'm taking my time!"
}
response:{
"janus": "event",
"session_id": 2171134171642143,
"transaction": "cMGGqkzXTSiW",
"sender": 3157394748811091,
"plugindata": {
"plugin": "janus.plugin.echotest",
"data": {
"echotest": "event",
"result": "ok"
}
},
"jsep": {
"type": "answer",
"sdp": "v=0\r\no=- 2425166536180571528 2 IN IP4 192.168.1.26\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0 1 2\r\na=msid-semantic: WMS janus\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111\r\nc=IN IP4 192.168.1.26\r\na=sendrecv\r\na=mid:0\r\na=rtcp-mux\r\na=ice-ufrag:7p7b\r\na=ice-pwd:YGJNBqcDidwrzf56RJH/Zb\r\na=ice-options:trickle\r\na=fingerprint:sha-256 F6:95:AF:C5:F6:4A:47:15:95:69:11:26:25:D3:EC:B7:B9:40:79:36:71:00:0D:44:04:0D:F8:B7:A6:5D:3D:D3\r\na=setup:active\r\na=rtpmap:111 opus/48000/2\r\na=fmtp:111 useinbandfec=1\r\na=extmap:2 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id\r\na=extmap:5 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id\r\na=ssrc:93902734 cname:janus\r\na=ssrc:93902734 msid:janus janusa0\r\na=ssrc:93902734 mslabel:janus\r\na=ssrc:93902734 label:janusa0\r\na=candidate:1 1 udp 2013266431 192.168.1.26 50761 typ host\r\na=end-of-candidates\r\nm=video 9 UDP/TLS/RTP/SAVPF 96\r\nc=IN IP4 192.168.1.26\r\na=sendrecv\r\na=mid:1\r\na=rtcp-mux\r\na=ice-ufrag:7p7b\r\na=ice-pwd:YGJNBqcDidwrzf56RJH/Zb\r\na=ice-options:trickle\r\na=fingerprint:sha-256 F6:95:AF:C5:F6:4A:47:15:95:69:11:26:25:D3:EC:B7:B9:40:79:36:71:00:0D:44:04:0D:F8:B7:A6:5D:3D:D3\r\na=setup:active\r\na=rtpmap:96 VP8/90000\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=extmap:2 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:8 http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07\r\na=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id\r\na=extmap:5 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id\r\na=ssrc:587949668 cname:janus\r\na=ssrc:587949668 msid:janus janusv0\r\na=ssrc:587949668 mslabel:janus\r\na=ssrc:587949668 label:janusv0\r\na=candidate:1 1 udp 2013266431 192.168.1.26 50761 typ host\r\na=end-of-candidates\r\nm=application 9 DTLS/SCTP 5000\r\nc=IN IP4 192.168.1.26\r\na=sendrecv\r\na=sctpmap:5000 webrtc-datachannel 16\r\na=mid:2\r\na=ice-ufrag:7p7b\r\na=ice-pwd:YGJNBqcDidwrzf56RJH/Zb\r\na=ice-options:trickle\r\na=fingerprint:sha-256 F6:95:AF:C5:F6:4A:47:15:95:69:11:26:25:D3:EC:B7:B9:40:79:36:71:00:0D:44:04:0D:F8:B7:A6:5D:3D:D3\r\na=setup:active\r\na=candidate:1 1 udp 2013266431 192.168.1.26 50761 typ host\r\na=end-of-candidates\r\n"
}
}
POST /janus/2171134171642143/3157394748811091
{
"janus": "trickle",
"candidate": {
"candidate": "candidate:2445384676 1 udp 2122260223 192.168.1.26 57156 typ host generation 0 ufrag 8bex network-id 1 network-cost 10",
"sdpMid": "0",
"sdpMLineIndex": 0
},
"transaction": "YVRy9zYwNopZ",
"session_id": 2171134171642143,
"handle_id": 3157394748811091
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "YVRy9zYwNopZ"
}
POST /janus/2171134171642143/3157394748811091
{
"janus": "trickle",
"candidate": {
"candidate": "candidate:2445384676 1 udp 2122260223 192.168.1.26 52495 typ host generation 0 ufrag 8bex network-id 1 network-cost 10",
"sdpMid": "1",
"sdpMLineIndex": 1
},
"transaction": "ADl5HLFwRhD8",
"session_id": 2171134171642143,
"handle_id": 3157394748811091
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "ADl5HLFwRhD8"
}
POST /janus/2171134171642143/3157394748811091
{
"janus": "trickle",
"candidate": {
"candidate": "candidate:2445384676 1 udp 2122260223 192.168.1.26 58158 typ host generation 0 ufrag 8bex network-id 1 network-cost 10",
"sdpMid": "2",
"sdpMLineIndex": 2
},
"transaction": "ZMYyZJLkgTrZ",
"session_id": 2171134171642143,
"handle_id": 3157394748811091
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "ZMYyZJLkgTrZ"
}
GET /janus/2171134171642143
{
"janus": "keepalive",
"session_id": 2171134171642143,
"transaction": "En5VbvlvuBO"
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "En5VbvlvuBO"
}
response:{
"janus": "webrtcup",
"session_id": 2171134171642143,
"sender": 3157394748811091
}
POST /janus/2171134171642143/3157394748811091
{
"janus": "trickle",
"candidate": {
"completed": true
},
"transaction": "joC3iUJ1E057",
"session_id": 2171134171642143,
"handle_id": 3157394748811091
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "joC3iUJ1E057"
}
response:{
"janus": "media",
"session_id": 2171134171642143,
"sender": 3157394748811091,
"type": "audio",
"receiving": true
}
GET /janus/2171134171642143
{
"janus": "keepalive",
"session_id": 2171134171642143,
"transaction": "3vtP1Zq9XBs"
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "3vtP1Zq9XBs"
}
response:{
"janus": "media",
"session_id": 2171134171642143,
"sender": 3157394748811091,
"type": "video",
"receiving": true
}
GET /janus/2171134171642143
{
"janus": "keepalive",
"session_id": 2171134171642143,
"transaction": "61zLgIgUXqQ"
}
response:{
"janus": "ack",
"session_id": 2171134171642143,
"transaction": "61zLgIgUXqQ"
}
POST /janus/2171134171642143
{
"janus": "destroy",
"transaction": "UOyds05J8Nzm",
"session_id": 2171134171642143
}
response:{
"janus": "success",
"session_id": 2171134171642143,
"transaction": "UOyds05J8Nzm"
}