Last active
March 29, 2016 10:23
-
-
Save stableShip/2e0e8d6f6cb5e747f41b to your computer and use it in GitHub Desktop.
通讯协议相关业务逻辑
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 通讯协议相关业务逻辑 | |
| ###### `(3. socket消息的定义在/model/config/protocol中,各个事件对应的业务在哪些接口或模块?各自的业务流程和场景是怎样的?)` | |
| ### C2S_REGISTER_REQ :注册身份请求 | |
| 用户登陆时,客户端发送`C2S_REGISTER_REQ`socketio协议请求: | |
| ``` | |
| message_sign.send({ | |
| type: MsgType.C2S_REGISTER_REQ, | |
| data:{ | |
| type:'user', | |
| uid:data.uid, | |
| deviceid:data.deviceid | |
| } | |
| }); | |
| ``` | |
| 服务端对根据客户端传过来的uid,查找用户账号信息,根据用户类型(user,doctor),进行相应的登陆信息记录,http建立jpush映射. | |
| ### S2C_ALONECHAT_PUSH : 用户与医生的对话消息 | |
| 客户端发送http请求: | |
| 1. 值班医生代答(/admin/duty/sendmsg)回答居民疑问 | |
| 2. 处理签约单,发送签约提示信息给居民(接受或拒绝)(/doctor/signedprocess) | |
| 3. 发送聊天信息--私聊(user|doctor/alonechat/send) | |
| 4. 更新预约单,发送预约信息给居民(办理或拒绝)(doctor/reservation/update) | |
| 5. 退出视频通话(居民和医生),发送视频关闭信息(user | doctor/videoCall/disconnect) | |
| 服务端根据策划数据组合需要的消息数据,储存到数据库表`socialMessage`中,再发送相应的消息 | |
| ``` | |
| model.socialMessage.create(info,function(err,smdoc){ | |
| if(err){ | |
| return callback(ERROR.FA_SYS); | |
| } | |
| model.jmsocket.sendTo(userid,{ | |
| type: MsgType.S2C_ALONECHAT_PUSH, | |
| data: smdoc.toJSON() | |
| }); | |
| }); | |
| ``` | |
| ### S2C_SIGNED_PUSH : 签约消息推送 | |
| 客户端发送http请求: | |
| 1. 微信签约,发送签约信息给居民和医生(social/signed2) | |
| 2. 处理签约单,发送签约信息(doctor/signedprocess) | |
| 3. 处理签约单,发送签约信息(doctor/signedprocess2) | |
| 服务端查找创建相应的签约信息,储存在数据库表`socialSigned`中,再发送签约信息 | |
| ### S2C_SYSTEM_PUSH : 后台推送给前端 | |
| 客户端发送http请求: | |
| 1. 平台推送 (admin/platform/push), | |
| 服务端创建平台文章`platformTopic`后,再创建系统消息记录`socialMessage`,在发送相应的平台推送消息给前端(居民与医生) | |
| ```javascript | |
| async.waterfall([ | |
| function(cb){ | |
| model.platformTopic.create(info, function (err, doc) { | |
| if (err) { | |
| return cb(ERROR.FA_SYS); | |
| } | |
| cb(null, doc); | |
| }) | |
| } | |
| ],function(err,result){ | |
| model.socialMessage.findOneAndUpdate({uid: user.uid, tags: 'system'}, info, {upsert: true}, function (err, doc) { | |
| if (err) return model.logger.error(req.path, err); | |
| model.jmsocket.sendTo(user.uid, { | |
| type: MsgType.S2C_SYSTEM_PUSH, | |
| data: doc.toJSON() | |
| }); | |
| callback(); | |
| }); | |
| } | |
| ``` | |
| ### S2C_RESERVATION_PUSH : 医生端监听用户预约 | |
| 客户端发送http请求: | |
| 1. 提交预约申请 (user/reservation/create) | |
| 服务端同样使用`socialMessage`表储存预约申请提醒信息,再发送给医生端 | |
| ``` | |
| model.socialMessage.create(obj, function (err, smdoc) { | |
| if (err) { | |
| return; | |
| } | |
| model.jmsocket.sendTo(doctorid.toString(), { | |
| type: MsgType.S2C_RESERVATION_PUSH, | |
| data: smdoc.toJSON() | |
| }); | |
| }); | |
| ``` | |
| ### S2C_DOCTORMSG_PUSH : 医生推送消息给用户 | |
| 客户端发送http请求: | |
| 1. 医生推送消息给居民(doctor/usermessage/push) | |
| 2. 医生推送消息给居民(doctor/usermessage/push2) | |
| 3. 推送消息给本团队所有居民(doctor/usermessage/pushall) | |
| 服务端同样使用`socialMessage`表储存医生推送消息,再发送给居民 | |
| ```javascript | |
| model.socialMessage.findOneAndUpdate({uid:uid,tags:'doctormsg'},info,{upsert:true},function(err,doc){ | |
| if(err) { | |
| model.logger.error(req.path, err); | |
| return; | |
| } | |
| if(doc){ | |
| model.jmsocket.sendTo(uid,{ | |
| type: MsgType.S2C_DOCTORMSG_PUSH, | |
| data: doc.toJSON() | |
| }); | |
| } | |
| callback(); | |
| }); | |
| ``` | |
| ### S2C_TEAMMATECHAT_PUSH : 队友之间对话消息 | |
| 客户端发送http请求: | |
| 1. 值班医生代答(admin/duty/sendmsg) | |
| 服务端同样使用`socialMessage`表储存对话信息 ,加上了`socialDialog`用于储存房间内的对话,再发送到房间 | |
| ```javascript | |
| model.socialMessage.findOne({uid: uid, tags: {$all: doc.tags}, 'data.roomid': roomid}, function ... | |
| //省略 | |
| model.socialDialog.update({_id: dialogid}, {$set: {'dutyinfo.dutyuid': dutyuid, 'dutyinfo.process': 1}}, function (err, osddoc) { | |
| ``` | |
| ### S2C_DOCTORFRIENDCHAT_PUSH : 医生好友对话消息 | |
| 客户端发送http请求: | |
| 1. 值班医生代答(admin/duty/sendmsg) | |
| 服务端同样使用`socialMessage`表储存对话信息 ,加上了`socialDialog`用于储存房间内的对话,再发送到房间 | |
| ```javascript | |
| model.socialMessage.findOne({uid: uid, tags: {$all: doc.tags}, 'data.roomid': roomid}, function ... | |
| //省略 | |
| model.socialDialog.update({_id: dialogid}, {$set: {'dutyinfo.dutyuid': dutyuid, 'dutyinfo.process': 1}}, function (err, osddoc) { | |
| ``` | |
| ### S2C_FRIENDAPPLY_PUSH : 好友请求消息 | |
| 客户端发送http请求: | |
| 1. 添加社区医生好友(doctor/doctorfriend/add) | |
| 服务端创建好友关系后直接发送好友请求信息 | |
| ```javascript | |
| model.friend.create(info,function(err,doc){ | |
| if(err){ | |
| return res.send(ERROR.FA_SYS); | |
| } | |
| res.send({}); | |
| model.jmsocket.sendTo(friendid,{ | |
| type: MsgType.S2C_FRIENDAPPLY_PUSH, | |
| data: { | |
| title:'请求添加好友', | |
| content:friendname+'用户向你添加好友请求', | |
| updatetime:new Date() | |
| } | |
| }); | |
| }); | |
| ``` | |
| ### S2C_SOCIAL_PUSH : 社区后台推送给前端 | |
| 客户端发送http请求: | |
| 1. 社区推送信息(admin/socialpush/create) | |
| 服务端同样使用`socialMessage`表储存社区信息,然后推送给医生或居民 | |
| ```javascript | |
| model.socialMessage.findOneAndUpdate({uid: doctor.uid, tags: 'social'}, info, {upsert: true}, function (err, doc) { | |
| if (err) return model.logger.error(req.path, err); | |
| model.jmsocket.sendTo(doctor.uid, { | |
| type: MsgType.S2C_SOCIAL_PUSH, | |
| data: doc.toJSON() | |
| }); | |
| callback(); | |
| }); | |
| ``` | |
| ### S2C_DIFFERENT_CONNECTION : 账号存在异地连接 | |
| 客户端登陆账号时,发送socket消息: `C2S_REGISTER_REQ` | |
| 服务端检测到有活动的socket存在时,发送`S2C_DIFFERENT_CONNECTION`给客户端进行处理 | |
| ``` | |
| conn.uid = doc._id.toString(); | |
| var curconn = model.jmsocket.conns[conn.uid]; | |
| if(curconn && conn != curconn){ | |
| model.jmsocket.sendTo(conn.uid,{ | |
| type: MsgType.S2C_DIFFERENT_CONNECTION, | |
| data: {} | |
| }); | |
| } | |
| ``` | |
| ---- | |
| ### S2C_REMIND_PUSH: 值班医生的提醒消息 | |
| 客户端发送http请求: | |
| 1. 值班医生提醒(admin/duty/remindmsg) | |
| 服务端同样使用`socialMessage`表储存对话信息 ,加上了`socialDialog`用于储存房间内的对话,再发送到房间 | |
| ---- | |
| ### S2C_UNSIGNED_PUSH: 解除签约消息推送 | |
| 客户端发送http请求: | |
| 1. 解除签约 (doctor/rejectsigned) | |
| 服务端对基础业务处理后,直接发送消息 | |
| ``` | |
| model.jmsocket.sendTo(result.uid.toString(),{ | |
| type: MsgType.S2C_UNSIGNED_PUSH, | |
| data: { | |
| title:'解除签约通知', | |
| team:result.stid.name, | |
| content:'您的签约已被解除: '+result.reason, | |
| sid:result.sid | |
| } | |
| }); | |
| ``` | |
| ---- | |
| ### S2C_TEAMCHAT_PUSH 讨论组的对话消息 | |
| 客户端发送http请求: | |
| 1. 发送讨论组聊天消息 (user|doctor/send) | |
| 服务端使用`socialMessage`表储存消息,在发送给房间内相应用户(model/discucssion/SendChatMessage) | |
| ---- | |
| ### S2C_TEAMMEMBER_ENTER 讨论组加入成员的消息 | |
| 客户端发送http请求: | |
| 1. 讨论组加人 (user|doctor/addmember) | |
| 服务端直接遍历房间人员信息,发送加入信息(model/discucssion/AddRoomMember) | |
| ---- | |
| ### S2C_TEAMMEMBER_LEAVE: 讨论组成员离开的消息 | |
| 客户端发送http请求: | |
| 1. 值班医生退出聊天室 (doctor/removemember) | |
| 2. 居民端删除历史通讯录 (user/contacts/remove) | |
| 服务端直接遍历房间人员信息,发送离开信息(model/discucssion/RemoveRoomMember) | |
| ---- | |
| ### S2C_VIDEOCALL_INVITE : 发起视频聊天邀请推送消息 | |
| 客户端发送http请求: | |
| 1. 发起视频会话邀请(user | doctor/videoCall/invite') | |
| 服务端查找房间人员信息,记录邀请请求到`socialDialog`, 发送视频聊天邀请 | |
| ### S2C_VIDEOCALL_END : 服务器通知在线一端另外一端已经下线 | |
| 客户端发送http请求: | |
| 1. 退出视频会话(user | doctor/videoCall/disconnect) | |
| 服务端记录视频聊天退出信息到`socialDialog`, 添加视频退出提醒到`socialMessage`,发送视频退出信息非挂断的另一方. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment