1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- var self = null;
- var socket = null;
- var docInfo = null;
- mui.plusReady(function(){
- self = plus.webview.currentWebview();
- docInfo = JSON.parse(plus.storage.getItem("docInfo"));
- connectSocket();
- });
- //判断是否有患者参与
- function connectSocket(){
- imClient.Sessions.getParticipants(self.sessionId, function(rs){
- var isPatient = false;
- $.each(rs , function(i, v) {
- if(v.is_patient==1){
- isPatient = true;//是否有患者
- }
- });
- createSocketConnect(isPatient);
-
- }, function(msg){
- console.log("e:"+JSON.stringify(msg))
- mui.toast("获取成员列表失败!");
- })
- }
- //加载socket组件 (连接socket)
- function createSocketConnect(isPatient){
- jQuery.getScript(socketUrl+"/socket.io/socket.io.js?"+Math.random()).done(function() {
- socket = io.connect(socketUrl);
- socket.emit('login', {userId: docInfo.code, password: docInfo.code,sessionId:sessionId,clientType:"doctor"});
- socket.on('message', function (data) {
- firstMsg = data;
- var p2pHtml = plus.webview.getWebviewById("p2p");
- var p2dzixunHtml = plus.webview.getWebviewById("p2dzixun");
- if((p2pHtml || p2dzixunHtml)){
- if(data.read){//已读消息
- if(data.read=="all"){//将消息全部置为已读
- if(!isPatient){//医生和医生对聊
- setTimeout(function(){
- $("#contain").find("dl.chat-right").find(".c-msg").find(".yidu").html("已读");
- },100)
- }else{//医生和居民对聊
- //$("#contain").find("dl.chat-right").find(".c-msg").find(".yidu").html("居民已读");
- // TODO "居民已读" 临时改为 "已读"
- setTimeout(function(){
- $("#contain").find("dl.chat-right").find(".c-msg").find(".yidu").html("已读");
- },100)
- }
- }
- if(data.read=="one"){
- if(!isPatient){//医生和医生对聊
- setTimeout(function(){
- $("#contain").find("dl.chat-right").last().find(".yidu").html("已读");
- },100)
- }else{//医生和居民对聊
- // $("#contain").find("dl").last().find(".yidu").html("居民已读");
- // TODO "居民已读" 临时改为 "已读"
- setTimeout(function(){
- $("#contain").find("dl.chat-right").last().find(".yidu").html("已读");
- },100)
- }
- }
- }else{
- // getNewMsgs(false);//消息接收
- var arr = [];
- arr.push(data);
- getNewMsgHandle( arr, false );
- }
- }else{//消息接收
- if(!data.read){
- getNewMsgs(false);
- }
- }
-
- });
-
- socket.on('error', function (data) {
- console.log(data);
- });
-
- socket.on('ack', function (data) {
- console.log(data);
- });
- function getLocalTime(nS) {
- return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
- }
- plus.storage.setItem("imSocket",socket);
- plus.storage.setItem("imSessionId",sessionId);
- })
- .fail(function() {
- plus.nativeUI.toast("医生实时对话连接失败!",{duration:"long"});
- });
- }
- //断开socket连接
- function logoutSocketConnect(){
- socket.emit('logout');
- }
|