mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-03-15 02:47:23 +00:00
Refactor Settings, FileTree, GitPanel, Shell, and CodeEditor components (#402)
This commit is contained in:
32
src/components/shell/utils/socket.ts
Normal file
32
src/components/shell/utils/socket.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { IS_PLATFORM } from '../../../constants/config';
|
||||
import type { ShellIncomingMessage, ShellOutgoingMessage } from '../types/types';
|
||||
|
||||
export function getShellWebSocketUrl(): string | null {
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
|
||||
if (IS_PLATFORM) {
|
||||
return `${protocol}//${window.location.host}/shell`;
|
||||
}
|
||||
|
||||
const token = localStorage.getItem('auth-token');
|
||||
if (!token) {
|
||||
console.error('No authentication token found for Shell WebSocket connection');
|
||||
return null;
|
||||
}
|
||||
|
||||
return `${protocol}//${window.location.host}/shell?token=${encodeURIComponent(token)}`;
|
||||
}
|
||||
|
||||
export function parseShellMessage(payload: string): ShellIncomingMessage | null {
|
||||
try {
|
||||
return JSON.parse(payload) as ShellIncomingMessage;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function sendSocketMessage(ws: WebSocket | null, message: ShellOutgoingMessage): void {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify(message));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user