25 lines
605 B
TypeScript
25 lines
605 B
TypeScript
import * as io from 'socket.io-client'
|
|
|
|
let host = process.env.TERA_HOST || 'http://127.0.0.1:8080/pow'
|
|
|
|
let powClient = io(host, {
|
|
path: '/ws'
|
|
})
|
|
|
|
powClient.on('connect', () => {
|
|
console.log(`Client ${powClient.id} connect ...`)
|
|
SendToWebClient(`${global.PROCESS_NAME} Connect to ${host} Successful...`)
|
|
powClient.send({ cmd: "online", message: "OK" })
|
|
});
|
|
|
|
powClient.on('disconnect', (error) => {
|
|
console.log(`Client disconnect Error: ${error}...`)
|
|
process.exit(0)
|
|
});
|
|
|
|
function SendToWebClient(msg: any) {
|
|
powClient.emit('web', msg)
|
|
}
|
|
|
|
export { powClient, SendToWebClient }
|