Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weisjohn/sleepyhollow-phantom
PhantomJS binder for two-way communication with Node.js
https://github.com/weisjohn/sleepyhollow-phantom
Last synced: about 1 month ago
JSON representation
PhantomJS binder for two-way communication with Node.js
- Host: GitHub
- URL: https://github.com/weisjohn/sleepyhollow-phantom
- Owner: weisjohn
- License: mit
- Created: 2014-05-22T14:59:38.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-18T07:36:17.000Z (almost 10 years ago)
- Last Synced: 2024-10-12T19:51:16.754Z (2 months ago)
- Language: JavaScript
- Size: 196 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
sleepyhollow-phantom
====================PhantomJS binder for two-way communication with Node.js. An IPC library in two modules, used in conjunction with [sleepyhollow-node](https://github.com/weisjohn/sleepyhollow-node), via `stdin` and `stderr`. No `socket.io` or server-page hacks required.
### usage
To receive messages from Node.js, require and invoke `sleepyhollow`. This returns an `EventEmitter` instance which allows you to implement your own message passing system.
```
// this is PhantomJS code, not Node.js code!var sleepyhollow = require('../index.js');
var mrhyde = sleepyhollow();mrhyde.on('render', function(url) {
var page = require('webpage').create();
page.open(url, function(status) {
page.render(url.replace(/[\/:]/g, "") + ".png");
mrhyde.emit("rendered");
page.close();
});
});mrhyde.on('end', function() {
phantom.exit();
});```
[See the usage example for the corresponding Node.js code](https://github.com/weisjohn/sleepyhollow-node#usage).
#### emit(event, [param])
Arguments:
1. event - String: name of the event
2. param - Mixed: optional, any `JSON.stringify()`-able value is supportedReturns: null
Example:
```javascript
myhyde.emit("payload", { prop : page.size });
```#### on(event, listener)
Arguments:
1. event - String: name of the event
2. listener - Function(Mixed): receives a optional `JSON.stringify()`-able valueExample:
```javascript
myhyde.on('render', function(obj) {
page.render("tmp");
})
```