generator-angular-fullstack icon indicating copy to clipboard operation
generator-angular-fullstack copied to clipboard

Sockets emit into a function Controller

Open ghost opened this issue 10 years ago • 3 comments

Hello I am trying to do socket.emit("notification", "Here is de json for notificacion"); some like that from a custom method like:

exports.uploadFile = function(req, res) {
  var uploaded = {};
  req.file('file').upload({
      adapter: require('skipper-gridfs'),
      uri: 'mongodb://localhost:27017/storage-dev.files'
    }, function (err, uploadedFiles) {
       if (err) 
        return res.send(500, err);
        socket.emit("notification", "Here is de json for notificacion"); ////// HERE IS THE SOCKET
      return res.status(200).send(uploadedFiles);
    });
};

My problem is how to import socket.io that has been created on app.js Thanks. Greetings

ghost avatar Jan 13 '16 12:01 ghost

I would use an EventEmitter.... or use the hook on the model after save/update

khwerhahn avatar Jan 13 '16 21:01 khwerhahn

The app is available on the request object, so simply change socket.emit(.......) to req.app.socket.emit(.......)

macliems avatar Feb 17 '16 07:02 macliems

req.app.socket is failing. Can you please help @victorhugoviiii

samsfisher avatar Jun 03 '17 03:06 samsfisher