Monday, 20 July 2020

Call socket event from router page in Node

Call socket event from router page in Node

Question: How to send socket notification from Node API/Router?
  1. In App file (like index.js OR app.js)
    //Express setup
    var express = require('express');
    var app = express();
    
    //socketsetup setup
    var io = require('socket.io')(https);    
    app.set('io', io); //IMP this will let available io in router file
    
  2. In Router or Controller file
    exports.sendnotify = function(req, res) {
        var io = req.app.get('io');
        io.sockets["in"]('room_446').emit('session_end_notify', {vid:100,event_type:'live'});   //Send the Notification
        res.send('node is working fine');
    };
    
    


Question: How decrypt a text which is encoded with base64?
let buff = Buffer.from('ENCRYPTED_TXT', 'base64');
print buff.toString('ascii');