几周以来,我一直在尝试使用 apprtc 在原生 android 应用程序 (https://github.com/njovy/AppRTCDemo
) 和浏览器之间建立网络 session 。当使用 appr.tc 作为房间服务器 url 时,该应用程序运行良好。
我已经在 Ubuntu 上设置了 apprtc 项目,我能够在 Ubuntu 机器上的浏览器和例如我的移动设备的浏览器之间创建 session 。但是当我尝试在 ubuntu 上的浏览器和应用程序之间建立连接时,我总是收到以下错误:
Room IO error: java.io.IOException:
Non-200 response when requesting
TURN server from https://
networktraversal.googleapis.com/
v1alpha/iceconfig?key=none : HTTP/
1.1 400 Bad Request
错误信息中提到的URL定义在src/app_engine/constants.py (https://github.com/webrtc/apprtc/blob/master/src/app_engine/constants.py
).但是我不知道该怎么办
# TODO(jansson): Remove once AppRTCDemo on iOS supports ICE_SERVER.
TURN_BASE_URL = 'https://computeengineondemand.appspot.com'
TURN_URL_TEMPLATE = '%s/turn?username=%s&key=%s'
CEOD_KEY = '4080218913'
ICE_SERVER_BASE_URL = 'https://networktraversal.googleapis.com'
ICE_SERVER_URL_TEMPLATE = '%s/v1alpha/iceconfig?key=%s'
ICE_SERVER_API_KEY = os.environ.get('ICE_SERVER_API_KEY')
CALLSTATS_PARAMS = {
'appId': os.environ.get('CALLSTATS_APP_ID'),
'appSecret': os.environ.get('CALLSTATS_APP_SECRET')
}
到目前为止我做了什么? (差不多就是apprtc https://github.com/webrtc/apprtc#deployment
的部署过程)
- Downloaded the latest verion of apprtc from git
- Installed npm, nodejs and grunt
- Building sources by using grunt build
- Downloaded, installed and configured collider (collider runs on rtc:8089)
- 4.1 I had to change my main.go in workspace/src/collidermain
from: var roomSrv = flag.String("room-server", "hxxps://appr.tc", "The origin of the room server")
to: var roomSrv = flag.String("room-server", "hxxp://rtc", "The origin of the room server")- 4.2 Also changed WS_INSTANCE_HOST_KEY to colliders adresse rtc:8089 in src/app_engine/constants.py
- I installed CoTurn and added a turnserver.conf that looks like
listening-port=3478
listening-ip=192.168.178.20
user=rtc:webrtc
cert=/home/rtc/work/src/collider/cert/cert.pem
pkey=/home/rtc/work/src/collider/cert/key.pem
Collider 在 192.168.178.20:8089(或 rtc:8089)上运行,而 turnserver 在 192.168.178.20:3478 上运行。 turnserver.conf中定义的凭证:用户名=rtc,密码=webrtc
设置完成后,我将 requestIceServers-Method 添加到 src/web_app/js/util.js (https://github.com/webrtc/apprtc/blob/master/src/web_app/js/util. js
)
function requestIceServers(iceServerRequestUrl, iceTransports) {
return new Promise(function(resolve, reject) {
var servers = [{
credential: "webrtc",
username: "rtc",
urls: [
"turn:192.168.178.20:3478?transport=udp",
"turn:192.168.178.20:3478?transport=tcp"
]
}];
resolve(servers);
});
}
并注释掉标准方法:
//function requestIceServers(iceServerRequestUrl, iceTransports) {
//return new Promise(function(resolve, reject) {
//sendAsyncUrlRequest('POST', iceServerRequestUrl).then(function(response) {
//var iceServerRequestResponse = parseJSON(response);
//if (!iceServerRequestResponse) {
//reject(Error('Error parsing response JSON: ' + response));
//return;
//}
//if (iceTransports !== '') {
//filterIceServersUrls(iceServerRequestResponse, iceTransports);
//}
//trace('Retrieved ICE server information.');
//resolve(iceServerRequestResponse.iceServers);
//}).catch(function(error) {
//reject(Error('ICE server request error: ' + error.message));
//return;
//});
//});
//}
当我现在启动我的 GAE、我的 turnserver 和 collider 时
python ~/google_appengine/dev_appserver.py ~/google_projects/apprtc-master/out/app_engine --host=0.0.0.0
sudo turnserver -a -r 192.168.178.20
$GOPATH/bin/collidermain -port=8089 -tls=false
我能够在两个浏览器客户端之间建立连接(从 collider-terminal 登录)
rtc@rtc:~$ $GOPATH/bin/collidermain -port=8089 -tls=false
2016/11/05 00:07:32 Starting collider: tls = false, port = 8089, room-server=http://rtc
2016/11/05 00:10:24 Created room stackoverflow
2016/11/05 00:10:24 Added client 97869213 to room stackoverflow
2016/11/05 00:10:24 Client 97869213 registered in room stackoverflow
2016/11/05 00:10:57 Added client 96368166 to room stackoverflow
2016/11/05 00:10:57 Client 96368166 registered in room stackoverflow
2016/11/05 00:10:57 Sent queued messages from 97869213 to 96368166
2016/11/05 00:11:09 Deregistered client 96368166 from room stackoverflow
2016/11/05 00:11:09 Removed client 96368166 from room stackoverflow
2016/11/05 00:11:19 Removing client 96368166 from room stackoverflow due to timeout
当我现在尝试通过 native 应用程序连接时,我总是收到上述错误。
经过调查,我在 git 上找到了以下链接,但对我帮助不大:https://github.com/webrtc/apprtc/issues/366
所以我决定尝试使用 constants.py (https://github.com/webrtc/apprtc/blob/master/src/app_engine/constants.py
) 并找到了一个地方在哪里覆盖 Turn/Stun 服务器
# Turn/Stun server override. This allows AppRTC to connect to turn servers
# directly rather than retrieving them from an ICE server provider.
TURN_SERVER_OVERRIDE = []
# Enable by uncomment below and comment out above, then specify turn and stun
# servers below.
#TURN_SERVER_OVERRIDE = [
# {
# "urls": [
# "turn:192.168.178.20:3478?transport=udp",
# "turn:192.168.178.20:3478?transport=tcp"
# ],
# "username": "rtc",
# "credential": "webrtc"
# },
# {
# "urls": [
# "stun:stun.l.google.com:19305"
# ]
# }
#]
所以我将 TURN_SERVER_OVERRIDE = [] 注释掉,注释掉其他行并填写我的 turnserver 的 IP 和我的凭据,在 turnserver.conf 中配置
GAE 意识到应用程序收到了新请求。它记录
INFO 2016-11-05 00:06:31,649 apprtc.py:408] Added client 50600142 in room stackoverflow, retries = 0
INFO 2016-11-05 00:06:31,650 apprtc.py:92] Applying media constraints: {'video': True, 'audio': True}
WARNING 2016-11-05 00:06:31,653 apprtc.py:136] Invalid or no value returned from memcache, using fallback: null
INFO 2016-11-05 00:06:31,653 apprtc.py:551] User 50600142 joined room stackoverflow
INFO 2016-11-05 00:06:31,653 apprtc.py:552] Room stackoverflow has state ['50600142']
INFO 2016-11-05 00:06:31,658 module.py:788] default: "POST /join/stackoverflow?wstls=false HTTP/1.1" 200 1175
但仍然会抛出相同的错误。
因为这也不起作用,所以我尝试将 turn-server 地址插入 ICE_SERVER_BASE_URL(仍在 constants.py 中)
ICE_SERVER_BASE_URL = 'https://networktraversal.googleapis.com'
ICE_SERVER_URL_TEMPLATE = '%s/v1alpha/iceconfig?key=%s'
ICE_SERVER_API_KEY = os.environ.get('ICE_SERVER_API_KEY')
改为
ICE_SERVER_BASE_URL = '192.168.178.20:3478'
ICE_SERVER_URL_TEMPLATE = ''
ICE_SERVER_API_KEY = os.environ.get('ICE_SERVER_API_KEY')
这将错误更改为:
Connection error
Non-200 response to POST to URL:
http://rtc:8080/join/stackoverflow=wstls=false : HTTP/1.1 500 Internal
Server Error
但现在我无法再从浏览器打开主机。因此我想这可能是完全错误的。
- 您知道如何使用 native 应用程序建立 session 吗?
- 如何绕过 networktraversal.googleapis.com 网址 导致错误?
- 我必须绕过它吗?
提前致谢!
最佳答案
将它们全部设置为空字符串:
ICE_SERVER_BASE_URL = ''
ICE_SERVER_URL_TEMPLATE = ''
ICE_SERVER_API_KEY = ''
你设置collinder url了吗? 并且您的 turnserver 应该使用 oauth 配置。 检查所有日志:apprtc、chrome 控制台日志、turnserver 日志、collinder 日志.. 了解更多详细信息。
关于android - 适用于 appr.tc 的 native android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40434034/