Last active
September 20, 2021 07:52
-
-
Save hoangsetup/b6e3f5bce9265e3928e2d8e3f7abd598 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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