2023-06-08 08:58:02 +02:00
|
|
|
// Project : lollms-webui
|
2023-05-03 00:02:00 +02:00
|
|
|
// Author : ParisNeo
|
|
|
|
// Description :
|
|
|
|
// All websocket stuff can be found here.
|
2023-05-06 11:32:41 +03:00
|
|
|
// More info can be found here https://socket.io/how-to/use-with-vue
|
2023-05-14 00:24:26 +02:00
|
|
|
import { createApp } from 'vue';
|
|
|
|
import io from 'socket.io-client';
|
2023-05-06 12:04:12 +03:00
|
|
|
|
2023-06-02 12:35:40 +03:00
|
|
|
// fixes issues when people not hosting this site on local network
|
2023-06-02 12:29:55 +03:00
|
|
|
const URL = process.env.NODE_ENV === "production" ? undefined : (import.meta.env.VITE_GPT4ALL_API);
|
|
|
|
const socket = new io(URL);
|
2023-05-03 00:02:00 +02:00
|
|
|
|
|
|
|
socket.onopen = () => {
|
|
|
|
console.log('WebSocket connection established.');
|
|
|
|
};
|
|
|
|
|
|
|
|
socket.onclose = (event) => {
|
|
|
|
console.log('WebSocket connection closed:', event.code, event.reason);
|
|
|
|
};
|
|
|
|
|
|
|
|
socket.onerror = (error) => {
|
|
|
|
console.error('WebSocket error:', error);
|
2023-05-06 12:04:12 +03:00
|
|
|
socket.disconnect()
|
2023-05-03 00:02:00 +02:00
|
|
|
};
|
|
|
|
|
2023-05-06 12:04:12 +03:00
|
|
|
socket.on("connect", () => {
|
2023-05-06 12:05:59 +03:00
|
|
|
console.log('WebSocket connected (websocket)');
|
2023-05-06 12:04:12 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("disconnect", () => {
|
2023-05-06 12:05:59 +03:00
|
|
|
console.log('WebSocket disonnected (websocket)');
|
2023-05-06 12:04:12 +03:00
|
|
|
});
|
|
|
|
|
2023-05-14 00:24:26 +02:00
|
|
|
const app = createApp(/* your root component */);
|
|
|
|
|
|
|
|
app.config.globalProperties.$socket = socket;
|
|
|
|
|
|
|
|
app.mount(/* your root element */);
|
|
|
|
|
|
|
|
export default socket;
|
|
|
|
|