Skip to content

Commit

Permalink
fix: broadcast params reduced to socket, message, data
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Sep 28, 2022
1 parent 14157aa commit 9192a90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
20 changes: 10 additions & 10 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ const CoCreateUser = {
this.initSocket();
this.initChangeOrg();
this.checkSession();
this.createUserSocket();
// this.createUserSocket();
},

createUserSocket: function() {
var user_id = window.localStorage.getItem('user_id');
if (user_id) {
crud.socket.create({
namespace: 'users',
room: user_id
})
}
},
// createUserSocket: function() {
// var user_id = window.localStorage.getItem('user_id');
// if (user_id) {
// crud.socket.create({
// namespace: 'users',
// room: user_id
// })
// }
// },

initSocket: function() {
const self = this;
Expand Down
25 changes: 6 additions & 19 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,34 +121,21 @@ class CoCreateUser {
*/
async userStatus(socket, data) {
const self = this;
const {info, status} = data;

const items = info.split('/');

if (items[1] !== 'users') {
return;
}

if (!items[2]) return;

try {
const {organization_id, db} = data
const selectedDB = db || organization_id;
const collection = self.dbClient.db(selectedDB).collection('users');
const user_id = items[2];
// const user_id = items[2];
const query = {
"_id": new ObjectId(user_id),
"_id": new ObjectId(data.user_id),
}
collection.updateOne(query, {$set: {status: status}}, function(err, res) {
collection.updateOne(query, {$set: {status: data.status}}, function(err, res) {
if (!err) {
self.wsManager.broadcast(socket, '', null, 'updateUserStatus',
{
user_id,
status
})
}
else
self.wsManager.broadcast(socket, 'updateUserStatus', data)
} else {
console.log('err', err)
}
})
} catch (error) {
console.log('userStatus error')
Expand Down

0 comments on commit 9192a90

Please sign in to comment.