mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
488 B
TypeScript
26 lines
488 B
TypeScript
4 years ago
|
import { io } from 'socket.io-client';
|
||
|
|
||
|
const socket = io('http://127.0.0.1:3000', {
|
||
|
transports: ['websocket'],
|
||
|
forceNew: true,
|
||
|
});
|
||
|
|
||
|
// client-side
|
||
|
socket.on('connect', () => {
|
||
|
console.log(socket.id); // x8WIv7-mJelg7on_ALbx
|
||
|
|
||
|
socket.emit('aaa', 'ddd');
|
||
|
});
|
||
|
|
||
|
socket.on('disconnect', () => {
|
||
|
console.log(socket.id); // undefined
|
||
|
});
|
||
|
|
||
|
socket.on('connect_error', (err) => {
|
||
|
console.log('connect_error', err.message);
|
||
|
});
|
||
|
|
||
|
socket.io.on('error', () => {
|
||
|
console.log('error');
|
||
|
});
|