1234567891011121314151617181920212223242526272829303132333435 |
- class Socket {
- constructor({
- socket
- }) {
- this.baseUrl = socket;
- this.socketEstablish = false; //是否建立链接
- this.socketCallback = () => {
- };
- }
- initSocket() {
- this.SocketTask = uni.connectSocket({
- url: this.baseUrl + '/waserver/webSocket/' + uni.getStorageSync('userMsg').token,
- complete: (res) => {
- console.log(res)
- }
- })
- this.SocketTask.onOpen(function (res) {
- this.socketEstablish = true;
- })
- this.SocketTask.onMessage(function (res) {
- // this.socketCallback(res)
- this.$Http.updateMessage && this.$Http.updateMessage()
- })
- this.SocketTask.onError(function (res) {
- this.socketEstablish = false;
- })
- this.SocketTask.onClose(function (res) {
- this.socketEstablish = false;
- })
- }
- }
- export {
- Socket
- }
|