1.安装socket
npm install socket.io
2.建立socekt provider
import * as io from 'socket.io-client';
3.provider的方法
connetct() {
if (Boolean(this.storage.get('token')) ==true) {
this.socket = io('http://xxx.xxxx.com:3001/?token=' +this.storage.get('token'));
}
}
//发送信息
sendMessage(key, message) {
this.socket.emit(key, message);
}
//断掉链接
disconnet() {
this.socket.disconnect(true);
}