These are chat archives for deployd/deployd

23rd
May 2017
Rares Golea
@rgolea
May 23 2017 05:33
@kkrishnan90 you need to use a dpd-event and require the user collection as following:
var uc = require('deployd/lib/resources/user-collection.js’);
var hash = uc.prototype.getUserAndPasswordHash(body.previousPassword);

dpd.users.getResource().store.getCollection().then(function(col){
    col.update({username: body.username, password: hash}, {….}, callback);
    //or
    col.find({username: body.username, password: hash}, {….}, callback);
})
It really depends on how you want to manage it
@thbl The server is on ctx.server so maybe you can print out the server itself and see there how you can get into the socketQueue from there?
thbl
@thbl
May 23 2017 07:16
@rgolea fount it here :smile:
`var  socketQueue = server.sessions.socketQueue;
socketQueue.on('socket', function (socket, session){
    console.log(socket)
    console.log(session)
})    `
thbl
@thbl
May 23 2017 11:03
@rgolea on #409 did you find out how to use the Session.emitToUsers ?
i can't figure out how to include the collection element on server side
Rares Golea
@rgolea
May 23 2017 11:04
this actually has various answers
  1. Emitting to a single user
var getUserChannel = function(uid) {
  return 'dpd_uid:' + uid;
};
server.sockets.to(getUserChannel(data.userId)).emit(‘event', data);
2Emitting to a channel
server.sockets.to(‘channelName').emit(“event", data);
in order to make users subscribe to a channel
you have to do
session.joinRoom(‘channel’);
inside your event
thbl
@thbl
May 23 2017 11:08
so if i wanna do somthing like 'session.emitToUsers(dpd.users, {'server': session.data.uid}, 'serverOff', 'err');'
Rares Golea
@rgolea
May 23 2017 11:09
no, you have to do a manual search on the users
and send to those users
what?
why aren’t you setting the emit from the event itself?
thbl
@thbl
May 23 2017 11:10
so in that case i should do query the users and then 1. Emitting to a single user for each user
Rares Golea
@rgolea
May 23 2017 11:11
hold on
why can’t you emit from the event script?
are you doing it inside a cron?
dpd-jobs module?
if you’re not, you should just do emit(me.id, ‘event’, data)
than try to do a workaround
thbl
@thbl
May 23 2017 11:20

im doing it on the run script ATM,
`
var socketQueue = server.sessions.socketQueue;
socketQueue.on('socket', function (socket, session){

//    session.emitToUsers(dpd.users, {'server': session.data.uid}, 'serverOff', 'err');

    if( session.data.path == '/servers')
        serversDB.update({id:session.data.uid},{socket:true, udp:true, sql:true}, function (err, res){
        console.log(res)
    })

          socket.on('disconnect', function () {
if( session.data.path == '/servers')
        serversDB.update({id:session.data.uid},{socket:false, udp:false, sql:false}, function (err, res){
        console.log(res)

    })

});

}) `

Rares Golea
@rgolea
May 23 2017 11:21
you have a servers path?
in order to control your other machines?
thbl
@thbl
May 23 2017 11:22
ye
like user collection
Rares Golea
@rgolea
May 23 2017 11:22
you might not want to do that… (software controlling itself is quite unreliable)
try docker and connecting to the docker api
anyways… try it out and see
:)
thbl
@thbl
May 23 2017 11:23
ye but my problem is the
session.emitToUsers(dpd.users, {'server': session.data.uid}, 'serverOff', 'err');
i dont know how to get dpd.users on server side / moudle xD