video_calls: Refactor zoom_xhrs to support other OAuth video applications.

Rename zoom_xhrs to video_call_xhrs.
Rename abort_zoom to abort_video_callbacks.
Delete callbacks from video_call_xhrs when they have been aborted.
Move generation of video_call_id in the .videolink handler into
the Jitsi video call handling block as it is the only place it is
referenced.
This commit is contained in:
Greg Rowe 2020-10-28 10:35:48 +00:00 committed by Tim Abbott
parent 954ad9f7ab
commit d1ae0cff1e
3 changed files with 12 additions and 11 deletions

View File

@ -184,13 +184,14 @@ exports.abort_xhr = function () {
};
exports.zoom_token_callbacks = new Map();
exports.zoom_xhrs = new Map();
exports.video_call_xhrs = new Map();
exports.abort_zoom = function (edit_message_id) {
exports.abort_video_callbacks = function (edit_message_id) {
const key = edit_message_id || "";
exports.zoom_token_callbacks.delete(key);
if (exports.zoom_xhrs.has(key)) {
exports.zoom_xhrs.get(key).abort();
if (exports.video_call_xhrs.has(key)) {
exports.video_call_xhrs.get(key).abort();
exports.video_call_xhrs.delete(key);
}
};
@ -1190,7 +1191,6 @@ exports.initialize = function () {
}
let video_call_link;
const video_call_id = util.random_int(100000000000000, 999999999999999);
const available_providers = page_params.realm_available_video_chat_providers;
const show_video_chat_button = exports.compute_show_video_chat_button();
@ -1202,20 +1202,20 @@ exports.initialize = function () {
available_providers.zoom &&
page_params.realm_video_chat_provider === available_providers.zoom.id
) {
exports.abort_zoom(edit_message_id);
exports.abort_video_callbacks(edit_message_id);
const key = edit_message_id || "";
const make_zoom_call = () => {
exports.zoom_xhrs.set(
exports.video_call_xhrs.set(
key,
channel.post({
url: "/json/calls/zoom/create",
success(res) {
exports.zoom_xhrs.delete(key);
exports.video_call_xhrs.delete(key);
insert_video_call_url(res.url, target_textarea);
},
error(xhr, status) {
exports.zoom_xhrs.delete(key);
exports.video_call_xhrs.delete(key);
if (
status === "error" &&
xhr.responseJSON &&
@ -1254,6 +1254,7 @@ exports.initialize = function () {
},
});
} else {
const video_call_id = util.random_int(100000000000000, 999999999999999);
video_call_link = page_params.jitsi_server_url + "/" + video_call_id;
insert_video_call_url(video_call_link, target_textarea);
}

View File

@ -267,7 +267,7 @@ exports.cancel = function () {
clear_box();
notifications.clear_compose_notifications();
compose.abort_xhr();
compose.abort_zoom(undefined);
compose.abort_video_callbacks(undefined);
compose_state.set_message_type(false);
compose_pm_pill.clear();
$(document).trigger($.Event("compose_canceled.zulip"));

View File

@ -586,7 +586,7 @@ exports.end_message_row_edit = function (row) {
currently_editing_messages.delete(message.id);
current_msg_list.hide_edit_message(row);
compose.abort_zoom(message.id);
compose.abort_video_callbacks(message.id);
}
condense.show_message_expander(row);
row.find(".message_reactions").show();