feat: allow renaming connection (#457)

* feat: allow renaming connection
This commit is contained in:
Carlos Valente
2023-07-21 20:15:54 +02:00
committed by GitHub
parent 6ef6b0fdcd
commit db1155ce1a
8 changed files with 180 additions and 21 deletions
+10 -1
View File
@@ -2,6 +2,7 @@ import { Log, RuntimeStore } from 'ontime-types';
import { RUNTIME, websocketUrl } from '../api/apiConstants';
import { ontimeQueryClient } from '../queryClient';
import { socketClientName } from '../stores/connectionName';
import { addLog } from '../stores/logger';
import { runtime } from '../stores/runtime';
@@ -11,13 +12,17 @@ const reconnectInterval = 1000;
export let shouldReconnect = true;
export let hasConnected = false;
export let reconnectAttempts = 0;
export const connectSocket = () => {
export const connectSocket = (preferredClientName?: string) => {
websocket = new WebSocket(websocketUrl);
websocket.onopen = () => {
clearTimeout(reconnectTimeout as NodeJS.Timeout);
hasConnected = true;
reconnectAttempts = 0;
if (preferredClientName) {
socketSendJson('set-client-name', preferredClientName);
}
};
websocket.onclose = () => {
@@ -49,6 +54,10 @@ export const connectSocket = () => {
// TODO: implement partial store updates
switch (type) {
case 'client-name': {
socketClientName.getState().setName(payload);
break;
}
case 'ontime-log': {
addLog(payload as Log);
break;