C
C#15mo ago
Joch

❔ SignalR

Hi, Seeking for help. hehehe , i don't know if this correct way to implement signal in js without trigger. i used interval to call the hub. i dont know the correct way.
sorry for my english grammar. Thanks
"use strict";


/*
1 sec = 1000 millisecond
*/
var MILLS = 1000;
var SECONDS = 5;
var MILL_IN_MINS = SECONDS * MILLS

var isAlreadyShowAlert = false;
var connection = new signalR.HubConnectionBuilder()
.withUrl("/SessionCheck")
.withAutomaticReconnect()
.build();

connection.on("ResponseSession", function (isLogout) {
if (isLogout && !isAlreadyShowAlert) {
alert("Session Forced to Logout.")
document.getElementById("logout").click();
isAlreadyShowAlert = true;
}

});

connection.start().then(function () {
console.log("signalR Start");
checkSession();
}).catch(function (err) {
console.error(err.toString());
});

function checkSession() {
var empCode = localStorage.getItem("user.empcode")
if (empCode !== "test") {
setInterval(function () {
connection.invoke("CheckSession", empCode).catch(function (err) {
console.error(err.toString());
});
}, MILL_IN_MINS)
}
}
"use strict";


/*
1 sec = 1000 millisecond
*/
var MILLS = 1000;
var SECONDS = 5;
var MILL_IN_MINS = SECONDS * MILLS

var isAlreadyShowAlert = false;
var connection = new signalR.HubConnectionBuilder()
.withUrl("/SessionCheck")
.withAutomaticReconnect()
.build();

connection.on("ResponseSession", function (isLogout) {
if (isLogout && !isAlreadyShowAlert) {
alert("Session Forced to Logout.")
document.getElementById("logout").click();
isAlreadyShowAlert = true;
}

});

connection.start().then(function () {
console.log("signalR Start");
checkSession();
}).catch(function (err) {
console.error(err.toString());
});

function checkSession() {
var empCode = localStorage.getItem("user.empcode")
if (empCode !== "test") {
setInterval(function () {
connection.invoke("CheckSession", empCode).catch(function (err) {
console.error(err.toString());
});
}, MILL_IN_MINS)
}
}
43 Replies
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
ohh. is the set interval work good?
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
ahh. ill fix the callback to async await.
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
i mean is i dont need to click the button for connection.invoke i want to set it programmtically every what will my management say seconds. i just define secod there whether my dev manager will change or stick it to 5 seconds. heheh
"use strict";


/*
1 sec = 1000 millisecond
*/
var MILLS = 1000;
var SECONDS = 5;
var MILL_IN_MINS = SECONDS * MILLS

var connection = new signalR.HubConnectionBuilder()
.withUrl("/SessionCheck")
.withAutomaticReconnect()
.build();

connection.on("ResponseSession", function (isLogout) {
isForceToLogout()
});
try {
await connection.start();
console.log("signalR Start");
checkSession();
} catch (error) {
console.error(error.toString());
}

function checkSession() {
var empCode = localStorage.getItem("user.empcode")
if (empCode !== "test") {
setInterval(function () {
connection.invoke("CheckSession", empCode).catch(function (err) {
console.error(err.toString());
});
}, MILL_IN_MINS)
}
}

function isForceToLogout(isLogout) {
if (isLogout && isBrowserInReadyState()) {
alert("Session Forced to Logout.")
document.getElementById("logout").click();
}
}

function isBrowserInReadyState() {
if (document.readyState === 'ready' || document.readyState === 'complete') {
return true
}
return false;
}
"use strict";


/*
1 sec = 1000 millisecond
*/
var MILLS = 1000;
var SECONDS = 5;
var MILL_IN_MINS = SECONDS * MILLS

var connection = new signalR.HubConnectionBuilder()
.withUrl("/SessionCheck")
.withAutomaticReconnect()
.build();

connection.on("ResponseSession", function (isLogout) {
isForceToLogout()
});
try {
await connection.start();
console.log("signalR Start");
checkSession();
} catch (error) {
console.error(error.toString());
}

function checkSession() {
var empCode = localStorage.getItem("user.empcode")
if (empCode !== "test") {
setInterval(function () {
connection.invoke("CheckSession", empCode).catch(function (err) {
console.error(err.toString());
});
}, MILL_IN_MINS)
}
}

function isForceToLogout(isLogout) {
if (isLogout && isBrowserInReadyState()) {
alert("Session Forced to Logout.")
document.getElementById("logout").click();
}
}

function isBrowserInReadyState() {
if (document.readyState === 'ready' || document.readyState === 'complete') {
return true
}
return false;
}
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
i noticed when i put a debugger in C# hub class, when I didnt call the invoke, there is no debug .
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
to be honest. i think its not supported by async await .
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
it came from asp.net core 1.0 something . then upgraded to .net core 3.1
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
yeah. i knew back days async await is in blooming i recently upgrade the version to 3.1 i thnk last may or march. something i forgot heheh
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
ohh. i just used now the signal r. when i handle the this project there is no signal r
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
im just implementing for real time check
MODiX
MODiX15mo ago
TeBeCo
like if i ask you to push a repo with only the html / js file / only a dumb hub in c# can you do it ?
Quoted by
<@689473681302224947> from #SignalR (click here)
React with ❌ to remove this embed.
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
i can do it for the class hub and js file only.
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
ohh. full code its very complicated. too many need to setup . 😦
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
i mean project. how i can do it ?.
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
specific file only ? i can do that. ill just create . and upload to github.
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
mvc.
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
ohh. but i dont need have a click button . i just want to use every 5 second . like click every 5 sec .
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
the button click here is mapp to function start ?
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
yeah. that what im seeing heheh. im just confused heh
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
ohh. sorry
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
ill try this . hehehe. thank you .
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Joch
JochOP15mo ago
hehehe. thank you for the help .
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server