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.
29 lines
636 B
29 lines
636 B
import io from "socket.io-client";
|
|
|
|
|
|
const socket = io(window.location.protocol + "//" + window.location.hostname + ":3001");
|
|
export default socket;
|
|
|
|
/**
|
|
* Promisify emit.
|
|
* @param event
|
|
* @param arg
|
|
*/
|
|
export function emit(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);
|
|
}
|
|
|
|
})
|
|
} |