destroyHandle method
Implementation
destroyHandle(int handleId, Callbacks callbacks) {
var noRequest = (callbacks.noRequest == true);
Janus.log("Destroying handle " +
handleId.toString() +
" (only-locally=" +
noRequest.toString() +
")");
cleanupWebrtc(handleId, false);
Plugin pluginHandle = this.pluginHandles[handleId.toString()];
// if (pluginHandle == null) {
// // Plugin was already detached by Janus, calling detach again will return a handle not found error, so just exit here
// this.pluginHandles.remove(handleId.toString());
// if (callbacks.success is Function) callbacks.success();
// return;
// }
// if (noRequest) {
// // We're only removing the handle locally
// this.pluginHandles.remove(handleId.toString());
// if (callbacks.success is Function) callbacks.success("Plugin removed");
// return;
// }
if (!this.connected) {
Janus.warn("Is the server down? (connected=false)");
callbacks.error("Is the server down? (connected=false)");
return;
}
Map<String, dynamic> request = {
"janus": "detach",
"transaction": Janus.randomString(12)
};
if (pluginHandle.handleToken != null)
request["token"] = pluginHandle.handleToken;
if (this.apiSecret != null) request["apisecret"] = this.apiSecret;
if (this.websockets != null) {
request["session_id"] = this.sessionId;
request["handle_id"] = handleId;
this.ws.send(jsonEncode(request)); // FIX ME
this.pluginHandles.remove(handleId.toString());
callbacks.success();
return;
}
GatewayCallbacks httpCallbacks = GatewayCallbacks();
httpCallbacks.success = (json) {
Janus.log("Destroyed handle:");
Janus.debug(json);
if (json["janus"] != "success") {
Janus.error("Ooops: " +
json["error"]["code"].toString() +
" " +
json["error"]["reason"]);
}
this.pluginHandles.remove(handleId.toString());
callbacks.success();
};
httpCallbacks.error = (textStatus, errorThrown) {
Janus.error(textStatus + ":" + errorThrown); // FIXME
// We cleanup anyway
this.pluginHandles.remove(handleId.toString());
callbacks.success();
};
Janus.httpAPICall(
this.server +
"/" +
this.sessionId.toString() +
"/" +
handleId.toString(),
{
'verb': 'POST',
'withCredentials': this.withCredentials,
'body': request
},
httpCallbacks);
}