|
@ -1,21 +1,34 @@
|
|
|
/**
|
|
|
* Created by Sand on 2016/11/17.
|
|
|
* author: Sand
|
|
|
* since: 2016/11/17
|
|
|
*/
|
|
|
"use strict";
|
|
|
|
|
|
var log = require("../util/log.js");
|
|
|
var PatientClient = require('./PatientClient');
|
|
|
|
|
|
var clients = {};
|
|
|
var clientCache = require('../models/socket.io/client.cache').clientCache();
|
|
|
var PatientClient = require('./../models/socket.io/patient.client');
|
|
|
|
|
|
module.exports.onConnection = function(socket){
|
|
|
log.info("Patient connected from WebSocket.");
|
|
|
/**
|
|
|
* 建立WS连接,发送welcome消息要求登录。之后响应login消息保存用户通信凭据。
|
|
|
*
|
|
|
* @param socket
|
|
|
*/
|
|
|
module.exports.onConnection = function (socket) {
|
|
|
socket.on('login', function (data) {
|
|
|
log.info('User login: ' + data.userId);
|
|
|
|
|
|
socket.on('data', function (data) {
|
|
|
var patientClient = new PatientClient(socket);
|
|
|
patientClient.userId = data.userId;
|
|
|
patientClient.password = data.password;
|
|
|
|
|
|
clientCache.addClient(patientClient);
|
|
|
});
|
|
|
socket.emit('welcome', {message: 'Welcome to IM server.'});
|
|
|
};
|
|
|
|
|
|
module.exports.onDisconnect = function () {
|
|
|
socket.on('disconnect', function () {
|
|
|
log.info("User disconnect: ", clientCache.findBySocket(socket).userId);
|
|
|
clientCache.removeByUserSocket(socket);
|
|
|
});
|
|
|
|
|
|
socket.emit('welcome', {message: 'Welcome to connect IM server, please login.'});
|
|
|
};
|