123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /// +----------------------------------------------------------------------
- // | HTTP 全局监听口[监听远程执行之后]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016-2017 ,Lioc All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: Mr Table <admin@hjf.pw>
- // +----------------------------------------------------------------------
- import store from "../../store";
- import md5 from "../vendor/md5.js";
- import Message from "../socket/Message.js";
- class SocketEvent {
- app = null;
- constructor(app) {
- this.app = app;
- }
- /**
- * 打开项目
- * @param {Object} res
- */
- onOpen(res) {
- uni.$emit('socketOpen',res);
- let user = store.state.user;
- if(user != null) {
- this.app.webSocket.send(new Message(user.token,"auth",true),
- (res)=>{
- let data = JSON.parse(res);
- if(data.type == 'auth_yes') {
-
- }
-
- if(data.type == 'auth_error') {
- //store.commit('loginOut');
- // uni.showToast({ 'title' : data.msg,duration : 3000,icon:'none'});
- }
-
- this.app.request.get("chatBagenum").then(res=>{
- if(res.code == 200) {
- store.commit('setTxbagenum',res.data);
- }
- }).catch((err)=>{
-
- });
-
- },()=>{
- console.log('测试失败了');
- });
- }
- }
- onMessage(res) {
- if(res.code == 'chat' || res.code == 'group_chat') {
- let bagenum = store.state.txbagenum;
- //bagenum.count ++;
- bagenum.chatCount ++;
- store.commit('setTxbagenum',bagenum);
- }
-
- //对方添加好友
- if(res.code == 'friend_add') {
- if(this.app.utils.isJSON(res.data)) {
- var data= JSON.parse(res.data);
- //消息提示
- let bagenumAr = store.state.txbagenum;
- bagenumAr.applyCount ++;
- store.commit('setTxbagenum',bagenumAr);
- }
- }
-
- //申请进群
- if(res.code == 'group_add') {
-
- }
-
-
- uni.$emit('socketMessage',res);
- return '';
- }
-
- onError(res) {
- uni.$emit('socketClose',res);
- }
-
- onStop(res) {
- uni.$emit('socketClose',res);
- }
-
- onClose(res) {
- uni.$emit('socketClose',res);
- }
- onSendError(res){
- uni.$emit('socketSendError',res);
- }
- onSendSuccess(res) {
- uni.$emit('socketSendSuccess',res);
- }
-
- onHeartBeat(res){
- uni.$emit('socketHeartBeat',res);
- }
- }
- export default SocketEvent;
|