Commit 4f19e789 by 蒋勇

d

parent 77b4cb5b
......@@ -8,7 +8,7 @@
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/center-manage/main.js"
"program": "${workspaceFolder}/im-center/main.js"
}
]
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ const request = require('request');
const jwk2pem = require('pem-jwk').jwk2pem
const jwt = require('jsonwebtoken')
const CryptoJS = require("crypto-js")
const deskey = '647a68c9-da01-40d3-9763-1ffa0f64cf3f'
class System {
static declare (ns) {
var ar = ns.split('.');
......@@ -309,8 +310,16 @@ class System {
return P
}
static encriptByDes (originStr) {
var keyHex = CryptoJS.enc.Utf8.parse(deskey);
var encrypted = CryptoJS.DES.encrypt(originStr, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
console.log(encrypted.toString());
return encrypted.toString();
}
static desEncript (desstr) {
let deskey = '647a68c9-da01-40d3-9763-1ffa0f64cf3f'
var keyHex = CryptoJS.enc.Utf8.parse(deskey);
// direct decrypt ciphertext
var decrypted = CryptoJS.DES.decrypt({
......
......@@ -105,62 +105,62 @@ class RedisClient {
}
});
}
async subscribe(channel, chatserver) {
async subscribe (channel, chatserver) {
if (!this.chatserver) {
this.chatserver = chatserver;
}
return this.subclient.subscribeAsync(channel);
}
async unsubscribe(channel) {
async unsubscribe (channel) {
//this.chatserver=null;
return this.subclient.unsubscribeAsync(channel);
}
async subscribeTask(channel, taskmanager) {
async subscribeTask (channel, taskmanager) {
if (!this.taskmanager) {
this.taskmanager = taskmanager;
}
return this.subclient.subscribeAsync(channel);
}
async publish(channel, msg) {
async publish (channel, msg) {
console.log(channel + ":" + msg);
return this.client.publishAsync(channel, msg);
}
async rpush(key, val) {
async rpush (key, val) {
return this.client.rpushAsync(key, val);
}
async llen(key) {
async llen (key) {
return this.client.llenAsync(key);
}
async rpushWithEx(key, val, t) {
async rpushWithEx (key, val, t) {
var p = this.rpush(key, val);
this.client.expire(key, t);
return p;
}
async rpop(key) {
async rpop (key) {
return this.client.rpopAsync(key);
}
async lpop(key) {
async lpop (key) {
return this.client.lpopAsync(key);
}
async lrem(key, val) {
async lrem (key, val) {
return this.client.lremAsync(key, 1, val);
}
async ltrim(key, s, e) {
async ltrim (key, s, e) {
return this.client.ltrimAsync(key, s, e);
}
async clearlist(key) {
async clearlist (key) {
await this.client.ltrim(key, -1, -1);
await this.client.ltrim(key, 1, -1);
return 0;
}
async flushall() {
async flushall () {
console.log("sss");
return this.client.flushallAsync();
}
async keys(p) {
async keys (p) {
return this.client.keysAsync(p);
}
async set(key, val) {
async set (key, val) {
if (typeof val == "undefined" || typeof key == "undefined") {
console.log("......................cache val undefined");
console.log(key);
......@@ -168,53 +168,53 @@ class RedisClient {
}
return this.client.setAsync(key, val);
}
async setWithEx(key, val, t) {
async setWithEx (key, val, t) {
var p = this.client.setAsync(key, val);
this.client.expire(key, t);
return p;
}
async get(key) {
async get (key) {
return this.client.getAsync(key);
}
async delete(key) {
async delete (key) {
return this.client.delAsync(key);
}
async hmset(key, jsonObj) {
async hmset (key, jsonObj) {
return this.client.hmsetAsync(key, jsonObj);
}
async hmsetWithEx(key, jsonObj, t) {
async hmsetWithEx (key, jsonObj, t) {
var p = this.client.hmsetAsync(key, jsonObj);
this.client.expire(key, t);
return p;
}
async hgetall(key) {
async hgetall (key) {
return this.client.hgetallAsync(key);
}
async hincrby(key, f, n) {
async hincrby (key, f, n) {
return this.client.hincrbyAsync(key, f, n);
}
async sadd(key, vals) {
async sadd (key, vals) {
await this.client.saddAsync(key, ...vals);
return this.scard(key);
}
async scard(key) {
async scard (key) {
return this.client.scardAsync(key);
}
async srem(key, val) {
async srem (key, val) {
return this.client.sremAsync(key, val);
}
async sismember(key, val) {
async sismember (key, val) {
return this.client.sismemberAsync(key, val);
}
async smembers(key) {
async smembers (key) {
return this.client.smembersAsync(key);
}
async exists(key) {
async exists (key) {
return this.client.existsAsync(key);
}
async incr(key) {
async incr (key) {
return this.client.incrAsync(key);
}
}
......
......@@ -5,6 +5,40 @@ const redisAdapter = require('socket.io-redis');
const uuidv4 = require('uuid/v4');
// const notifyCtl = system.getObject("web.socketNotifyCtl");
// const msgHistoryService = system.getObject("service.msghistorySve");
class RoomSet {
constructor(server, client) {
this.roomset = [];//房间集
this.memberset = [];//人员集
this.init();
}
init () {
var self = this
redisClient.smembers("roomset").then(rs => {
//初始化房间集
self.roomset = rs
});
redisClient.smembers("memberset").then(rs => {
//初始化人员集
self.memberset = rs
});
}
/**
* 按照房间名查看人员
*/
async clientsByRoom (roomname) {
let rlst = await redisClient.get(roomname)
return rlst
}
/**
* 查看所有当前在线人数
*/
async allmembers () {
return this.memberset
}
async allrooms () {
return this.roomset
}
}
class MsgHandler {
constructor(server, client) {
this.server = server;
......@@ -68,6 +102,10 @@ class SocketServer {
// console.log(req.headers)
return "custom:id:" + this.getUUID(); // custom id must be unique
}
this.users = {}//缓存所有客户端处理器
this.uinfos = {}//缓存用户信息
this.socketidMap = {}
this.rooms = {}
this.init()
}
getUUID () {
......@@ -76,19 +114,46 @@ class SocketServer {
return u;
}
init () {
var self = this.server;
var self = this;
this.server.on('connection', function (client) {
console.log("connection.....socket");
client.on("login", (d) => {
console.log(d)
let uname = d.userName
let nickName = d.nickName ? d.nickName : uname
let headUrl = d.headUrl ? d.headUrl : 'https://gsb-zc.oss-cn-beijing.aliyuncs.com/zc_picUrl344116000745887092020814.jpg'
let id = d.id
let encuk = {
companyid: d.company.id,
userid: id,
userName: uname,
nickName: nickName,
headUrl: headUrl
}
// let str = system.encriptByDes(JSON.stringify(encuk))
//console.log('encstr', str)
let uk = uname + "_" + id + "_" + d.company.id
let ukencstr = system.encriptByDes(JSON.stringify(uk))
//保存所有的客户端的消息处理器
self.users[ukencstr] = new MsgHandler(self, client)
self.uinfos[ukencstr] = encuk
self.socketidMap[client.id] = ukencstr
//订阅uk私人频道房间
var ss = redisClient.subscribe(ukencstr, self);
//缓存房间到set,缓存所有房间
//缓存房间中的所有人
})
//
self.of('/').adapter.clients((err, clients) => {
console.log(clients); // an array containing all connected socket ids
});
// //
// self.of('/').adapter.clients((err, clients) => {
// console.log(clients); // an array containing all connected socket ids
// });
//链接断开事件
client.on('disconnect', async function (r) {
console.log("connection.........................................dismiss.............", client.id, r);
let ukencstr = self.socketidMap[client.id]
delete self.users[ukencstr]
delete self.uinfos[ukencstr]
delete self.socketidMap[client.id]
});
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment