How to use the node-ipc.connectTo function in node-ipc

To help you get started, we’ve selected a few node-ipc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inkandswitch / pushpin / src / apps / clipper-host / index.ts View on Github external
return new Promise((res, rej) => {
    // Note: we give pushpin a couple seconds to handle the message
    const timer = setTimeout(() => {
      ipc.disconnect('renderer')
      res({ type: 'Failed', details: 'Timed out.' })
    }, 2500)
    ipc.connectTo('renderer', WEBCLIPPER_SOCKET_LOCATION, () => {
      ipc.of.renderer.on('connect', () => {
        ipc.of.renderer.emit('clipper', msg)

        ipc.of.renderer.on('renderer', (msg) => {
          res(msg)
          ipc.disconnect('renderer')
          clearTimeout(timer)
        })
      })
    })
  })
}
github Mayank1791989 / gql / src / cli / rpc / Client.js View on Github external
return new Promise((resolve, reject) => {
      const serverName = ipc.config.id;

      ipc.connectTo(serverName, () => {
        const server = ipc.of[serverName];

        // connected and emit method
        server.on('connect', () => {
          ipc.log(`connected to "${serverName}"`);
          // call method on server
          server.emit(method, input);
        });

        // listen for method response
        server.on(method, ({ error, response }) => {
          // receive server respons
          ipc.disconnect(serverName); // disconnect client to server
          ipc.log(`${serverName}@${method}:response`, error, response);
          resolve(response); // return response
        });
github embark-framework / embark / src / lib / core / ipc.js View on Github external
done();
        }
      });
      ipc.of['embark'].on('disconnect',function() {
        self.connected = false;
        ipc.disconnect('embark');

        // we only want to trigger the error callback the first time
        if (!connectedBefore && !alreadyDisconnected) {
          alreadyDisconnected = true;
          done(new Error("no connection found"));
        }
      });
    }

    ipc.connectTo('embark', this.socketPath, connecting);
  }
github TheBrainFamily / cypress-app-watcher-preprocessor / appWatcher.js View on Github external
appProc.stdout.on("data", data => {
    let stringifiedData = data.toString();
    process.stdout.write(stringifiedData);
    if (stringifiedData.match(new RegExp(process.env.WAIT_FOR_MESSAGE, "i"))) {
      console.log("Restarting cypress tests!");
      const cypressWatcherId = "cypress-rerun-with-app";
      ipc.connectTo(cypressWatcherId, function() {
        ipc.of[cypressWatcherId].emit("message", "RESTART");
      });
    }
  });
github facebookarchive / atom-ide-ui / modules / jest-atom-runner / src / ipc-client.js View on Github external
return new Promise(resolve => {
    const onMessageCallbacks = [];
    ipc.connectTo(serverID, () => {
      ipc.of[serverID].on('connect', () => {
        const initMessage = makeMessage({
          messageType: MESSAGE_TYPES.INITIALIZE,
        });
        ipc.of[serverID].emit(workerID, initMessage);
      });

      ipc.of[serverID].on(workerID, data => {
        onMessageCallbacks.forEach(cb => cb(data));
      });

      resolve({
        send: message => ipc.of[serverID].emit(workerID, message),
        onMessage: fn => {
          onMessageCallbacks.push(fn);
        },
github SolidStateGroup / rio / rio-server / outputs / pi-output.js View on Github external
pyshell.on('message', (message) => {
    console.log('Python output:', message);
})

var channel = null;
ipc.config.id = 'ipc';
ipc.config.socketRoot = '/tmp/';
ipc.config.appspace = 'app.';
ipc.config.silent = true;
ipc.config.rawBuffer = true;
ipc.config.retry= 1500;

var callback = null;

//TODO: this should be put into an init function
ipc.connectTo(
    'main',
    function(){
        ipc.of.main.on(
            'connect',
            function(){
                ipc.log('## connected to main ##', ipc.config.delay);
                channel = ipc.of.main;
            }
        );
        ipc.of.main.on(
            'data',
            function(data) {
                callback && callback();
            }
        )
    }
github BoostIO / Boostnote / browser / main / lib / ipcClient.js View on Github external
import ConfigManager from './ConfigManager'

const nodeIpc = require('node-ipc')
const { remote, ipcRenderer } = require('electron')
const { app } = remote
const path = require('path')

nodeIpc.config.id = 'main'
nodeIpc.config.retry = 1500
nodeIpc.config.silent = true

nodeIpc.connectTo(
  'node',
  path.join(app.getPath('userData'), 'boostnote.service'),
  function () {
    nodeIpc.of.node.on('error', function (err) {
      console.error(err)
    })
    nodeIpc.of.node.on('connect', function () {
      ipcRenderer.send('config-renew', {config: ConfigManager.get()})
    })
    nodeIpc.of.node.on('disconnect', function () {
      return
    })
  }
)

module.exports = nodeIpc
github jlongster / electron-with-server-example / find-open-socket.js View on Github external
return new Promise((resolve, reject) => {
    ipc.connectTo(name, () => {
      ipc.of[name].on('error', () => {
        ipc.disconnect(name);
        resolve(false);
      });

      ipc.of[name].on('connect', () => {
        ipc.disconnect(name);
        resolve(true);
      });
    });
  });
}
github fyodorvi / jspm-watch / lib / jspm-worker-orchestrator.js View on Github external
if (this._child) {

            this._child.kill();

        }

        this._child = exec(`node "${path.join(__dirname, 'jspm-worker.js')}" ${this._workerId}`);

        this._child.stderr.on('data', error => {

            //immediate death
            throw new Error(error);

        });

        ipc.connectTo(this._workerId, () => {

            ipc.of[this._workerId].on('connect', () => {

                defer.resolve();

            });

            ipc.of[this._workerId].on('result', this._resultHandler.bind(this));

        });

        return defer.promise;

    }

node-ipc

A nodejs module for local and remote Inter Process Communication (IPC), Neural Networking, and able to facilitate machine learning.

MIT
Latest version published 4 months ago

Package Health Score

67 / 100
Full package analysis