Skip to content

Commit

Permalink
Automatically reconnecting signalr + better UX
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Sep 28, 2023
1 parent d9e6198 commit b2b49ad
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions backend/files/system/openai/front.files/chat/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,12 @@ function aista_submit_form(speech) {
if (!ainiroStream || ainiro_con) {
aista_submit_form_impl(speech);
} else {
ainiro_con = new signalR.HubConnectionBuilder().withUrl('[[url]]/sockets', {
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets,
}).build();
ainiro_con = new signalR.HubConnectionBuilder()
.withAutomaticReconnect()
.withUrl('[[url]]/sockets', {
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets,
}).build();
ainiro_con.on(aistaSession, function (args) {

// Turning test response into JavaScript object.
Expand Down Expand Up @@ -615,6 +617,15 @@ function aista_show_chat_window() {
if (btns.length > 0) {
btns[0].style.display = 'none';
}

// Scrolling to bottom in case we've got session messages.
console.log('foo');
const allMsgs = window.document.getElementsByClassName('aista-chat-question');
if (allMsgs && allMsgs.length > 0) {
allMsgs[allMsgs.length - 1].scrollIntoView({behavior: 'instant', block: 'start'});
}

// Setting focus to input textbox.
const inp = window.document.getElementsByClassName('aista-chat-prompt')[0];
setTimeout(() => {
inp.focus();
Expand Down

0 comments on commit b2b49ad

Please sign in to comment.