搜索
您的当前位置:首页正文

ionic3 连接socket

来源:知库网

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 =  +this.storage.get('token'));

  }

}

//发送信息

sendMessage(key, message) {

this.socket.emit(key, message);

}

//断掉链接

disconnet() {

this.socket.disconnect(true);

}
Top