适用于appr.tc的原生Android应用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了适用于appr.tc的原生Android应用相关的知识,希望对你有一定的参考价值。
从几个星期以来,我正试图通过使用apprtc在本机android应用程序(https://github.com/njovy/AppRTCDemo
)和浏览器之间建立websession。当使用appr.tc作为room-server url时,该应用程序运行良好。我已经在Ubuntu上设置了apprtc项目,我可以在Ubuntu机器上的浏览器和我的移动设备的浏览器之间创建一个会议。但是当我尝试在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
的部署过程)
- 从git下载最新版本的webrtc
- 安装了npm,nodejs和grunt
- 使用grunt构建来构建源代码
- 下载,安装和配置的对撞机(对撞机在rtc上运行:8089) 4.1我必须在workspace / src / collidermain中更改main.go from:var roomSrv = flag.String(“room-server”,“hxxps://appr.tc”,“房间服务器的起源”) to:var roomSrv = flag.String(“room-server”,“hxxp:// rtc”,“房间服务器的起源”) 4.2还在src / app_engine / constants.py中将WS_INSTANCE_HOST_KEY更改为碰撞者adresse rtc:8089
- 我安装了CoTurn并添加了一个看起来像的turnserver.conf 监听端口= 3478 听-IP = 192.168.178.20 用户= RTC:的WebRTC 证书= /家庭/ RTC /工作/ src目录/撞机/ CERT / cert.pem p键= /家庭/ RTC /工作/ src目录/撞机/ CERT / key.pem
Collider运行在192.168.178.20:8089(或rtc:8089)和转发服务器192.168.178.20:3478。在turnserver.conf中定义的凭据:Username = rtc,Password = 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;
//});
//});
//}
当我现在开始我的游戏,我的转弯服务器和对撞机
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
我能够在两个浏览器客户端之间建立连接(从对撞机终端登录)
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
当我现在尝试通过本机应用程序连接时,我总是收到上面提到的错误。
经过调查后,我在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 = [] out,评论了我的turnserver中的其他行并填写了我的凭据,在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
但仍然会抛出同样的错误。
由于这不起作用,我试图将转向服务器地址插入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
但现在我无法再通过浏览器打开主机了。所以我想这可能是完全错误的。
- 您是否知道如何使用本机应用程序建立会议?
- 如何绕过可能导致错误的networktraversal.googleapis.com网址?
- 我必须绕过它吗?
提前致谢!
将所有这些设置为空字符串:
ICE_SERVER_BASE_URL = ''
ICE_SERVER_URL_TEMPLATE = ''
ICE_SERVER_API_KEY = ''
你设置了collinder网址吗?你的转向服务器应该使用oauth配置。检查所有日志:apprtc,chrome console log,turnserver log,collinder log ..了解更多详情。
以上是关于适用于appr.tc的原生Android应用的主要内容,如果未能解决你的问题,请参考以下文章
适用于 iOS/Android/Windows 8 的混合应用程序
在使用适用于 iOS 和 Android 的 React Native 时,我还能使用原生第三方库吗?
如何在 iOS 项目中添加两个或多个 kotlin 原生模块