invoking the client to create a session using custom URL
This commit is contained in:
parent
15583ce99d
commit
505d7c0496
|
|
@ -280,7 +280,6 @@
|
|||
}
|
||||
console.log("logged with new msg", msg);
|
||||
const loggedInResp = await context.jamClient.OnLoggedIn(msg); // ACTS AS CONTINUATION
|
||||
console.log("OnLoggedIn response 1", loggedInResp);
|
||||
if (loggedInResp && loggedInResp['CustomUrl']) {
|
||||
handleLoggedInResponse(loggedInResp['CustomUrl']);
|
||||
}
|
||||
|
|
@ -291,7 +290,6 @@
|
|||
payload.token,
|
||||
payload.username
|
||||
); // ACTS AS CONTINUATION
|
||||
console.log("OnLoggedIn response 1", loggedInResp);
|
||||
if (loggedInResp && loggedInResp['CustomUrl']) {
|
||||
handleLoggedInResponse(loggedInResp['CustomUrl']);
|
||||
}
|
||||
|
|
@ -374,29 +372,17 @@
|
|||
}
|
||||
|
||||
function handleLoggedInResponse(loggedInResp) {
|
||||
console.log("handleLoggedInResponse", context.JK);
|
||||
if(localStorage.getItem("after-login-redirect-to")) {
|
||||
localStorage.removeItem("after-login-redirect-to");
|
||||
}
|
||||
try {
|
||||
const url = new URL(loggedInResp);
|
||||
const redirectTo = new URLSearchParams(url.search).get("redirect-to");
|
||||
const redirectTo = new URLSearchParams(url.search).get("redirect-to");
|
||||
if (redirectTo) {
|
||||
// const cusQuery = redirectTo.substring(
|
||||
// redirectTo.lastIndexOf("/") + 1
|
||||
// );
|
||||
//if (redirectTo.includes("/client#/createSession")) {
|
||||
// JK.createScheduledSessionScreen.launchSessionFromCustomUrlScheme(
|
||||
// cusQuery
|
||||
// );
|
||||
//}
|
||||
|
||||
localStorage.setItem("after-login-redirect-to", redirectTo);
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("error in handleLoggedInResponse", e);
|
||||
context.JK.app.notifyAlert(
|
||||
"Error",
|
||||
"An invalid URL was given. Please try again."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1524,21 +1524,11 @@
|
|||
}
|
||||
|
||||
function launchSessionFromCustomUrlScheme(urlString){
|
||||
//an example URL would be: /client#/createSession/custom~yes|privacy~2|description~hello|inviteeIds~1,2,3,4
|
||||
//var url;
|
||||
//try{
|
||||
// url = new URL(urlString);
|
||||
//}catch(error){
|
||||
// logger.debug(error);
|
||||
// context.JK.app.notifyAlert("Error", "An invalid URL was given. Couldn't create the session. Please try again.");
|
||||
// return;
|
||||
//}
|
||||
//an example urlString would be: custom~yes|privacy~2|description~hello|inviteeIds~1,2,3,4
|
||||
|
||||
|
||||
//var hash = decodeURIComponent(url.hash);
|
||||
//var qStr = hash.substring(hash.lastIndexOf('/') + 1);
|
||||
|
||||
//decode the query params according to the custom format
|
||||
var qParamsArr = qStr.split('|');
|
||||
var qParamsArr = decodeURIComponent(urlString).split('|');
|
||||
var isCustom, privacy, description, inviteeIds;
|
||||
qParamsArr.forEach(function(q){
|
||||
var qp = q.split('~')
|
||||
|
|
@ -1551,8 +1541,12 @@
|
|||
return;
|
||||
}
|
||||
|
||||
console.log('**LoggedIn params', privacy, description, inviteeIds)
|
||||
|
||||
createSessionSettings.description = description;
|
||||
|
||||
console.log('**LoggedIn privacy', privacy)
|
||||
|
||||
switch(privacy){
|
||||
case privacyMap['private_invite']:
|
||||
clickQuickStartFriends();
|
||||
|
|
@ -1586,26 +1580,30 @@
|
|||
}
|
||||
}).catch(function(error){
|
||||
logger.debug(error)
|
||||
context.JK.app.notifyAlert("Alert!", "An error occurred while creating the session. Please try again.");
|
||||
console.log('Error while creating session', error)
|
||||
context.JK.app.notifyAlert("Alert!", "Session was not created properly. Please try again.");
|
||||
});
|
||||
}
|
||||
|
||||
function waitUntilSessionCreated(){
|
||||
return new Promise(function(resolve, reject){
|
||||
var maxAttempts = 5;
|
||||
var maxAttempts = 10;
|
||||
var attempt = 0;
|
||||
var sessionCreateInterval;
|
||||
try{
|
||||
var sessionCreateInterval = setInterval(function(){
|
||||
sessionCreateInterval = setInterval(function(){
|
||||
attempt++;
|
||||
console.log('_DEBUG_ trying to get the sessionId....', attempt)
|
||||
console.log('attempting to get the sessionId....', attempt)
|
||||
if(createSessionSettings.newSessionId){
|
||||
clearInterval(sessionCreateInterval)
|
||||
resolve()
|
||||
}else if(attempt > maxAttempts){
|
||||
clearInterval(sessionCreateInterval)
|
||||
reject("Maximum number of attepts for getting a sessionId is exceeded.")
|
||||
}
|
||||
}, 1000)
|
||||
}catch(error){
|
||||
clearInterval(sessionCreateInterval)
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -389,8 +389,19 @@
|
|||
|
||||
JK.app.initialRouting();
|
||||
|
||||
|
||||
JK.hideCurtain(300);
|
||||
|
||||
//handle onLoggedIn custom URL scheme
|
||||
if (localStorage.getItem('after-login-redirect-to')) {
|
||||
var redirectTo = localStorage.getItem('after-login-redirect-to');
|
||||
console.log("**after-login-redirect-to: " + redirectTo);
|
||||
const cusQuery = redirectTo.substring(redirectTo.lastIndexOf("/") + 1);
|
||||
console.log("**after-login-redirect-to cusQuery: " + decodeURIComponent(cusQuery));
|
||||
if (redirectTo.includes("/client#/createSession")) {
|
||||
JK.createScheduledSessionScreen.launchSessionFromCustomUrlScheme(decodeURIComponent(cusQuery))
|
||||
}
|
||||
localStorage.removeItem('after-login-redirect-to');
|
||||
}
|
||||
}
|
||||
|
||||
// async function redirectLatencyTester(){
|
||||
|
|
@ -448,18 +459,7 @@
|
|||
JK.bindHoverEvents();
|
||||
|
||||
|
||||
//after-login-redirect
|
||||
if (localStorage.getItem('after-login-redirect-to')) {
|
||||
var redirect = localStorage.getItem('after-login-redirect-to');
|
||||
const cusQuery = redirect.substring(redirectTo.lastIndexOf("/") + 1);
|
||||
|
||||
if (redirect.includes("/client#/createSession")) {
|
||||
alert("create session");
|
||||
}
|
||||
|
||||
localStorage.removeItem('after-login-redirect');
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue