|
@@ -29,24 +29,22 @@ class LiveroomService extends CrudService {
|
|
|
|
|
|
async personcount(data) {
|
|
|
const { number, name, userid, type } = data;
|
|
|
- console.error('personcount');
|
|
|
// 取出已经进入直播的用户列表
|
|
|
- let list = await this.app.redis.get(`liveroom${number}`);
|
|
|
- console.error(_.cloneDeep(list));
|
|
|
+ let list = await this.app.redis.get(`liveroom${number}`) || JSON.stringify([{ name: '刘睿峰', userid: '5f3cbc4666f12fbf94799e05', number: '98389' }]);
|
|
|
if (list) {
|
|
|
- // 已经开始直播,并且有人观看
|
|
|
+ // // 已经开始直播,并且有人观看
|
|
|
list = JSON.parse(list);
|
|
|
- if (!type) {
|
|
|
- list = _.uniqBy(list.push({ name, userid }), 'userid');
|
|
|
- } else {
|
|
|
- list = list.filter(f => f.userid !== userid);
|
|
|
- }
|
|
|
- list = JSON.stringify(list);
|
|
|
} else {
|
|
|
// 还没有人进直播
|
|
|
- list = JSON.stringify([{ name, userid }]);
|
|
|
+ list = [{ name, userid }];
|
|
|
}
|
|
|
- await this.app.redis.set(`liveroom${number}`, list);
|
|
|
+ if (!type) {
|
|
|
+ list.push({ name, userid, number });
|
|
|
+ list = _.uniqBy(list, 'userid');
|
|
|
+ } else {
|
|
|
+ list = list.filter(f => f.userid !== userid);
|
|
|
+ }
|
|
|
+ await this.app.redis.set(`liveroom${number}`, JSON.parse(list));
|
|
|
const { mq } = this.ctx;
|
|
|
if (mq) {
|
|
|
const exchange = 'liveroom-personcount';
|