mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 13:22:12 +00:00
Wait for location data to be returned before setting up the socket connection
This commit is contained in:
@@ -54,6 +54,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
let region = null;
|
let region = null;
|
||||||
let city = null;
|
let city = null;
|
||||||
let countryName = null;
|
let countryName = null;
|
||||||
|
let waitingForLocation = true;
|
||||||
|
|
||||||
let websocketState = {
|
let websocketState = {
|
||||||
newResponseText: null,
|
newResponseText: null,
|
||||||
@@ -73,6 +74,11 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return;
|
return;
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
console.debug("Region:", region, "City:", city, "Country:", countryName);
|
||||||
|
waitingForLocation = false;
|
||||||
|
setupWebSocket();
|
||||||
});
|
});
|
||||||
|
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
@@ -855,6 +861,11 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
let wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
let wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
let webSocketUrl = `${wsProtocol}//${window.location.host}/api/chat/ws`;
|
let webSocketUrl = `${wsProtocol}//${window.location.host}/api/chat/ws`;
|
||||||
|
|
||||||
|
if (waitingForLocation) {
|
||||||
|
console.debug("Waiting for location data to be fetched. Will setup WebSocket once location data is available.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
websocketState = {
|
websocketState = {
|
||||||
newResponseText: null,
|
newResponseText: null,
|
||||||
newResponseElement: null,
|
newResponseElement: null,
|
||||||
@@ -877,7 +888,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
|
|
||||||
if (chatBody.dataset.conversationId) {
|
if (chatBody.dataset.conversationId) {
|
||||||
webSocketUrl += `?conversation_id=${chatBody.dataset.conversationId}`;
|
webSocketUrl += `?conversation_id=${chatBody.dataset.conversationId}`;
|
||||||
webSocketUrl += `®ion=${region}&city=${city}&country=${countryName}`;
|
webSocketUrl += (!!region && !!city && !!countryName) ? `®ion=${region}&city=${city}&country=${countryName}` : '';
|
||||||
|
|
||||||
websocket = new WebSocket(webSocketUrl);
|
websocket = new WebSocket(webSocketUrl);
|
||||||
websocket.onmessage = function(event) {
|
websocket.onmessage = function(event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user