Thursday, 1 June 2017

how to reenabled events on Javascript object?

I am creating a javascript object on express server API call

var express = require('express');
var app = express();
var expressWs = require('express-ws')(app);
var os = require('os');
var pty = require('node-pty');    
app.ws('/terminals', function (req, res) {
        var terminals = {};    
        var term = pty.spawn(process.platform === 'win32' ? 'cmd.exe' : 'bash', [], {
                          name: 'xterm-color',
                          cols: cols || 80,
                          rows: rows || 24,
                          cwd: process.env.PWD,
                          env: process.env
                        });
And attaching event as below 
        term.on('data', function(data) {
            try {
              ws.send(data);
            } catch (ex) {
              // The WebSocket is not open, ignore
            }
          });
    }

Then I am saving the entire object to use in some other function 

        terminals[term.pid] = term;

Now when on next API call i want to user same object. I am checking do I have an object already create and getting it.

I am getting term object back from terminals object but this time ON events listeners are no longer working.

How to enabled event on objects back?



via Pradeep Jaiswar

No comments:

Post a Comment