shipthis
Version:
ShipThis manages building and uploading your Godot games to the App Store and Google Play.
37 lines (34 loc) • 928 B
JavaScript
import { useEffect } from 'react';
import { io } from 'socket.io-client';
import { N as WS_URL, O as getAuthToken } from './index-BwnzoldS.js';
function useWebSocket(listeners = []) {
const log = () => {
};
useEffect(() => {
if (listeners.length === 0) {
return;
}
const token = getAuthToken();
const socket = io(WS_URL, {
auth: { token },
forceNew: true
});
socket.on("connect", () => log());
for (const listener of listeners) {
const pattern = listener.getPattern();
const bindSocket = (pattern2) => {
const boundListener = listener.eventHandler.bind(listener, pattern2);
socket.on(pattern2, boundListener);
};
if (Array.isArray(pattern)) {
pattern.forEach(bindSocket);
continue;
}
bindSocket(pattern);
}
return () => {
socket.disconnect();
};
}, []);
}
export { useWebSocket as u };