fixes for creating sessions by custom URL

This commit is contained in:
Nuwan 2024-10-28 09:08:22 +05:30
parent fd8f31e7d4
commit 0bd3f9463d
2 changed files with 30 additions and 22 deletions

View File

@ -3,6 +3,7 @@
"use strict";
context.JK = context.JK || {};
context.JK.CreateScheduledSessionDataIsLoaded = false;
context.JK.CreateScheduledSession = function(app) {
var gearUtils = context.JK.GearUtilsInstance;
@ -315,8 +316,7 @@
$fetchingSpinnerLabel.show();
Promise.all([fetchScheduledSessions(), fetchUserDetail()]).then(function() {
// console.log('** calling createSessionByCustomUrlScheme() from scheduled_session');
//createSessionByCustomUrlScheme();
context.JK.CreateScheduledSessionDataIsLoaded = true;
});
}
@ -500,7 +500,6 @@
}
else {
var instruments_me = [];
console.log("** getCreatorInstruments() (1)", JSON.stringify(getCreatorInstruments()));
$.each(getCreatorInstruments(), function(index, instrument) {
instruments_me.push(instrument.name);
});
@ -886,7 +885,6 @@
data.friends_can_join = createSessionSettings.friends_can_join;
data.rsvp_slots = [];
console.log("** startSession getCreatorInstruments (2): " + JSON.stringify(getCreatorInstruments()));
$.each(getCreatorInstruments(), function(index, instrument) {
var slot = {};
slot.instrument_id = instrument.id;
@ -896,7 +894,6 @@
});
var otherInstruments = instrumentRSVP.getSelectedInstruments();
console.log("** startSession getSelectedInstruments: " + JSON.stringify(otherInstruments));
data.isUnstructuredRsvp = otherInstruments.length == 0 && userSelectedSlots(createSessionSettings.createType);
$.each(instrumentRSVP.getSelectedInstruments(), function(index, instrument) {
for (var i = 0; i < instrument.count; i++) {
@ -907,7 +904,6 @@
data.rsvp_slots.push(slot);
}
});
console.log("** startSession data.rsvp_slots: " + JSON.stringify(data.rsvp_slots));
}
var joinSession = function(sessionId) {
@ -1512,7 +1508,6 @@
// asks the instrument selector for the creator's specified instruments, and defaults to Other/Beginner if none were selected
function getCreatorInstruments() {
var instruments = instrumentSelector.getSelectedInstruments();
console.log("** getCreatorInstruments getSelectedInstruments (0)", JSON.stringify(instruments))
if(instruments.length == 0) {
var otherId = context.JK.server_to_client_instrument_map.Other.server_id; // get server ID
var otherInstrumentInfo = context.JK.instrument_id_to_instrument[otherId]; // get display name
@ -1580,13 +1575,16 @@
switch(privacy){
case privacyMap['private_invite']:
clickQuickStartFriends();
//clickQuickStartFriends();
$quickStartFriendsBtn.trigger('click');
break;
case privacyMap['private_approve']:
clickQuickStartSolo()
//clickQuickStartSolo()
$quickStartSoloBtn.trigger('click');
break;
case privacyMap['public']:
clickQuickStartPublic();
//clickQuickStartPublic();
$quickStartOpenBtn.trigger('click');
break;
default:
logger.debug('Invalid session privacy value')

View File

@ -286,16 +286,13 @@
var instrumentSelectorRSVPInstance = new JK.InstrumentSelector(JK.app);
instrumentSelectorRSVPInstance.initialize(true);
var createScheduledSessionScreen = new JK.CreateScheduledSession(JK.app);
JK.createScheduledSessionScreen = createScheduledSessionScreen;
createScheduledSessionScreen.initialize(
JK.InvitationDialogInstance,
JK.FriendSelectorDialogInstance,
instrumentSelectorInstance,
instrumentSelectorRSVPInstance
);
JK.createScheduledSessionScreen = createScheduledSessionScreen;
console.log("** createScheduledSessionScreen initialized **");
var bandSetupScreen = new JK.BandSetupScreen(JK.app);
bandSetupScreen.initialize(JK.InvitationDialogInstance, JK.FriendSelectorDialogInstance);
@ -452,36 +449,49 @@
});
window.addEventListener('load', (event) => {
window.addEventListener('load', (event) => { // when the page is loaded
function handleCustomUrlScheme(){
console.log("** handleCustomUrlScheme **");
// this is a hack to create a session from a custom URL scheme
// an example custom URL would be: https://www.jamkazam.com/client#/createSession/custom~yes|privacy~2|description~hello|inviteeIds~1,2,3,4
var maxAttempts = 10;
//TODO: show a notification while waiting for the screen to load
var screenLoadInterval = setInterval(() => {
var hash = decodeURIComponent(window.location.hash)
console.log("** handleCustomUrlScheme hash **", hash);
console.log("handling custom URL", hash);
if(hash.includes("custom~yes")){ // if the hash contains the custom yes flag
//handle create session
if(hash.includes("#/createSession")){ // if the hash contains the createSession flag
if (JK.createScheduledSessionScreen) {
if (JK.createScheduledSessionScreen && JK.CreateScheduledSessionDataIsLoaded) { // if the createScheduledSessionScreen is loaded
JK.createScheduledSessionScreen.createSessionByCustomUrlScheme(hash); // this will create a session
clearInterval(screenLoadInterval);
}else{
console.log("** attempting to create session by custom URL scheme", maxAttempts);
console.log("waiting for createScheduledSessionScreen to load", maxAttempts);
maxAttempts--;
if(maxAttempts <= 0){
clearInterval(screenLoadInterval);
}
}
}
//handle join session
if(hash.includes("#/joinSession")){ // if the hash contains the joinSession flag
// if (JK.findSessionScreen && JK.FindSessionDataIsLoaded) { // if the findSessionScreen is loaded
// JK.findSessionScreen.joinSessionByCustomUrlScheme(hash); // this will join a session
// clearInterval(screenLoadInterval);
// }else{
// console.log("waiting for findSessionScreen to load", maxAttempts);
// maxAttempts--;
// if(maxAttempts <= 0){
// clearInterval(screenLoadInterval);
// }
// }
}
}
}, 1000); // check every second