added tab notification and fixed websocket q-chat

This commit is contained in:
2023-06-13 13:30:23 +03:00
parent 02a78173a3
commit 22ca790f51
10 changed files with 1361 additions and 1122 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -44,4 +44,7 @@ export const ENCRYPT_DATA = 'ENCRYPT_DATA'
export const DECRYPT_DATA = 'DECRYPT_DATA'
// SAVE_FILE
export const SAVE_FILE = 'SAVE_FILE'
export const SAVE_FILE = 'SAVE_FILE'
//SET_TAB_NOTIFICATIONS
export const SET_TAB_NOTIFICATIONS = 'SET_TAB_NOTIFICATIONS'

View File

@@ -892,10 +892,42 @@ class WebBrowser extends LitElement {
this.service = data.service;
this.identifier = data.identifier;
this.displayUrl = url;
const frame = window.frameElement
let tabId = ""
if (frame && frame.dataset.id) {
tabId = frame.dataset.id
}
if (data.name === 'Q-Mail') {
localStorage.setItem("Q-Mail-last-visited", Date.now())
}
window.parent.reduxStore.dispatch(window.parent.reduxAction.addTabInfo({
name: data.name,
service: data.service,
id: tabId ? tabId : ""
}))
return;
case actions.SET_TAB_NOTIFICATIONS: {
const { count } = data
if (isNaN(count)) {
response['error'] = 'count is not a number'
break
}
if (count === undefined) {
response['error'] = 'missing count'
break
}
window.parent.reduxStore.dispatch(window.parent.reduxAction.setTabNotifications({
name: this.name,
count: count
}))
response = true
break
}
case actions.PUBLISH_QDN_RESOURCE: {
// optional fields: encrypt:boolean recipientPublicKey:string

View File

@@ -115,6 +115,7 @@ let closeGracefully = false
let onceLoggedIn = false
let retryOnClose = false
let canPing = false
let timeoutId
parentEpml.subscribe('logged_in', async isLoggedIn => {
@@ -127,18 +128,16 @@ parentEpml.subscribe('logged_in', async isLoggedIn => {
if (window.parent.location.protocol === "https:") {
activeChatSocketLink = `wss://${nodeUrl}/websockets/chat/active/${window.parent.reduxStore.getState().app.selectedAddress.address}`;
activeChatSocketLink = `wss://${nodeUrl}/websockets/chat/active/${window.parent.reduxStore.getState().app.selectedAddress.address}?encoding=BASE64`;
} else {
activeChatSocketLink = `ws://${nodeUrl}/websockets/chat/active/${window.parent.reduxStore.getState().app.selectedAddress.address}`;
activeChatSocketLink = `ws://${nodeUrl}/websockets/chat/active/${window.parent.reduxStore.getState().app.selectedAddress.address}?encoding=BASE64`;
}
const activeChatSocket = new WebSocket(activeChatSocketLink);
// Open Connection
activeChatSocket.onopen = () => {
console.log(`[SOCKET]: Connected.`);
socketObject = activeChatSocket
initial = initial + 1
@@ -147,28 +146,26 @@ parentEpml.subscribe('logged_in', async isLoggedIn => {
// Message Event
activeChatSocket.onmessage = (e) => {
if (e.data === 'pong') {
clearTimeout(timeoutId);
activeChatSocketTimeout = setTimeout(pingActiveChatSocket, 45000)
return
}
try {
chatHeadWatcher(JSON.parse(e.data))
} catch (error) {
}
chatHeadWatcher(JSON.parse(e.data))
}
// Closed Event
activeChatSocket.onclose = () => {
console.log(`[SOCKET]: CLOSED`);
clearInterval(activeChatSocketTimeout)
if (closeGracefully === false && initial <= 52) {
if (initial <= 52) {
parentEpml.request('showSnackBar', "Connection to the Qortal Core was lost, is your Core running ?")
retryOnClose = true
setTimeout(pingActiveChatSocket, 10000)
initial = initial + 1
} else {
parentEpml.request('showSnackBar', "Cannot connect to the Qortal Core, restart UI and Core!")
}
if (closeGracefully === false) {
retryOnClose = true
setTimeout(pingActiveChatSocket, 10000)
}
}
@@ -188,18 +185,21 @@ parentEpml.subscribe('logged_in', async isLoggedIn => {
initChatHeadSocket()
onceLoggedIn = true
activeChatSocketTimeout = setTimeout(pingActiveChatSocket, 295000)
activeChatSocketTimeout = setTimeout(pingActiveChatSocket, 45000)
} else if (retryOnClose) {
retryOnClose = false
clearTimeout(activeChatSocketTimeout)
initChatHeadSocket()
onceLoggedIn = true
activeChatSocketTimeout = setTimeout(pingActiveChatSocket, 295000)
activeChatSocketTimeout = setTimeout(pingActiveChatSocket, 45000)
} else if (canPing) {
socketObject.send('ping')
activeChatSocketTimeout = setTimeout(pingActiveChatSocket, 295000)
timeoutId = setTimeout(() => {
socketObject.close();
clearTimeout(activeChatSocketTimeout)
}, 5000);
}
} else {