Skip to content

Instantly share code, notes, and snippets.

@hoangsetup
Last active September 20, 2021 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoangsetup/b6e3f5bce9265e3928e2d8e3f7abd598 to your computer and use it in GitHub Desktop.
Save hoangsetup/b6e3f5bce9265e3928e2d8e3f7abd598 to your computer and use it in GitHub Desktop.
// src/socket.ts
import { Server } from 'socket.io';
import * as http from 'http';
let io: Server;
export function initSocketIo(server: http.Server) {
if (io) {
return;
}
io = new Server(server);
io.on('connection', (socket) => {
console.log('a user connected', socket.id);
});
}
export function emitCallStateChange(data: {
customerId: string,
customerName: string,
phone: string,
state: string,
date: string,
}) {
if (!io) {
return;
}
io.emit('call_state_change', data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment