Kopie van https://gitlab.com/studieverenigingvia/ict/centurion met een paar aanpassingen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
centurion/frontend/src/util/socket.ts

42 lines
786 B

// const socket = io(window.location.protocol + "//" + window.location.hostname + ":3001");
const socket = {
on: (...args: any[]) => {
},
once: (...args: any[]) => {
},
off: (...args: any[]) => {
},
id: '1'
};
export default socket;
/**
* Promisify emit.
* @param event
* @param arg
*/
export function emit(socket: SocketIOClient.Socket, event: string, arg: any = null) {
return new Promise((resolve, reject) => {
const cb = (err: any, res: any) => {
if (err) {
return reject(err);
}
resolve(res);
};
if (arg === null || typeof arg === 'undefined') {
socket.emit(event, cb);
} else {
socket.emit(event, arg, cb);
}
})
}