From b0f224d79bae663ac9316275b4ca087121435829 Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Wed, 5 Aug 2020 17:00:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/information/information.vue | 21 ++++++++-- static/goeasy-1.0.17.js | 4 ++ static/imservice.js | 69 ++++++++++++++++++++++--------- 3 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 static/goeasy-1.0.17.js diff --git a/pages/information/information.vue b/pages/information/information.vue index c18dc2f..2250bbe 100644 --- a/pages/information/information.vue +++ b/pages/information/information.vue @@ -18,11 +18,11 @@ - + - {{item.title}} - {{item.contentes}} - {{item.title}} + {{item.name}} + {{item.text}} + {{item.time}} @@ -88,6 +88,10 @@ show: false }; }, + onShow(){ + this.information_dl = this.imService.friends; + this.imService.onFriendListChange=this.onFriendListChange; + }, onLoad() { // /消息模块的请求 this.messageIndex() @@ -99,13 +103,22 @@ let that = this setTimeout(function(){ that.imService.disconnect() + console.log("guanbi") },1000) setTimeout(function(){ + console.log("lianjie") that.imService.connectIM() },2000) } }, methods: { + onFriendListChange(onlineFriends) { + //todo:比较垃圾的处理方式,因为Uniapp的基于MAP的双向绑定在H5端不稳定,H5端偶尔会抽风 + // 下边这一行删掉,有时候页面可以更新,有时候不行,大家有优雅的方式,也欢迎跟我们沟通 + this.information_dl = this.imService.friends; + + this.$forceUpdate(); + }, // 选中某个复选框时,由checkbox时触发 checkboxChange(e) { //console.log(e); diff --git a/static/goeasy-1.0.17.js b/static/goeasy-1.0.17.js new file mode 100644 index 0000000..e362116 --- /dev/null +++ b/static/goeasy-1.0.17.js @@ -0,0 +1,4 @@ +// [AIV_SHORT] Build version: 1.0.17 - Tuesday, June 16th, 2020, 1:45:48 PM + !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.GoEasy=e():t.GoEasy=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return t[o].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function o(){if(g()&&uni.overrideShowHideAlready!==!0&&"undefined"!=typeof getApp().$options){uni.overrideShowHideAlready=!0;var t=getApp().$options,e=t.onShow[0],n=t.onHide[0];t.onShow[0]=function(){getApp().uniAppRunningBackend=!1,e.call(getApp())},t.onHide[0]=function(){getApp().uniAppRunningBackend=!0,n.call(getApp())}}}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r=n(1),s=n(35),c=[],a=!1,u=function(t){if(a){var e=(new Date).formatDate("yy-MM-dd hh:mm:ss.S");c.push(e+" "+t+"\n")}},p=function(){this.currentNumber=this.initialCurrentNumber()};p.prototype={maxNumber:parseInt("10"),number:function(){return this.currentNumber},initialCurrentNumber:function(){var t=this;return k()?t.currentNumber=parseInt(f("goeasyNode")):t.currentNumber||(t.currentNumber=m(1,parseInt("10"))),t.currentNumber>0&&t.currentNumber-1&&(e=!0,this.splice(n,1)),this.unshift(t);this.length>300;)this.pop();return e},x.prototype={debug:!1,socket:null,networkStatus:"initial",authorizeResult:null,subscribeBuffer:[],subscriptions:[],subscriptionChannelUUIDs:[],maxRetries:3,_manualConnect:!1,_manualDisconnectStatus:"initial",authorizeStatus:"initial",receivedGuids:new y,type:null,_copyConfig:function(t){this._appkey=t.appkey,this._otp=t.otp,this._isEmpty(t.userId)?(this._userId="anonymous-"+Math.floor(1e5*Math.random()+1),t.userId=this._userId):this._userId=this._trim(t.userId),this._isEmpty(t.userData)?this._userData="":this._userData=this._trim(t.userData),1==t.debug&&(this.debug=!0),this._isEmpty(t.type)||(this.type=t.type)},validateSubscription:function(t){var e=t.channel,n=t.channels;if("undefined"==typeof e&&"undefined"==typeof n)return t.onFailed({code:400,content:"channel is required"}),!1;if("undefined"!=typeof e&&"undefined"!=typeof n)return t.onFailed({code:400,content:"subscribe to either channel or channels, not both"}),!1;if("undefined"!=typeof e){if("number"==typeof e&&(e=e.toString()),this._isEmpty(e)&&"undefined"!=typeof t.onFailed)return t.onFailed({code:400,content:"channel is required"}),!1}else{if(!this._isArray(n)||0===n.length)return t.onFailed({code:400,content:"channels must be an array"}),!1;if(this._isArray(n)&&n.length>500)return t.onFailed({code:400,content:"channels over max length:500"}),!1;if(this._isArray(n)&&n.length>0)for(var o=0;o500?e({code:400,content:"userIds is over max length 500"}):this.socket.emit("hereNowByUserIds",n,function(t){e(t)}))},history:function(t,e){return"number"==typeof t.channel&&(t.channel=t.channel.toString()),this._isEmpty(t.channel)?void("undefined"!=typeof e&&e({code:400,content:"channel is required"})):void this.socket.emit("historyMessages",t,function(t){"undefined"!=typeof e&&e(t)})},disconnect:function(){var t=this;if(this._manualDisconnectStatus="disconnecting","connected"===this.networkStatus&&"authorized"===this.authorizeStatus&&200===this.authorizeResult.code){var e=function(){t.socket.disconnect()},n=function(){t._manualDisconnectStatus="disconnected"};t.tryEmit("manualDisconnect",null,e,n)}else this.socket.disconnect()},disconnected:function(){return"disconnected"===this.networkStatus},reconnect:function(){this._manualConnect=!0,this.socket.connect()},tryEmit:function(t,e,n,o){function i(){r.socket.emit(t,e,function(t){s=!0,"undefined"!=typeof o&&o(t)})}var r=this,s=!1,c=0;i();var a=setInterval(function(){var t=c===r.maxRetries;s||t?(clearInterval(a),t&&"undefined"!=typeof n&&n({code:408,content:"Server unreachable or timeout"})):(c++,e&&"undefined"!==e.retried&&(e.retried=c),i())},1e3)},_callbackEvents:function(t){var e=this;this.socket.on("message",function(t,n){var o=JSON.parse(t);if(!e.receivedGuids.unshiftGuid(o.i)){o.a&&e.socket.emit("ack",{publishGuid:o.i});var i=e.subscriptionChannelUUIDs[o.n];if(e._endWith(o.n,"presence"))"undefined"!=typeof e.subscriptions[i].onPresence&&e.subscriptions[i].onPresence(JSON.parse(o.c));else if("undefined"!=typeof e.subscriptions[i].onMessage){var r={time:o.t,channel:o.n,content:o.c};o.s&&(r.senderId=o.s),e.subscriptions[i].onMessage(r)}}}),this.socket.on("connect",function(){function n(){u("doAuthorize() emit authorize params:"+JSON.stringify(i)),e._isEmpty(i.artifactVersion)&&e.sendlogs(),e.socket.emit("authorize",i,function(n){if(u("doAuthorize() received authorize ack:"+JSON.stringify(n)),!r)if(r=!0,e.authorizeStatus="authorized",e._manualDisconnectStatus="initial",null==e.authorizeResult&&(e.authorizeResult={}),e.authorizeResult.code=n.resultCode,e.authorizeResult.content=n.content,200==n.resultCode){if(o(),null==e.authorizeResult.sid)e.authorizeResult.sid=n.sid;else if(e.authorizeResult.sid!=n.sid){e.authorizeResult.sid=n.sid;for(var i in e.subscriptions)e.subscriptions.hasOwnProperty(i)&&(u("doAuthorize() sid expired and will call doSubscribeAndCheckAck for channels:"+JSON.stringify(e.subscriptions[i])),e.doSubscribeAndCheckAck(e.subscriptions[i]))}for(var s in e.subscribeBuffer)e.subscribeBuffer.hasOwnProperty(s)&&(u("doAuthorize() will doSubscribeAndCheckAck from subscribeBuffer:"+JSON.stringify(e.subscribeBuffer[s])),e.doSubscribeAndCheckAck(e.subscribeBuffer[s]));"undefined"!=typeof t.onConnected&&t.onConnected()}else"undefined"!=typeof t.onConnectFailed&&t.onConnectFailed({code:n.resultCode,content:n.content})})}if("disconnecting"!==e._manualDisconnectStatus&&"disconnected"!==e._manualDisconnectStatus||e._manualConnect){e.authorizeStatus="authorizing",e.networkStatus="connected";var i={appkey:e._appkey,userId:e._userId,userData:e._userData,otp:e._otp,artifactVersion:"1.0.17",type:e.type};null!=e.authorizeResult&&(i.sid=e.authorizeResult.sid);var r=!1;n();var s=setInterval(function(){r||"connected"!=e.networkStatus?clearInterval(s):n()},1300)}}),this.socket.on("connect_error",function(e){"undefined"!=typeof t.onConnectFailed&&t.onConnectFailed({code:408,content:e})}),this.socket.on("disconnect",function(){e.networkStatus="disconnected",e.authorizeStatus="initial",e._manualConnect=!1,null==e.authorizeResult&&(e.authorizeResult={}),e.authorizeResult.code=408,e.authorizeResult.content="Server unreachable or timeout","undefined"!=typeof t.onDisconnected&&t.onDisconnected()})},_isEmpty:function(t){return"undefined"==typeof t||null==t||0==this._trim(t).length},_trim:function(t){return t.replace(/(^\s*)|(\s*$)/g,"")},_endWith:function(t,e){var n=new RegExp(e+"$");return n.test(t)},_isArray:function(t){return"[object Array]"==Object.prototype.toString.call(t)},log:function(t){"undefined"!=typeof window&&window.console&&this.debug&&console.log(t)},uuid_goeasy:function(){var t=s();return t.replace(/-/g,"")},sendlogs:function(){a&&this.socket.emit("log",{logs:c})}};var A=function(){var t;return function(e){return t&&!t.disconnected()||(t=new x(e)),t}}();t.exports=A},function(t,e,n){"use strict";function o(t,e){"object"===("undefined"==typeof t?"undefined":i(t))&&(e=t,t=void 0),e=e||{};var n,o=r(t),s=o.source,u=o.id,p=o.path,h=a[u]&&p in a[u].nsps,f=e.forceNew||e["force new connection"]||!1===e.multiplex||h;return f?n=c(s,e):(a[u]||(a[u]=c(s,e)),n=a[u]),o.query&&!e.query&&(e.query=o.query),n.socket(o.path,e)}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r=n(2),s=n(5),c=n(8);n(4)("socket.io-client");t.exports=e=o;var a=e.managers={};e.protocol=s.protocol,e.connect=o,e.Manager=n(8),e.Socket=n(30)},function(t,e,n){"use strict";function o(t,e){var n=t;e=e||"undefined"!=typeof location&&location,null==t&&(t=e.protocol+"//"+e.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?e.protocol+t:e.host+t),/^(https?|wss?):\/\//.test(t)||(t="undefined"!=typeof e?e.protocol+"//"+t:"https://"+t),n=i(t)),n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443")),n.path=n.path||"/";var o=n.host.indexOf(":")!==-1,r=o?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+r+":"+n.port,n.href=n.protocol+"://"+r+(e&&e.port===n.port?"":":"+n.port),n}var i=n(3);n(4)("socket.io-client:url");t.exports=o},function(t,e){var n=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,o=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];t.exports=function(t){var e=t,i=t.indexOf("["),r=t.indexOf("]");i!=-1&&r!=-1&&(t=t.substring(0,i)+t.substring(i,r).replace(/:/g,";")+t.substring(r,t.length));for(var s=n.exec(t||""),c={},a=14;a--;)c[o[a]]=s[a]||"";return i!=-1&&r!=-1&&(c.source=e,c.host=c.host.substring(1,c.host.length-1).replace(/;/g,":"),c.authority=c.authority.replace("[","").replace("]","").replace(/;/g,":"),c.ipv6uri=!0),c}},function(t,e){"use strict";t.exports=function(){return function(){}}},function(t,e,n){"use strict";function o(){}function i(t){var n=""+t.type;if(e.BINARY_EVENT!==t.type&&e.BINARY_ACK!==t.type||(n+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(n+=t.nsp+","),null!=t.id&&(n+=t.id),null!=t.data){var o=r(t.data);if(o===!1)return d;n+=o}return n}function r(t){try{return JSON.stringify(t)}catch(t){return!1}}function s(){this.reconstructor=null}function c(t){var n=0,o={type:Number(t.charAt(0))};if(null==e.types[o.type])return p("unknown packet type "+o.type);if(e.BINARY_EVENT===o.type||e.BINARY_ACK===o.type){for(var i="";"-"!==t.charAt(++n)&&(i+=t.charAt(n),n!=t.length););if(i!=Number(i)||"-"!==t.charAt(n))throw new Error("Illegal attachments");o.attachments=Number(i)}if("/"===t.charAt(n+1))for(o.nsp="";++n;){var r=t.charAt(n);if(","===r)break;if(o.nsp+=r,n===t.length)break}else o.nsp="/";var s=t.charAt(n+1);if(""!==s&&Number(s)==s){for(o.id="";++n;){var r=t.charAt(n);if(null==r||Number(r)!=r){--n;break}if(o.id+=t.charAt(n),n===t.length)break}o.id=Number(o.id)}if(t.charAt(++n)){var c=a(t.substr(n)),u=c!==!1&&(o.type===e.ERROR||f(c));if(!u)return p("invalid payload");o.data=c}return o}function a(t){try{return JSON.parse(t)}catch(t){return!1}}function u(t){this.reconPack=t,this.buffers=[]}function p(t){return{type:e.ERROR,data:"parser error: "+t}}var h=(n(4)("socket.io-parser"),n(6)),f=n(7);e.protocol=4,e.types=["CONNECT","DISCONNECT","EVENT","ACK","ERROR","BINARY_EVENT","BINARY_ACK"],e.CONNECT=0,e.DISCONNECT=1,e.EVENT=2,e.ACK=3,e.ERROR=4,e.BINARY_EVENT=5,e.BINARY_ACK=6,e.Encoder=o,e.Decoder=s;var d=e.ERROR+'"encode error"';o.prototype.encode=function(t,e){var n=i(t);e([n])},h(s.prototype),s.prototype.add=function(t){var e;if("string"!=typeof t)throw new Error("Unknown type: "+t);e=c(t),this.emit("decoded",e)},s.prototype.destroy=function(){this.reconstructor&&this.reconstructor.finishedReconstruction()},u.prototype.takeBinaryData=function(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){var e=binary.reconstructPacket(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null},u.prototype.finishedReconstruction=function(){this.reconPack=null,this.buffers=[]}},function(t,e,n){function o(t){if(t)return i(t)}function i(t){for(var e in o.prototype)t[e]=o.prototype[e];return t}t.exports=o,o.prototype.on=o.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},o.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this},o.prototype.off=o.prototype.removeListener=o.prototype.removeAllListeners=o.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n=this._callbacks["$"+t];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var o,i=0;i0&&!this.encoding){var t=this.packetBuffer.shift();this.packet(t)}},o.prototype.cleanup=function(){for(var t=this.subs.length,e=0;e=this._reconnectionAttempts)this.backoff.reset(),this.emitAll("reconnect_failed"),this.reconnecting=!1;else{var e=this.backoff.duration();this.reconnecting=!0;var n=setTimeout(function(){t.skipReconnect||(t.emitAll("reconnect_attempt",t.backoff.attempts),t.emitAll("reconnecting",t.backoff.attempts),t.skipReconnect||(i()?(t.reconnecting=!1,t.reconnect(),t.emitAll("reconnect_error","Uniapp running backend, skipped reconnect...")):t.open(function(e){e?(t.reconnecting=!1,t.reconnect(),t.emitAll("reconnect_error",e.data)):t.onreconnect()})))},e);this.subs.push({destroy:function(){clearTimeout(n)}})}},o.prototype.onreconnect=function(){var t=this.backoff.attempts;this.reconnecting=!1,this.backoff.reset(),this.updateSocketIds(),this.emitAll("reconnect",t)}},function(t,e,n){"use strict";t.exports=n(10),t.exports.parser=n(15)},function(t,e,n){"use strict";function o(t,e){return this instanceof o?(e=e||{},t&&"object"===("undefined"==typeof t?"undefined":r(t))&&(e=t,t=null),t?(t=p(t),e.hostname=t.host,e.secure="https"===t.protocol||"wss"===t.protocol,e.port=t.port,t.query&&(e.query=t.query)):e.host&&(e.hostname=p(e.host).host),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.agent=e.agent||!1,this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?443:80),this.query=e.query||{},"string"==typeof this.query&&(this.query=h.decode(this.query)),this.upgrade=!1!==e.upgrade,this.path=(e.path||"/engine.io").replace(/\/$/,"")+"/",this.forceJSONP=!!e.forceJSONP,this.jsonp=!1!==e.jsonp,this.forceBase64=!!e.forceBase64,this.enablesXDR=!!e.enablesXDR,this.timestampParam=e.timestampParam||"t",this.timestampRequests=e.timestampRequests,this.transports=e.transports||["polling","websocket"],this.transportOptions=e.transportOptions||{},this.readyState="",this.writeBuffer=[],this.prevBufferLen=0,this.policyPort=e.policyPort||843,this.rememberUpgrade=e.rememberUpgrade||!1,this.binaryType=null,this.onlyBinaryUpgrades=e.onlyBinaryUpgrades,this.perMessageDeflate=!1!==e.perMessageDeflate&&(e.perMessageDeflate||{}),!0===this.perMessageDeflate&&(this.perMessageDeflate={}),this.perMessageDeflate&&null==this.perMessageDeflate.threshold&&(this.perMessageDeflate.threshold=1024),this.pfx=e.pfx||null,this.key=e.key||null,this.passphrase=e.passphrase||null,this.cert=e.cert||null,this.ca=e.ca||null,this.ciphers=e.ciphers||null,this.rejectUnauthorized=void 0===e.rejectUnauthorized||e.rejectUnauthorized,this.forceNode=!!e.forceNode,this.isReactNative="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase(),("undefined"==typeof self||this.isReactNative)&&(e.extraHeaders&&Object.keys(e.extraHeaders).length>0&&(this.extraHeaders=e.extraHeaders),e.localAddress&&(this.localAddress=e.localAddress)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingIntervalTimer=null,this.pingTimeoutTimer=null,void this.open()):new o(t,e)}function i(t){var e={};for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s=n(11),c=n(6),a=(n(4)("engine.io-client:socket"),n(29)),u=n(15),p=n(3),h=n(22);t.exports=o,o.priorWebsocketSuccess=!1,c(o.prototype),o.protocol=u.protocol,o.Socket=o,o.Transport=n(14),o.transports=n(11),o.parser=n(15),o.prototype.createTransport=function(t){var e=i(this.query);e.EIO=u.protocol,e.transport=t;var n=this.transportOptions[t]||{};this.id&&(e.sid=this.id);var o=new s[t]({query:e,socket:this,agent:n.agent||this.agent,hostname:n.hostname||this.hostname,port:n.port||this.port,secure:n.secure||this.secure,path:n.path||this.path,forceJSONP:n.forceJSONP||this.forceJSONP,jsonp:n.jsonp||this.jsonp,forceBase64:n.forceBase64||this.forceBase64,enablesXDR:n.enablesXDR||this.enablesXDR,timestampRequests:n.timestampRequests||this.timestampRequests,timestampParam:n.timestampParam||this.timestampParam,policyPort:n.policyPort||this.policyPort,pfx:n.pfx||this.pfx,key:n.key||this.key,passphrase:n.passphrase||this.passphrase,cert:n.cert||this.cert,ca:n.ca||this.ca,ciphers:n.ciphers||this.ciphers,rejectUnauthorized:n.rejectUnauthorized||this.rejectUnauthorized, +perMessageDeflate:n.perMessageDeflate||this.perMessageDeflate,extraHeaders:n.extraHeaders||this.extraHeaders,forceNode:n.forceNode||this.forceNode,localAddress:n.localAddress||this.localAddress,requestTimeout:n.requestTimeout||this.requestTimeout,protocols:n.protocols||void 0,isReactNative:this.isReactNative});return o},o.prototype.open=function(){var t;if(this.rememberUpgrade&&o.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)t="websocket";else{if(0===this.transports.length){var e=this;return void setTimeout(function(){e.emit("error","No transports available")},0)}t=this.transports[0]}this.readyState="opening";try{t=this.createTransport(t)}catch(t){return this.transports.shift(),void this.open()}t.open(),this.setTransport(t)},o.prototype.setTransport=function(t){var e=this;this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",function(){e.onDrain()}).on("packet",function(t){e.onPacket(t)}).on("error",function(t){e.onError(t)}).on("close",function(){e.onClose("transport close")})},o.prototype.probe=function(t){function e(){if(h.onlyBinaryUpgrades){var t=!this.supportsBinary&&h.transport.supportsBinary;p=p||t}p||(u.send([{type:"ping",data:"probe"}]),u.once("packet",function(t){if(!p)if("pong"===t.type&&"probe"===t.data){if(h.upgrading=!0,h.emit("upgrading",u),!u)return;o.priorWebsocketSuccess="websocket"===u.name,h.transport.pause(function(){p||"closed"!==h.readyState&&(a(),h.setTransport(u),u.send([{type:"upgrade"}]),h.emit("upgrade",u),u=null,h.upgrading=!1,h.flush())})}else{var e=new Error("probe error");e.transport=u.name,h.emit("upgradeError",e)}}))}function n(){p||(p=!0,a(),u.close(),u=null)}function i(t){var e=new Error("probe error: "+t);e.transport=u.name,n(),h.emit("upgradeError",e)}function r(){i("transport closed")}function s(){i("socket closed")}function c(t){u&&t.name!==u.name&&n()}function a(){u.removeListener("open",e),u.removeListener("error",i),u.removeListener("close",r),h.removeListener("close",s),h.removeListener("upgrading",c)}var u=this.createTransport(t,{probe:1}),p=!1,h=this;o.priorWebsocketSuccess=!1,u.once("open",e),u.once("error",i),u.once("close",r),this.once("close",s),this.once("upgrading",c),u.open()},o.prototype.onOpen=function(){if(this.readyState="open",o.priorWebsocketSuccess="websocket"===this.transport.name,this.emit("open"),this.flush(),"open"===this.readyState&&this.upgrade&&this.transport.pause)for(var t=0,e=this.upgrades.length;t';r=document.createElement(t)}catch(t){r=document.createElement("iframe"),r.name=i.iframeId,r.src="javascript:0"}r.id=i.iframeId,i.form.appendChild(r),i.iframe=r}var i=this;if(!this.form){var r,s=document.createElement("form"),c=document.createElement("textarea"),a=this.iframeId="eio_iframe_"+this.index;s.className="socketio",s.style.position="absolute",s.style.top="-1000px",s.style.left="-1000px",s.target=a,s.method="POST",s.setAttribute("accept-charset","utf-8"),c.name="d",s.appendChild(c),document.body.appendChild(s),this.form=s,this.area=c}this.form.action=this.uri(),o(),t=t.replace(p,"\\\n"),this.area.value=t.replace(u,"\\n");try{this.form.submit()}catch(t){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){"complete"===i.iframe.readyState&&n()}:this.iframe.onload=n}}).call(e,function(){return this}())},function(t,e,n){"use strict";function o(t){var e=t&&t.forceBase64;u&&!e||(this.supportsBinary=!1),i.call(this,t)}var i=n(14),r=n(22),s=n(15),c=n(23),a=n(24);n(4)("engine.io-client:polling");t.exports=o;var u=function(){var t=n(25),e=new t({xdomain:!1});return null!=e.responseType}();c(o,i),o.prototype.name="polling",o.prototype.doOpen=function(){this.poll()},o.prototype.pause=function(t){function e(){n.readyState="paused",t()}var n=this;if(this.readyState="pausing",this.polling||!this.writable){var o=0;this.polling&&(o++,this.once("pollComplete",function(){--o||e()})),this.writable||(o++,this.once("drain",function(){--o||e()}))}else e()},o.prototype.poll=function(){this.polling=!0,this.doPoll(),this.emit("poll")},o.prototype.onData=function(t){var e=this,n=function(t,n,o){return"opening"===e.readyState&&e.onOpen(),"close"===t.type?(e.onClose(),!1):void e.onPacket(t)};s.decodePayload(t,this.socket.binaryType,n),"closed"!==this.readyState&&(this.polling=!1,this.emit("pollComplete"),"open"===this.readyState&&this.poll())},o.prototype.doClose=function(){function t(){e.write([{type:"close"}])}var e=this;"open"===this.readyState?t():this.once("open",t)},o.prototype.write=function(t){var e=this;this.writable=!1;var n=function(){e.writable=!0,e.emit("drain")};s.encodePayload(t,this.supportsBinary,function(t){e.doWrite(t,n)})},o.prototype.uri=function(){var t=this.query||{},e=this.secure?"https":"http",n="";!1!==this.timestampRequests&&(t[this.timestampParam]=a()),this.supportsBinary||t.sid||(t.b64=1),t=r.encode(t),this.port&&("https"===e&&443!==Number(this.port)||"http"===e&&80!==Number(this.port))&&(n=":"+this.port),t.length&&(t="?"+t);var o=this.hostname.indexOf(":")!==-1;return e+"://"+(o?"["+this.hostname+"]":this.hostname)+n+this.path+t}},function(t,e,n){"use strict";function o(t){this.path=t.path,this.hostname=t.hostname,this.port=t.port,this.secure=t.secure,this.query=t.query,this.timestampParam=t.timestampParam,this.timestampRequests=t.timestampRequests,this.readyState="",this.agent=t.agent||!1,this.socket=t.socket,this.enablesXDR=t.enablesXDR,this.pfx=t.pfx,this.key=t.key,this.passphrase=t.passphrase,this.cert=t.cert,this.ca=t.ca,this.ciphers=t.ciphers,this.rejectUnauthorized=t.rejectUnauthorized,this.forceNode=t.forceNode,this.isReactNative=t.isReactNative,this.extraHeaders=t.extraHeaders,this.localAddress=t.localAddress}var i=n(15),r=n(6);t.exports=o,r(o.prototype),o.prototype.onError=function(t,e){var n=new Error(t);return n.type="TransportError",n.description=e,this.emit("error",n),this},o.prototype.open=function(){return"closed"!==this.readyState&&""!==this.readyState||(this.readyState="opening",this.doOpen()),this},o.prototype.close=function(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this},o.prototype.send=function(t){if("open"!==this.readyState)throw new Error("Transport not open");this.write(t)},o.prototype.onOpen=function(){this.readyState="open",this.writable=!0,this.emit("open")},o.prototype.onData=function(t){var e=i.decodePacket(t,this.socket.binaryType);this.onPacket(e)},o.prototype.onPacket=function(t){this.emit("packet",t)},o.prototype.onClose=function(){this.readyState="closed",this.emit("close")}},function(t,e,n){"use strict";function o(t){try{t=a.decode(t,{strict:!1})}catch(t){return!1}return t}function i(t,e,n){for(var o=new Array(t.length),i=c(t.length,n),r=function(t,n,i){e(n,function(e,n){o[t]=n,i(e,o)})},s=0;s1?{type:p[i],data:t.substring(1)}:{type:p[i]}:h}var r=new Uint8Array(t),i=r[0],s=sliceBuffer(t,1);return f&&"blob"===e&&(s=new f([s])),{type:p[i],data:s}},e.encodePayload=function(t,n,o){function r(t){return t.length+":"+t}function c(t,o){e.encodePacket(t,!!a&&n,!0,function(t){o(null,r(t))})}"function"==typeof n&&(o=n,n=null);var a=s(t);return t.length?void i(t,c,function(t,e){return o(e.join(""))}):o("0:")},e.decodePayload=function(t,n,o){"function"==typeof n&&(o=n,n=null);var i;if(""===t)return o(h,0,1);for(var r,s,c="",a=0,u=t.length;a=55296&&e<=56319&&i65535&&(e-=65536,i+=l(e>>>10&1023|55296),e=56320|1023&e),i+=l(e);return i}function i(t,e){if(t>=55296&&t<=57343){if(e)throw Error("Lone surrogate U+"+t.toString(16).toUpperCase()+" is not a scalar value");return!1}return!0}function r(t,e){return l(t>>e&63|128)}function s(t,e){if(0==(4294967168&t))return l(t);var n="";return 0==(4294965248&t)?n=l(t>>6&31|192):0==(4294901760&t)?(i(t,e)||(t=65533),n=l(t>>12&15|224),n+=r(t,6)):0==(4292870144&t)&&(n=l(t>>18&7|240),n+=r(t,12),n+=r(t,6)),n+=l(63&t|128)}function c(t,e){e=e||{};for(var o,i=!1!==e.strict,r=n(t),c=r.length,a=-1,u="";++a=f)throw Error("Invalid byte index");var t=255&h[d];if(d++,128==(192&t))return 63&t;throw Error("Invalid continuation byte")}function u(t){var e,n,o,r,s;if(d>f)throw Error("Invalid byte index");if(d==f)return!1;if(e=255&h[d],d++,0==(128&e))return e;if(192==(224&e)){if(n=a(),s=(31&e)<<6|n,s>=128)return s;throw Error("Invalid continuation byte")}if(224==(240&e)){if(n=a(),o=a(),s=(15&e)<<12|n<<6|o,s>=2048)return i(s,t)?s:65533;throw Error("Invalid continuation byte")}if(240==(248&e)&&(n=a(),o=a(),r=a(),s=(7&e)<<18|n<<12|o<<6|r,s>=65536&&s<=1114111))return s;throw Error("Invalid UTF-8 detected")}function p(t,e){e=e||{};var i=!1!==e.strict;h=n(t),f=h.length,d=0;for(var r,s=[];(r=u(i))!==!1;)s.push(r);return o(s)}/*! https://mths.be/utf8js v2.1.2 by @mathias */ +var h,f,d,l=String.fromCharCode;t.exports={version:"2.1.2",encode:c,decode:p}},function(t,e){function n(t){return t.map(function(t){if(t.buffer instanceof ArrayBuffer){var e=t.buffer;if(t.byteLength!==e.byteLength){var n=new Uint8Array(t.byteLength);n.set(new Uint8Array(e,t.byteOffset,t.byteLength)),e=n.buffer}return e}return t})}function o(t,e){e=e||{};var o=new r;return n(t).forEach(function(t){o.append(t)}),e.type?o.getBlob(e.type):o.getBlob()}function i(t,e){return new Blob(n(t),e||{})}var r="undefined"!=typeof r?r:"undefined"!=typeof WebKitBlobBuilder?WebKitBlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder&&MozBlobBuilder,s=function(){try{var t=new Blob(["hi"]);return 2===t.size}catch(t){return!1}}(),c=s&&function(){try{var t=new Blob([new Uint8Array([1,2])]);return 2===t.size}catch(t){return!1}}(),a=r&&r.prototype.append&&r.prototype.getBlob;"undefined"!=typeof Blob&&(o.prototype=Blob.prototype,i.prototype=Blob.prototype),t.exports=function(){return s?c?Blob:i:a?o:void 0}()},function(t,e){e.encode=function(t){var e="";for(var n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e},e.decode=function(t){for(var e={},n=t.split("&"),o=0,i=n.length;o0);return e}function o(t){var e=0;for(p=0;p0&&t.jitter<=1?t.jitter:0,this.attempts=0}t.exports=n,n.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=0==(1&Math.floor(10*e))?t-n:t+n}return 0|Math.min(t,this.max)},n.prototype.reset=function(){this.attempts=0},n.prototype.setMin=function(t){this.ms=t},n.prototype.setMax=function(t){this.max=t},n.prototype.setJitter=function(t){this.jitter=t}},function(t,e,n){function o(t,e,n){var o=e&&n||0,p=e||[];t=t||{};var h=t.node||i,f=void 0!==t.clockseq?t.clockseq:r;if(null==h||null==f){var d=s();null==h&&(h=i=[1|d[0],d[1],d[2],d[3],d[4],d[5]]),null==f&&(f=r=16383&(d[6]<<8|d[7]))}var l=void 0!==t.msecs?t.msecs:(new Date).getTime(),y=void 0!==t.nsecs?t.nsecs:u+1,m=l-a+(y-u)/1e4;if(m<0&&void 0===t.clockseq&&(f=f+1&16383),(m<0||l>a)&&void 0===t.nsecs&&(y=0),y>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");a=l,u=y,r=f,l+=122192928e5;var b=(1e4*(268435455&l)+y)%4294967296;p[o++]=b>>>24&255,p[o++]=b>>>16&255,p[o++]=b>>>8&255,p[o++]=255&b;var g=l/4294967296*1e4&268435455;p[o++]=g>>>8&255,p[o++]=255&g,p[o++]=g>>>24&15|16,p[o++]=g>>>16&255,p[o++]=f>>>8|128,p[o++]=255&f;for(var v=0;v<6;++v)p[o+v]=h[v];return e?e:c(p)}var i,r,s=n(36),c=n(37),a=0,u=0;t.exports=o},function(t,e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var o=new Uint8Array(16);t.exports=function(){return n(o),o}}else{var i=new Array(16);t.exports=function(){for(var t,e=0;e<16;e++)0===(3&e)&&(t=4294967296*Math.random()),i[e]=t>>>((3&e)<<3)&255;return i}}},function(t,e){function n(t,e){var n=e||0,i=o;return[i[t[n++]],i[t[n++]],i[t[n++]],i[t[n++]],"-",i[t[n++]],i[t[n++]],"-",i[t[n++]],i[t[n++]],"-",i[t[n++]],i[t[n++]],"-",i[t[n++]],i[t[n++]],i[t[n++]],i[t[n++]],i[t[n++]],i[t[n++]]].join("")}for(var o=[],i=0;i<256;++i)o[i]=(i+256).toString(16).substr(1);t.exports=n}])}); \ No newline at end of file diff --git a/static/imservice.js b/static/imservice.js index 4e8d1b6..2fa0de8 100644 --- a/static/imservice.js +++ b/static/imservice.js @@ -14,6 +14,8 @@ function Friend(uuid, name, avatar) { this.avatar = avatar; this.online = false; this.unReadMessage = 0; + this.text = ""; + this.time = ""; } function Group(uuid, name, avatar) { @@ -144,24 +146,35 @@ IMService.prototype.resetFriendUnReadMessage = function (friend) { //连接GoEasy IMService.prototype.connectIM = function () { //初始化IM相关的监听器 + try { this.initialIMListeners(); - this.im.connect({ - id: this.currentUser.uuid, - data: { - avatar: this.currentUser.avatar, - name: this.currentUser.name - } - }).then(() => { - console.log('连接成功') - //订阅与自己相关的群信息 - this.subscribeGroupMessage(); - //初始化好友们的在线状态 - this.initialFriendOnlineStatus(); - //订阅我的好友们的上下线信息 - this.subscribeFriendsPresence(); - }).catch(error => { - console.log('连接失败,请确保网络正常,appkey和host正确,code:' + error.code + " content:" + error.content); - }); + + } catch (error) { + console.log(123) + } + try { + this.im.connect({ + id: this.currentUser.uuid, + data: { + avatar: this.currentUser.avatar, + name: this.currentUser.name + } + }).then(() => { + console.log('连接成功') + //订阅与自己相关的群信息 + this.subscribeGroupMessage(); + //初始化好友们的在线状态 + this.initialFriendOnlineStatus(); + //订阅我的好友们的上下线信息 + this.subscribeFriendsPresence(); + }).catch(error => { + console.log('连接失败,请确保网络正常,appkey和host正确,code:' + error.code + " content:" + error.content); + this.connectIM() + }); + } catch (error) { + console.log(12323) + } + }; //IM监听 @@ -192,9 +205,12 @@ IMService.prototype.initialIMListeners = function () { //如果不是自己发的,朋友未读消息数 +1 if (message.senderId != this.currentUser.uuid) { let friend = this.friends[message.senderId]; - if(friend && friend == undefined){ + console.log(friend) + // return ; + let that = this + if(!friend && friend == undefined){ const token = uni.getStorageSync('token'); - console.log(token,that.id) + console.log(token) uni.request({ url:"https://dmmall.sdbairui.com/api/Specialci/getAtwillUserInfo", data:{ @@ -206,13 +222,28 @@ IMService.prototype.initialIMListeners = function () { }, success(res){ console.log(res) + that.friends[message.senderId] = new Friend(res.data.data.member_id, res.data.data.member_nickname, res.data.data.member_avatar); + friend = that.friends[message.senderId]; + console.log(friend) + friend.unReadMessage++; + friend.text = message.type != "text" ? "其他消息" : message.payload.text + let time = new Date(message.timestamp) + friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds() + that.onFriendListChange(that.friends); + console.log(that.friends) } }) }else{ + console.log(friend) friend.unReadMessage++; + friend.text = message.type != "text" ? "其他消息" : message.payload.text + let time = new Date(message.timestamp) + friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds() this.onFriendListChange(this.friends); + console.log(this.friends) } + } //更新私聊消息记录 let friendId;