我是使用 Android 版 Xirsys API 的新手。我已按照教程(“Learning WebRTC Getting Started”)进行操作,但我注意到的一件事是,我从SYS收到的“用户”消息不断增长,并且我在测试中使用了相同名称的重复项(大概是因为我我在尝试 API 时连接了多次)。这是一个示例消息:
{"m":{"f":"StayingInTouch/__sys__","o":"peers","t":null},"p":{"users":["tad@gmail.com","tad@gmail.com","tad@gmail.com","tad@gmail.com","tad@gmail.com","tad@gmail.com","tad@gmail.com","tad@gmail.com","tad@gmail.com","tad"]},"t":"u"}
除了关闭各种资源以让 Xirsys 从其内部列表中删除该用户之外,我还应该做些什么吗?
我首先通过 Volley 发出 PUT 以获取令牌,然后通过 Volley 使用 GET 来获取信令主机 Url,然后打开套接字:
okhttp3.Request request = new okhttp3.Request.Builder().url(hostValue + "/v2/" + mToken).build();
ws = client.newWebSocket(request, socketListener);
所有这些都很好,我可以来回发出信号。
这是我的 onDestroy():
protected void onDestroy() {
shutDownResources();
try {
client.dispatcher().executorService().shutdown();
} catch (Exception e) {
myLog("Error shutting down socket client: " + e.getMessage());
}
mQueue.cancelAll(null);
mQueue.stop();
super.onDestroy();
}
这是 shutDownResources() 方法:
private void shutDownResources() {
if ( localDataChannel != null ) {
try {
localDataChannel.unregisterObserver();
localObserver = null;
localDataChannel.close();
localDataChannel.dispose();
localDataChannel = null;
} catch (Exception e) {
myLog( "Error closing local data channel:" + e.getMessage());
}
}
if ( localPeer != null ) {
try {
localPeer.close();
localPeer.dispose();
localPeer = null;
} catch (Exception e) {
myLog( "Error closing peer:" + e.getMessage());
}
}
if ( ws != null ) {
try {
ws.cancel();
ws = null;
} catch (Exception e) {
myLog( "Error shutting down socket client: " + e.getMessage());
}
}
iceServers = null;
iceServerMap.clear();
}