initial commit
This commit is contained in:
470
node_modules/ipc/README.md
generated
vendored
Normal file
470
node_modules/ipc/README.md
generated
vendored
Normal file
@@ -0,0 +1,470 @@
|
||||
#node-ipc
|
||||
*a nodejs module for local and remote Inter Process Communication* for Linux, Mac and Windows.
|
||||
A great solution for **Neural Networking** in Node.JS
|
||||
|
||||
**npm install node-ipc**
|
||||
[](https://npmjs.org/package/node-ipc "node-ipc details from npm")
|
||||
|
||||
Package details websites :
|
||||
* [GitHub.io site](http://riaevangelist.github.io/node-ipc/ "node-ipc documentation"). A prettier version of this site.
|
||||
* [NPM Module](https://www.npmjs.org/package/node-ipc "node-ipc npm module"). The npm page for the node-ipc module.
|
||||
|
||||
This work is licenced via the [DBAD Public Licence](http://www.dbad-license.org/).
|
||||
|
||||
----
|
||||
#### Contents
|
||||
|
||||
1. [Types of IPC Sockets and Supporting OS](#types-of-ipc-sockets)
|
||||
2. [IPC Methods](#ipc-methods)
|
||||
1. [log](#log)
|
||||
2. [connectTo](#connectto)
|
||||
3. [connectToNet](#connecttonet)
|
||||
4. [disconnect](#disconnect)
|
||||
5. [serve](#serve)
|
||||
6. [serveNet](#servenet)
|
||||
3. [IPC Stores and Default Variables](#ipc-stores-and-default-variables)
|
||||
4. [Basic Examples](#basic-examples)
|
||||
1. [Server for Unix Sockets & TCP Sockets](#server-for-unix-sockets--tcp-sockets)
|
||||
2. [Client for Unix Sockets & TCP Sockets](#client-for-unix-sockets--tcp-sockets)
|
||||
3. [Server & Client for UDP Sockets](#server--client-for-udp-sockets)
|
||||
5. [Advanced Examples](https://github.com/RIAEvangelist/node-ipc/tree/master/example)
|
||||
|
||||
|
||||
----
|
||||
#### Types of IPC Sockets
|
||||
|
||||
| Type | Stability |Definition |
|
||||
|-----------|-----------|-----------|
|
||||
|Unix Socket| Stable | Gives Linux and Mac lightning fast communication and avoids the network card to reduce overhead and latency. [Local Unix Socket examples ](https://github.com/RIAEvangelist/node-ipc/tree/master/example/unixSocket/ "Unix Socket Node IPC examples") |
|
||||
|TCP Socket | Stable | Gives the most reliable communication across the network. Can be used for local IPC as well, but is slower than #1's Unix Socket Implementation because TCP sockets go through the network card while Unix Sockets do not. [Local or remote network TCP Socket examples ](https://github.com/RIAEvangelist/node-ipc/tree/master/example/TCPSocket/ "TCP Socket Node IPC examples") |
|
||||
|TLS Socket | Alpha | ***coming soon...*** |
|
||||
|UDP Sockets| Stable | Gives the **fastest network communication**. UDP is less reliable but much faster than TCP. It is best used for streaming non critical data like sound, video, or multiplayer game data as it can drop packets depending on network connectivity and other factors. UDP can be used for local IPC as well, but is slower than #1's Unix Socket Implementation because UDP sockets go through the network card while Unix Sockets do not. [Local or remote network UDP Socket examples ](https://github.com/RIAEvangelist/node-ipc/tree/master/example/UDPSocket/ "UDP Socket Node IPC examples") |
|
||||
|
||||
| OS | Supported Sockets |
|
||||
|-----|--------------------|
|
||||
|Linux| Unix, TCP, TLS, UDP|
|
||||
|Mac | Unix, TCP, TLS, UDP|
|
||||
|Win | TCP, TLS, UDP |
|
||||
|
||||
**Windows** users may want to use UDP servers for the fastest local IPC. Unix Servers are the fastest oprion on Linux and Mac, but not available for windows.
|
||||
|
||||
----
|
||||
|
||||
``ipc.config``
|
||||
|
||||
Set these variables in the ``ipc.config`` scope to overwrite or set default values.
|
||||
|
||||
{
|
||||
appspace : 'app.',
|
||||
socketRoot : '/tmp/',
|
||||
id : os.hostname(),
|
||||
networkHost : 'localhost',
|
||||
networkPort : 8000,
|
||||
encoding : 'utf8',
|
||||
silent : false,
|
||||
maxConnections : 100,
|
||||
retry : 500,
|
||||
stopRetrying : false
|
||||
}
|
||||
|
||||
|
||||
| variable | documentation |
|
||||
|----------|---------------|
|
||||
| appspace | used for Unix Socket (Unix Domain Socket) namespacing. If not set specifically, the Unix Domain Socket will combine the socketRoot, appspace, and id to form the Unix Socket Path for creation or binding. This is available incase you have many apps running on your system, you may have several sockets with the same id, but if you change the appspace, you will still have app specic unique sockets.|
|
||||
| socketRoot| the directory in which to create or bind to a Unix Socket |
|
||||
| id | the id of this socket or service |
|
||||
| networkHost| the local or remote host on which TCP, TLS or UDP Sockets should connect |
|
||||
| networkPort| the default port on which TCP, TLS, or UDP sockets should connect |
|
||||
| encoding | the default encoding for data sent on sockets |
|
||||
| silent | turn on/off logging default is false which means logging is on |
|
||||
| maxConnections| this is the max number of connections allowed to a socket. It is currently only being set on Unix Sockets. Other Socket types are using the system defaults. |
|
||||
| retry | this is the time in milliseconds a client will wait before trying to reconnect to a server if the connection is lost. This does not effect UDP sockets since they do not have a client server relationship like Unix Sockets and TCP Sockets. |
|
||||
| stopRetrying| Defaults to false mwaning clients will continue to retryt to connect to servers indefinately at the retry interval. If set to any number the client will stop retrying when that number is exceeded after each disconnect. If set to 0, the client will ***NOT*** try to reconnect. |
|
||||
|
||||
----
|
||||
|
||||
#### IPC Methods
|
||||
These methods are available in the IPC Scope.
|
||||
|
||||
----
|
||||
##### log
|
||||
|
||||
``ipc.log(a,b,c,d,e...);``
|
||||
|
||||
ipc.log will accept any number of arguments and if ``ipc.config.silent`` is not set, it will concat them all with a sincle space ' ' between them and then log them to the console. This is fast because it prevents any concation from happening if the ipc is set to silent. That way if you leave your logging in place it should not effect performance.
|
||||
|
||||
the log also supports [colors](https://github.com/Marak/colors.js) implementation. All of the available styles are supported and the theme styles are as follows :
|
||||
|
||||
{
|
||||
good : 'green',
|
||||
notice : 'yellow',
|
||||
warn : 'red',
|
||||
error : 'redBG',
|
||||
debug : 'magenta',
|
||||
variable: 'cyan',
|
||||
data : 'blue'
|
||||
}
|
||||
|
||||
You can override any of these settings by requireing colors and setting the theme as follows :
|
||||
|
||||
var colors=require('colors');
|
||||
|
||||
colors.setTheme(
|
||||
{
|
||||
good : 'zebra',
|
||||
notice : 'redBG',
|
||||
...
|
||||
}
|
||||
);
|
||||
----
|
||||
##### connectTo
|
||||
|
||||
``ipc.connectTo(id,path,callback);``
|
||||
|
||||
Used for connecting as a client to local Unix Sockets. ***This is the fastst way for processes on the same machine to communicate*** because it bypasses the network card which TCP and UDP must both use.
|
||||
|
||||
| variable | required | definition |
|
||||
|----------|----------|------------|
|
||||
| id | required | is the string id of the socket being connected to. The socket with this id is added to the ipc.of object when created. |
|
||||
| path | optional | is the path of the Unix Domain Socket File, if not set this will be defaylted to ``ipc.config.socketRoot``+``ipc.config.appspace``+``id`` |
|
||||
| callback | optional | this is the function to execute when the socket has been created. |
|
||||
|
||||
**examples** arguments can be ommitted solong as they are still in order.
|
||||
|
||||
ipc.connectTo('world');
|
||||
|
||||
or using just an id and a callback
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'hello',
|
||||
function(data){
|
||||
ipc.log(data.debug);
|
||||
//if data was a string, it would have the color set to the debug style applied to it
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
or explicitly setting the path
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
'myapp.world'
|
||||
);
|
||||
|
||||
or explicitly setting the path with callback
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
'myapp.world',
|
||||
function(){
|
||||
...
|
||||
}
|
||||
);
|
||||
----
|
||||
##### connectToNet
|
||||
|
||||
``ipc.connectToNet(id,host,port,callback)``
|
||||
|
||||
Used to connect as a client to a TCP or TLS socket via the network card. This can be local or remote, if local, it is recommended that you use the Unix Socket Implementaion of ``connectTo`` instead as it is much faster since it avoids the network card alltogether.
|
||||
|
||||
| variable | required | definition |
|
||||
|----------|----------|------------|
|
||||
| id | required | is the string id of the socket being connected to. For TCP & TLS sockets, this id is added to the ``ipc.of`` object when the socket is created with a refrence to the socket. |
|
||||
| host | optional | is the host on which the TCP or TLS socket resides. This will default to ``ipc.config.networkHost`` if not specified. |
|
||||
| port | optional | the port on which the TCP or TLS socket resides. |
|
||||
| callback | optional | this is the function to execute when the socket has been created. |
|
||||
|
||||
**examples** arguments can be ommitted solong as they are still in order.
|
||||
So while the default is : (id,host,port,callback), the following examples will still work because they are still in order (id,port,callback) or (id,host,callback) or (id,port) etc.
|
||||
|
||||
ipc.connectToNet('world');
|
||||
|
||||
or using just an id and a callback
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
...
|
||||
}
|
||||
);
|
||||
|
||||
or explicitly setting the host and path
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
'myapp.com',serve(path,callback)
|
||||
3435
|
||||
);
|
||||
|
||||
or only explicitly setting port and callback
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
3435,
|
||||
function(){
|
||||
...
|
||||
}
|
||||
);
|
||||
|
||||
----
|
||||
##### disconnect
|
||||
|
||||
``ipc.disconnect(id)``
|
||||
|
||||
Used to disconnect a client from a Unix, TCP or TLS socket. The socket and its refrence will be removed from memory and the ``ipc.of`` scope. This can be local or remote. UDP clients do not maintain connections and so there are no Clients and this method has no value to them.
|
||||
|
||||
| variable | required | definition |
|
||||
|----------|----------|------------|
|
||||
| id | required | is the string id of the socket from which to disconnect. |
|
||||
|
||||
**examples**
|
||||
|
||||
ipc.disconnect('world');
|
||||
|
||||
----
|
||||
##### serve
|
||||
``ipc.serve(path,callback);``
|
||||
|
||||
Used to create local Unix Socket Server to which Clients can bind. The server can ``emit`` events to specific Client Sockets, or ``broadcast`` events to all known Client Sockets.
|
||||
|
||||
| variable | required | definition |
|
||||
|----------|----------|------------|
|
||||
| path | optional | This is the Unix Domain Socket path to bind to. If not supplied, it will default to : ipc.config.socketRoot + ipc.config.appspace + ipc.config.id; |
|
||||
| callback | optional | This is a function to be called after the Server has started. This can also be done by binding an event to the start event like ``ipc.server.on('start',function(){});`` |
|
||||
|
||||
***examples*** arguments can be ommitted solong as they are still in order.
|
||||
|
||||
ipc.serve();
|
||||
|
||||
or specifying callback
|
||||
|
||||
ipc.serve(
|
||||
function(){...}
|
||||
);
|
||||
|
||||
or specify path
|
||||
|
||||
ipc.serve(
|
||||
'/tmp/myapp.myservice'
|
||||
);
|
||||
|
||||
or specifying everything
|
||||
|
||||
ipc.serve(
|
||||
'/tmp/myapp.myservice',
|
||||
function(){...}
|
||||
);
|
||||
|
||||
----
|
||||
##### serveNet
|
||||
|
||||
``serveNet(host,port,UDPType,callback)``
|
||||
|
||||
Used to create TCP, TLS or UDP Socket Server to which Clients can bind or other servers can send data to. The server can ``emit`` events to specific Client Sockets, or ``broadcast`` events to all known Client Sockets.
|
||||
|
||||
|
||||
| variable | required | definition |
|
||||
|----------|----------|------------|
|
||||
| host | optional | If not specified this defaults to localhost. For TCP, TLS & UDP servers this is most likely going to be localhost or 0.0.0.0 unless you have something like [node-http-server](https://github.com/RIAEvangelist/node-http-server) installed to run subdomains for you. |
|
||||
| port | optional | The port on which the TCP, UDP, or TLS Socket server will be bound, this defaults to 8000 if not specified |
|
||||
| UDPType | optional | If set this will create the server as a UDP socket. 'udp4' or 'udp6' are valid values. This defaults to not being set.
|
||||
| callback | optional | Function to be called when the server is created |
|
||||
|
||||
***examples*** arguments can be ommitted solong as they are still in order.
|
||||
|
||||
default tcp server
|
||||
|
||||
ipc.serveNet();
|
||||
|
||||
default udp server
|
||||
|
||||
ipc.serveNet('udp4');
|
||||
|
||||
or specifying TCP server with callback
|
||||
|
||||
ipc.serveNet(
|
||||
function(){...}
|
||||
);
|
||||
|
||||
or specifying UDP server with callback
|
||||
|
||||
ipc.serveNet(
|
||||
'udp4',
|
||||
function(){...}
|
||||
);
|
||||
|
||||
or specify port
|
||||
|
||||
ipc.serveNet(
|
||||
3435
|
||||
);
|
||||
|
||||
or specifying everything TCP
|
||||
|
||||
ipc.serveNet(
|
||||
'MyMostAwesomeApp.com',
|
||||
3435,
|
||||
function(){...}
|
||||
);
|
||||
|
||||
or specifying everything UDP
|
||||
|
||||
ipc.serveNet(
|
||||
'MyMostAwesomeApp.com',
|
||||
3435,
|
||||
'udp4',
|
||||
function(){...}
|
||||
);
|
||||
|
||||
----
|
||||
### IPC Stores and Default Variables
|
||||
|
||||
| variable | definition |
|
||||
|-----------|------------|
|
||||
| ipc.of | This is where socket connection refrences will be stored when connecting to them as a client via the ``ipc.connectTo`` or ``iupc.connectToNet``. They will be stored based on the ID used to create them, eg : ipc.of.mySocket|
|
||||
| ipc.server| This is a refrence to the server created by ``ipc.serve`` or ``ipc.serveNet``|
|
||||
|
||||
----
|
||||
### Basic Examples
|
||||
You can find [Advanced Examples](https://github.com/RIAEvangelist/node-ipc/tree/master/example) in the examples folder. In the examples you will find more complex demos including multi client examples.
|
||||
|
||||
#### Server for Unix Sockets & TCP Sockets
|
||||
The server is the process keeping a socket for IPC open. Multiple sockets can connect to this server and talk to it. It can also broadcast to all clients or emit to a specific client. This is the most basic example which will work for both local Unix Sockets and local or remote network TCP Sockets.
|
||||
|
||||
var ipc=require('node-ipc');
|
||||
|
||||
ipc.config.id = 'world';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.serve(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : '.debug, data);
|
||||
ipc.server.emit(
|
||||
'message',
|
||||
data+' world!'
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.start();
|
||||
|
||||
#### Client for Unix Sockets & TCP Sockets
|
||||
The client connects to the servers socket for Inter Process Communication. The socket will recieve events emitted to it specifically as well as events which are broadcast out on the socket by the server. This is the most basic example which will work for both local Unix Sockets and local or remote network TCP Sockets.
|
||||
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
)
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
#### Server & Client for UDP Sockets
|
||||
UDP Sockets are different than Unix & TCP Sockets because they must be bound to a unique port on their machine to recieve messages. For example, A TCP or Unix Socket client could just connect to a seperate TCP or Unix Socket sever. That client could then exchange, both send and recive, data on the servers port or location. UDP Sockets can not do this. They must bind to a port to recieve or send data.
|
||||
|
||||
This means a UDP Client and Server are the same thing because inorder to recieve data, a UDP Socket must have its own port to recieve data on, and only one process can use this port at a time. It also means that inorder to ``emit`` or ``broadcast`` data the UDP server will need to know the host and port of the Socket it intends to broadcast the data to.
|
||||
|
||||
This is the most basic example which will work for both local Unix Sockets and local or remote network TCP Sockets.
|
||||
|
||||
##### UDP Server 1 - "World"
|
||||
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
ipc.config.id = 'world';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.serveNet(
|
||||
'udp4',
|
||||
function(){
|
||||
console.log(123);
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from '.debug, data.from.variable ,' : '.debug, data.message.variable);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
{
|
||||
from : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
console.log(ipc.server);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen.message='This event type listens for message strings as value of data key.';
|
||||
|
||||
ipc.server.start();
|
||||
|
||||
##### UDP Server 2 - "Hello"
|
||||
*note* we set the port here to 8001 because the world server is already using the default ipc.config.networkPort of 8000. So we can not bind to 8000 while world is using it.
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.serveNet(
|
||||
8001,
|
||||
'udp4',
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got Data');
|
||||
ipc.log('got a message from '.debug, data.from.variable ,' : '.debug, data.message.variable);
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
{
|
||||
address : 'localhost',
|
||||
port : ipc.config.networkPort
|
||||
},
|
||||
'message',
|
||||
{
|
||||
from : ipc.config.id,
|
||||
message : 'Hello'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen.message='This event type listens for message strings as value of data key.';
|
||||
|
||||
ipc.server.start();
|
||||
43
node_modules/ipc/example/TCPSocket/Multi-Client-Broadcast/goodbye-client.js
generated
vendored
Normal file
43
node_modules/ipc/example/TCPSocket/Multi-Client-Broadcast/goodbye-client.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'goodbye';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'goodbye'
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection'.notice);
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
49
node_modules/ipc/example/TCPSocket/Multi-Client-Broadcast/hello-client.js
generated
vendored
Normal file
49
node_modules/ipc/example/TCPSocket/Multi-Client-Broadcast/hello-client.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'hello'
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data.messgae);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection'.notice);
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
51
node_modules/ipc/example/TCPSocket/Multi-Client-Broadcast/world-server.js
generated
vendored
Normal file
51
node_modules/ipc/example/TCPSocket/Multi-Client-Broadcast/world-server.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'world';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
var messages={
|
||||
goodbye:false,
|
||||
hello:false
|
||||
}
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from'.debug, (data.id).variable, (data.message).data);
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling clients to kill connection'.good);
|
||||
ipc.server.broadcast(
|
||||
'kill.connection',
|
||||
{
|
||||
id:ipc.config.id
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen['app.message']='This event type listens for message strings as value of data key.';
|
||||
ipc.server.define.broadcast['kill.connection']='This event is a command to kill connection to this server, the data object will contain the id of this server incase the client needs it';
|
||||
|
||||
ipc.server.start();
|
||||
41
node_modules/ipc/example/TCPSocket/basic/hello-client.js
generated
vendored
Normal file
41
node_modules/ipc/example/TCPSocket/basic/hello-client.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
)
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
console.log(ipc)
|
||||
31
node_modules/ipc/example/TCPSocket/basic/world-server.js
generated
vendored
Normal file
31
node_modules/ipc/example/TCPSocket/basic/world-server.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'world';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : '.debug, data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
data+' world!'
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen.message='This event type listens for message strings as value of data key.';
|
||||
|
||||
ipc.server.start();
|
||||
48
node_modules/ipc/example/UDPSocket/Multi-Client-Broadcast/goodbye-client.js
generated
vendored
Normal file
48
node_modules/ipc/example/UDPSocket/Multi-Client-Broadcast/goodbye-client.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* Since there is no client relationship
|
||||
* with UDP sockets sockets are not kept
|
||||
* open.
|
||||
*
|
||||
* This means the order sockets are opened
|
||||
* is important.
|
||||
*
|
||||
* Start World first. Then you can start
|
||||
* hello or goodbye in any order you
|
||||
* choose.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'goodbye';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.serveNet(
|
||||
8002, //we set the port here because the hello client and world server are already using the default of 8000 and the port 8001. So we can not bind to those while hello and world are connected to them.
|
||||
'udp4',
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got Data');
|
||||
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
{
|
||||
address : 'localhost',
|
||||
port : ipc.config.networkPort
|
||||
},
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'Goodbye'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen.message='This event type listens for message strings as value of data key.';
|
||||
|
||||
ipc.server.start();
|
||||
48
node_modules/ipc/example/UDPSocket/Multi-Client-Broadcast/hello-client.js
generated
vendored
Normal file
48
node_modules/ipc/example/UDPSocket/Multi-Client-Broadcast/hello-client.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* Since there is no client relationship
|
||||
* with UDP sockets sockets are not kept
|
||||
* open.
|
||||
*
|
||||
* This means the order sockets are opened
|
||||
* is important.
|
||||
*
|
||||
* Start World first. Then you can start
|
||||
* hello or goodbye in any order you
|
||||
* choose.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.serveNet(
|
||||
8001, //we set the port here because the world server is already using the default of 8000. So we can not bind to 8000 while world is using it.
|
||||
'udp4',
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got Data');
|
||||
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
{
|
||||
address : 'localhost',
|
||||
port : ipc.config.networkPort
|
||||
},
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'Hello'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen.message='This event type listens for message strings as value of data key.';
|
||||
|
||||
ipc.server.start();
|
||||
63
node_modules/ipc/example/UDPSocket/Multi-Client-Broadcast/world-server.js
generated
vendored
Normal file
63
node_modules/ipc/example/UDPSocket/Multi-Client-Broadcast/world-server.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* Since there is no client relationship
|
||||
* with UDP sockets sockets are not kept
|
||||
* open.
|
||||
*
|
||||
* This means the order sockets are opened
|
||||
* is important.
|
||||
*
|
||||
* Start World first. Then you can start
|
||||
* hello or goodbye in any order you
|
||||
* choose.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'world';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
var messages={
|
||||
goodbye:false,
|
||||
hello:false
|
||||
}
|
||||
|
||||
ipc.serveNet(
|
||||
'udp4',
|
||||
function(){
|
||||
console.log(123);
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling evryone how muchg I am loved!'.good);
|
||||
ipc.server.broadcast(
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'Everybody Loves The World! Got messages from hello and goodbye!'
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
console.log(ipc.server);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen.message='This event type listens for message strings as value of data key.';
|
||||
|
||||
ipc.server.start();
|
||||
52
node_modules/ipc/example/UDPSocket/basic/hello-client.js
generated
vendored
Normal file
52
node_modules/ipc/example/UDPSocket/basic/hello-client.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* UDP Client is really a UDP server
|
||||
*
|
||||
* Dedicated UDP sockets on the same
|
||||
* machine can not be bound to in the
|
||||
* traditional client/server method
|
||||
*
|
||||
* Every UDP socket is it's own UDP server
|
||||
* And so must have a unique port on its
|
||||
* machine, unlike TCP or Unix Sockts
|
||||
* which can share on the same machine.
|
||||
*
|
||||
* Since there is no open client server
|
||||
* relationship, you should start world
|
||||
* first and then hello.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.serveNet(
|
||||
8001, //we set the port here because the world server is already using the default of 8000. So we can not bind to 8000 while world is using it.
|
||||
'udp4',
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got Data');
|
||||
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
{
|
||||
address : 'localhost',
|
||||
port : ipc.config.networkPort
|
||||
},
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'Hello'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen.message='This event type listens for message strings as value of data key.';
|
||||
|
||||
ipc.server.start();
|
||||
49
node_modules/ipc/example/UDPSocket/basic/world-server.js
generated
vendored
Normal file
49
node_modules/ipc/example/UDPSocket/basic/world-server.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* UDP Client is really a UDP server
|
||||
*
|
||||
* Dedicated UDP sockets on the same
|
||||
* machine can not be bound to in the
|
||||
* traditional client/server method
|
||||
*
|
||||
* Every UDP socket is it's own UDP server
|
||||
* And so must have a unique port on its
|
||||
* machine, unlike TCP or Unix Sockts
|
||||
* which can share on the same machine.
|
||||
*
|
||||
* Since there is no open client server
|
||||
* relationship, you should start world
|
||||
* first and then hello.
|
||||
*
|
||||
* *************************************//
|
||||
|
||||
ipc.config.id = 'world';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.serveNet(
|
||||
'udp4',
|
||||
function(){
|
||||
console.log(123);
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen.message='This event type listens for message strings as value of data key.';
|
||||
|
||||
ipc.server.start();
|
||||
43
node_modules/ipc/example/unixSocket/Multi-Client-Broadcast/goodbye-client.js
generated
vendored
Normal file
43
node_modules/ipc/example/unixSocket/Multi-Client-Broadcast/goodbye-client.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'goodbye';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'goodbye'
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection'.notice);
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
49
node_modules/ipc/example/unixSocket/Multi-Client-Broadcast/hello-client.js
generated
vendored
Normal file
49
node_modules/ipc/example/unixSocket/Multi-Client-Broadcast/hello-client.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'hello'
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection'.notice);
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
51
node_modules/ipc/example/unixSocket/Multi-Client-Broadcast/world-server.js
generated
vendored
Normal file
51
node_modules/ipc/example/unixSocket/Multi-Client-Broadcast/world-server.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'world';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
var messages={
|
||||
goodbye:false,
|
||||
hello:false
|
||||
}
|
||||
|
||||
ipc.serve(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from'.debug, (data.id).variable, (data.message).data);
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling clients to kill connection'.good);
|
||||
ipc.server.broadcast(
|
||||
'kill.connection',
|
||||
{
|
||||
id:ipc.config.id
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen['app.message']='This event type listens for message strings as value of data key.';
|
||||
ipc.server.define.broadcast['kill.connection']='This event is a command to kill connection to this server, the data object will contain the id of this server incase the client needs it';
|
||||
|
||||
ipc.server.start();
|
||||
42
node_modules/ipc/example/unixSocket/basic/hello-client.js
generated
vendored
Normal file
42
node_modules/ipc/example/unixSocket/basic/hello-client.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'hello'
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
34
node_modules/ipc/example/unixSocket/basic/world-server.js
generated
vendored
Normal file
34
node_modules/ipc/example/unixSocket/basic/world-server.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
var ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'world';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.serve(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
//ipc.log('got a message from'.debug, (data.id).variable, (data.message).data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen['app.message']='This event type listens for message strings as value of data key.';
|
||||
|
||||
ipc.server.start();
|
||||
146
node_modules/ipc/lib/client.js
generated
vendored
Normal file
146
node_modules/ipc/lib/client.js
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
var net = require('net'),
|
||||
eventParser = require('../lib/eventParser.js'),
|
||||
pubsub = require('event-pubsub');
|
||||
|
||||
function init(config,log){
|
||||
var client={
|
||||
config : config,
|
||||
socket : false,
|
||||
connect : connect,
|
||||
emit : emit,
|
||||
log : log,
|
||||
retryCount:0
|
||||
}
|
||||
new pubsub(client);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
function emit(type,data){
|
||||
this.log('dispatching event to '.debug, this.id.variable, this.path.variable,' : ', type.data,',', data);
|
||||
if(!data)
|
||||
data=false;
|
||||
this.socket.write(
|
||||
eventParser.format(
|
||||
{
|
||||
type:type,
|
||||
data:data
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
function connect(){
|
||||
//init client object for scope persistance especially inside of socket events.
|
||||
var client=this;
|
||||
|
||||
client.log('requested connection to '.debug, client.id.variable, client.path.variable);
|
||||
if(!this.path){
|
||||
client.log('\n\n######\nerror: '.error, client.id .info,' client has not specified socket path it wishes to connect to.'.error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!client.port){
|
||||
client.log('Connecting client on Unix Socket :'.debug, client.path.variable);
|
||||
client.socket = net.connect(
|
||||
{
|
||||
path:client.path
|
||||
}
|
||||
);
|
||||
}else{
|
||||
client.log('Connecting client via TCP to'.debug, client.path.variable ,client.port);
|
||||
client.socket = net.connect(
|
||||
{
|
||||
port:client.port,
|
||||
host:client.path
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
client.socket.setEncoding(this.config.encoding);
|
||||
|
||||
client.socket.on(
|
||||
'error',
|
||||
function(err){
|
||||
client.log('\n\n######\nerror: '.error, err);
|
||||
}
|
||||
);
|
||||
|
||||
client.socket.on(
|
||||
'connect',
|
||||
function(){
|
||||
client.trigger('connect');
|
||||
}
|
||||
);
|
||||
|
||||
client.socket.on(
|
||||
'close',
|
||||
function(){
|
||||
client.log('connection closed'.notice ,client.id.variable , client.path.variable);
|
||||
|
||||
if(client.config.stopRetrying || client.config.stopRetrying===0){
|
||||
if(client.retryCount++>client.config.stopRetrying){
|
||||
client.log(client.config.id.variable,'exceeded connection rety amount of'.warn,client.config.stopRetrying);
|
||||
client.socket.destroy();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
client.isRetrying=true;
|
||||
|
||||
setTimeout(
|
||||
(
|
||||
function(client){
|
||||
return function(){
|
||||
client.isRetrying=false;
|
||||
client.connect();
|
||||
setTimeout(
|
||||
function(){
|
||||
if(!client.isRetrying)
|
||||
client.retryCount=0;
|
||||
},
|
||||
100
|
||||
)
|
||||
}
|
||||
}
|
||||
)(client),
|
||||
client.config.retry
|
||||
);
|
||||
|
||||
client.trigger('disconnect');
|
||||
}
|
||||
);
|
||||
|
||||
client.socket.on(
|
||||
'data',
|
||||
function(data) {
|
||||
client.log('## recieved events ##'.rainbow);
|
||||
if(!this.ipcBuffer)
|
||||
this.ipcBuffer='';
|
||||
|
||||
data=(this.ipcBuffer+=data);
|
||||
|
||||
if(data.slice(-1)!=eventParser.delimiter){
|
||||
client.log('Socket buffer size exceeded consider smaller messages or a larger buffer.'.warn, 'Implementing software buffer expansion for this message.'.notice);
|
||||
return;
|
||||
}
|
||||
|
||||
this.ipcBuffer='';
|
||||
|
||||
var events = eventParser.parse(data);
|
||||
var eCount = events.length;
|
||||
for(var i=0; i<eCount; i++){
|
||||
var e=JSON.parse(
|
||||
events[i]
|
||||
);
|
||||
client.log('detected event of type '.debug, e.type.data, e.data);
|
||||
client.trigger(
|
||||
e.type,
|
||||
e.data
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
module.exports=init;
|
||||
23
node_modules/ipc/lib/eventParser.js
generated
vendored
Normal file
23
node_modules/ipc/lib/eventParser.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
function formatData(data){
|
||||
if(!data.data)
|
||||
data.data={};
|
||||
if(data.data['_maxListeners'])
|
||||
delete data.data;
|
||||
|
||||
data=JSON.stringify(data)+parser.delimiter;
|
||||
return data;
|
||||
};
|
||||
|
||||
function parseDataEvents(data){
|
||||
var events=data.split(parser.delimiter);
|
||||
events.pop();
|
||||
return events;
|
||||
}
|
||||
|
||||
var parser={
|
||||
parse : parseDataEvents,
|
||||
format : formatData,
|
||||
delimiter : '\f'
|
||||
}
|
||||
|
||||
module.exports=parser;
|
||||
332
node_modules/ipc/lib/socketServer.js
generated
vendored
Normal file
332
node_modules/ipc/lib/socketServer.js
generated
vendored
Normal file
@@ -0,0 +1,332 @@
|
||||
var net = require('net'),
|
||||
fs = require('fs'),
|
||||
dgram = require('dgram'),
|
||||
eventParser = require('../lib/eventParser.js'),
|
||||
pubsub = require('event-pubsub');
|
||||
|
||||
function emit(socket, type, data){
|
||||
if(!data)
|
||||
data=false;
|
||||
this.log('dispatching event to socket'.debug, ' : ', type.data, data);
|
||||
|
||||
var event={
|
||||
type:type,
|
||||
data:data
|
||||
}
|
||||
|
||||
if(this.udp4 || this.udp6){
|
||||
|
||||
if(!socket.address || !socket.port){
|
||||
this.log('Attempting to emit to a single UDP socket without supplying socket address or port. Redispatching event as broadcast to all connected sockets');
|
||||
this.broadcast(type,data);
|
||||
return;
|
||||
}
|
||||
|
||||
this.server.write(
|
||||
eventParser.format(
|
||||
event
|
||||
),
|
||||
socket
|
||||
)
|
||||
return;
|
||||
};
|
||||
|
||||
socket.write(
|
||||
eventParser.format(
|
||||
event
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
function broadcast(type,data){
|
||||
this.log('broadcasting event to all known sockets listening to '.debug, this.path.variable,' : ', ((this.port)?this.port:''), type, data);
|
||||
if(!data)
|
||||
data=false;
|
||||
|
||||
var e=eventParser.format(
|
||||
{
|
||||
type:type,
|
||||
data:data
|
||||
}
|
||||
);
|
||||
|
||||
if(this.udp4 || this.udp6){
|
||||
for(var i=0, count=this.sockets.length; i<count; i++){
|
||||
this.server.write(e,this.sockets[i]);
|
||||
}
|
||||
}else{
|
||||
for(var i=0, count=this.sockets.length; i<count; i++){
|
||||
this.sockets[i].write(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function init(path,config,log,port){
|
||||
var server={
|
||||
config : config,
|
||||
path : path,
|
||||
port : port,
|
||||
udp4 : false,
|
||||
udp6 : false,
|
||||
log : log,
|
||||
server : false,
|
||||
sockets : [],
|
||||
emit : emit,
|
||||
broadcast : broadcast,
|
||||
define : {
|
||||
listen : {
|
||||
'get.events.broadcasting' : 'does not require any special paramaters',
|
||||
'get.events.listening' : 'does not require any special paramaters'
|
||||
},
|
||||
broadcast : {
|
||||
'events.broadcasting' : 'data.events is a JSON object of event definitions by type '+config.id+' will broadcast on '+path,
|
||||
'events.listening' : 'data.events is a JSON object of event definitions by type '+config.id+' is listening for on '+path
|
||||
}
|
||||
},
|
||||
onStart : function(socket){
|
||||
this.trigger(
|
||||
'start',
|
||||
socket
|
||||
);
|
||||
},
|
||||
start : function(){
|
||||
if(!this.path){
|
||||
server.log('Socket Server Path not specified, refusing to start'.warn);
|
||||
return;
|
||||
}
|
||||
|
||||
fs.unlink(
|
||||
this.path,
|
||||
(
|
||||
function(server){
|
||||
return function () {
|
||||
server.log('starting server on '.debug,server.path.variable,((server.port)?':'+server.port:'').variable);
|
||||
|
||||
if(!server.udp4 && !server.udp6){
|
||||
server.server=net.createServer(
|
||||
serverCreated
|
||||
);
|
||||
}else{
|
||||
function UDPWrite(message,socket){
|
||||
var data=new Buffer(message, server.config.encoding);
|
||||
server.server.send(
|
||||
data,
|
||||
0,
|
||||
data.length,
|
||||
socket.port,
|
||||
socket.address,
|
||||
function(err, bytes) {
|
||||
if(err){
|
||||
server.trigger(
|
||||
'error',
|
||||
function(err){
|
||||
server.trigger('error',err);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
server.server=dgram.createSocket(
|
||||
((server.udp4)? 'udp4':'udp6')
|
||||
);
|
||||
server.server.write=UDPWrite;
|
||||
server.server.on(
|
||||
'listening',
|
||||
function () {
|
||||
serverCreated(server.server)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function serverCreated(socket) {
|
||||
server.sockets.push(socket);
|
||||
|
||||
if(socket.setEncoding)
|
||||
socket.setEncoding(server.config.encoding);
|
||||
|
||||
server.log('## socket connection to server detected ##'.rainbow);
|
||||
socket.on(
|
||||
'close',
|
||||
function(socket){
|
||||
server.trigger(
|
||||
'close',
|
||||
socket
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
socket.on(
|
||||
'error',
|
||||
function(err){
|
||||
server.trigger('error',err);
|
||||
}
|
||||
);
|
||||
|
||||
socket.on(
|
||||
'data',
|
||||
function(data,UDPSocket){
|
||||
if(!this.ipcBuffer)
|
||||
this.ipcBuffer='';
|
||||
|
||||
data=(this.ipcBuffer+=data);
|
||||
|
||||
if(data.slice(-1)!=eventParser.delimiter){
|
||||
server.log('Socket buffer size exceeded, consider smaller messages or a larger buffer.'.warn, 'Implementing software buffer expansion for this message.'.notice);
|
||||
return;
|
||||
}
|
||||
|
||||
this.ipcBuffer='';
|
||||
|
||||
data=eventParser.parse(data);
|
||||
var sock=((server.udp4 || server.udp6)? UDPSocket : socket);
|
||||
|
||||
while(data.length>0){
|
||||
var e=JSON.parse(data.shift());
|
||||
server.log('received event of : '.debug,e.type.data,e.data);
|
||||
|
||||
server.trigger(
|
||||
e.type,
|
||||
e.data,
|
||||
sock
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
socket.on(
|
||||
'message',
|
||||
function(msg,rinfo) {
|
||||
if (!rinfo)
|
||||
return;
|
||||
server.log('Received UDP message from '.debug, rinfo.address.variable, rinfo.port);
|
||||
socket.emit('data',msg.toString(),rinfo);
|
||||
}
|
||||
);
|
||||
|
||||
server.trigger(
|
||||
'connect',
|
||||
socket
|
||||
);
|
||||
|
||||
server.trigger(
|
||||
'get.events.broadcasting',
|
||||
socket
|
||||
);
|
||||
|
||||
server.trigger(
|
||||
'get.events.listening',
|
||||
socket
|
||||
);
|
||||
}
|
||||
|
||||
function started(socket){
|
||||
server.onStart(socket)
|
||||
}
|
||||
|
||||
if(!port){
|
||||
server.log('starting server as'.debug, 'Unix Socket'.variable);
|
||||
server.server.listen(
|
||||
server.path,
|
||||
started
|
||||
);
|
||||
|
||||
server.server.maxConnections=server.maxConnections;
|
||||
return;
|
||||
}
|
||||
|
||||
if(!server.udp4 && !server.udp4){
|
||||
server.log('starting server as'.debug, 'TCP'.variable);
|
||||
server.server.listen(
|
||||
server.port,
|
||||
server.path,
|
||||
started
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
server.log('starting server as'.debug,((server.udp4)? 'udp4':'udp6').variable);
|
||||
server.server.bind(
|
||||
server.port,
|
||||
server.path
|
||||
);
|
||||
|
||||
started(
|
||||
{
|
||||
address : server.path,
|
||||
port : server.port
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
)(this)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
new pubsub(server);
|
||||
|
||||
server.on(
|
||||
'get.events.broadcasting',
|
||||
function(socket){
|
||||
server.emit(
|
||||
socket,
|
||||
'events.broadcasting',
|
||||
{
|
||||
id : server.config.id,
|
||||
events : server.define.broadcast
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
server.on(
|
||||
'get.events.listening',
|
||||
function(socket){
|
||||
server.emit(
|
||||
socket,
|
||||
'events.listening',
|
||||
{
|
||||
id : server.config.id,
|
||||
events : server.define.listen,
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
|
||||
server.on(
|
||||
'close',
|
||||
function(){
|
||||
for(var i=0, count=server.sockets.length; i<count; i++){
|
||||
var socket=server.sockets[i];
|
||||
|
||||
if(socket){
|
||||
if(socket.readable)
|
||||
continue;
|
||||
}
|
||||
|
||||
server.log(socket.id, 'socket disconnected'.notice);
|
||||
var deadSocket=socket.id;
|
||||
|
||||
if(socket)
|
||||
socket.destroy();
|
||||
|
||||
server.sockets.splice(i,1);
|
||||
|
||||
server.trigger(
|
||||
'socket.disconnected',
|
||||
{
|
||||
id:deadSocket
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
module.exports=init;
|
||||
27
node_modules/ipc/licence.md
generated
vendored
Normal file
27
node_modules/ipc/licence.md
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# DON'T BE A DICK PUBLIC LICENSE
|
||||
|
||||
> Version 1, December 2009
|
||||
|
||||
> Copyright (C) 2009 Philip Sturgeon <email@philsturgeon.co.uk>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
> DON'T BE A DICK PUBLIC LICENSE
|
||||
> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
1. Do whatever you like with the original work, just don't be a dick.
|
||||
|
||||
Being a dick includes - but is not limited to - the following instances:
|
||||
|
||||
1a. Outright copyright infringement - Don't just copy this and change the name.
|
||||
1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
|
||||
1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.
|
||||
|
||||
2. If you become rich through modifications, related works/services, or supporting the original work,
|
||||
share the love. Only a dick would make loads off this work and not buy the original work's
|
||||
creator(s) a pint.
|
||||
|
||||
3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
|
||||
you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.
|
||||
295
node_modules/ipc/node-ipc.js
generated
vendored
Normal file
295
node_modules/ipc/node-ipc.js
generated
vendored
Normal file
@@ -0,0 +1,295 @@
|
||||
var os = require('os'),
|
||||
util = require('util'),
|
||||
colors = require('colors'),
|
||||
pubsub = require('event-pubsub'),
|
||||
eventParser = require('./lib/eventParser.js'),
|
||||
Client = require('./lib/client.js'),
|
||||
Server = require('./lib/socketServer.js');
|
||||
|
||||
colors.setTheme(
|
||||
{
|
||||
good : 'green',
|
||||
notice : 'yellow',
|
||||
warn : 'red',
|
||||
error : 'redBG',
|
||||
debug : 'magenta',
|
||||
variable: 'cyan',
|
||||
data : 'blue'
|
||||
}
|
||||
);
|
||||
|
||||
var defaults={
|
||||
appspace : 'app.',
|
||||
socketRoot : '/tmp/',
|
||||
networkHost : 'localhost',
|
||||
networkPort : 8000,
|
||||
id : os.hostname(),
|
||||
encoding : 'utf8',
|
||||
silent : false,
|
||||
maxConnections : 100,
|
||||
retry : 500,
|
||||
stopRetrying : false,
|
||||
}
|
||||
|
||||
var ipc = {
|
||||
config : defaults,
|
||||
connectTo : connect,
|
||||
connectToNet: connectNet,
|
||||
disconnect : disconnect,
|
||||
serve : serve,
|
||||
serveNet : serveNet,
|
||||
of : {},
|
||||
server : false,
|
||||
log : log
|
||||
}
|
||||
|
||||
function log(){
|
||||
if(ipc.config.silent)
|
||||
return;
|
||||
|
||||
var args=Array.prototype.slice.call(arguments);
|
||||
|
||||
for(var i=0, count=args.length; i<count; i++){
|
||||
if(typeof args[i] != 'object')
|
||||
continue;
|
||||
|
||||
args[i]=util.inspect(args[i],{colors:true});
|
||||
}
|
||||
|
||||
console.log(
|
||||
args.join(' ')
|
||||
);
|
||||
}
|
||||
|
||||
function disconnect(id){
|
||||
if(!ipc.of[id])
|
||||
return;
|
||||
|
||||
ipc.of[id].off('*');
|
||||
if(ipc.of[id].socket){
|
||||
if(ipc.of[id].socket.destroy)
|
||||
ipc.of[id].socket.destroy();
|
||||
}
|
||||
|
||||
delete ipc.of[id];
|
||||
}
|
||||
|
||||
function serve(path,callback){
|
||||
if(typeof path=='function'){
|
||||
callback=path;
|
||||
path=false;
|
||||
}
|
||||
if(!path){
|
||||
ipc.log(
|
||||
'Server path not specified, so defaulting to'.notice,
|
||||
'ipc.config.socketRoot + ipc.config.appspace + ipc.config.id'.variable,
|
||||
(ipc.config.socketRoot+ipc.config.appspace+ipc.config.id).data
|
||||
);
|
||||
path=ipc.config.socketRoot+ipc.config.appspace+ipc.config.id;
|
||||
}
|
||||
|
||||
if(!callback)
|
||||
callback=function(){};
|
||||
|
||||
ipc.server=new Server(
|
||||
path,
|
||||
ipc.config,
|
||||
log
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'start',
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
function serveNet(host,port,UDPType,callback){
|
||||
if(typeof host=='number'){
|
||||
callback=UDPType;
|
||||
UDPType=port;
|
||||
port=host;
|
||||
host=false;
|
||||
}
|
||||
if(typeof host=='function'){
|
||||
callback=host;
|
||||
UDPType=false;
|
||||
host=false;
|
||||
port=false;
|
||||
}
|
||||
if(!host){
|
||||
ipc.log(
|
||||
'Server host not specified, so defaulting to'.notice,
|
||||
'ipc.config.networkHost'.variable,
|
||||
ipc.config.networkHost.data
|
||||
);
|
||||
host=ipc.config.networkHost;
|
||||
}
|
||||
if(host.toLowerCase()=='udp4' || host.toLowerCase()=='udp6'){
|
||||
callback=port;
|
||||
UDPType=host.toLowerCase();
|
||||
port=false;
|
||||
host=ipc.config.networkHost;
|
||||
}
|
||||
|
||||
if(typeof port=='string'){
|
||||
callback=UDPType;
|
||||
UDPType=port;
|
||||
port=false;
|
||||
}
|
||||
if(typeof port=='function'){
|
||||
callback=port;
|
||||
UDPType=false;
|
||||
port=false;
|
||||
}
|
||||
if(!port){
|
||||
ipc.log(
|
||||
'Server port not specified, so defaulting to'.notice,
|
||||
'ipc.config.networkPort'.variable,
|
||||
ipc.config.networkPort
|
||||
);
|
||||
port=ipc.config.networkPort;
|
||||
}
|
||||
|
||||
if(typeof UDPType=='function'){
|
||||
callback=UDPType;
|
||||
UDPType=false;
|
||||
}
|
||||
|
||||
if(!callback)
|
||||
callback=function(){};
|
||||
|
||||
ipc.server=new Server(
|
||||
host,
|
||||
ipc.config,
|
||||
log,
|
||||
port
|
||||
);
|
||||
|
||||
if(UDPType)
|
||||
ipc.server[UDPType]=true;
|
||||
|
||||
ipc.server.on(
|
||||
'start',
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
function connect(id,path,callback){
|
||||
if(typeof path == 'function'){
|
||||
callback=path;
|
||||
path=false;
|
||||
}
|
||||
|
||||
if(!callback)
|
||||
callback=function(){};
|
||||
|
||||
if(!id){
|
||||
ipc.log(
|
||||
'Service id required'.warn,
|
||||
'Requested service connection without specifying service id. Aborting connection attempt'.notice
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!path){
|
||||
ipc.log(
|
||||
'Service path not specified, so defaulting to'.notice,
|
||||
'ipc.config.socketRoot + ipc.config.appspace + id'.variable,
|
||||
(ipc.config.socketRoot+ipc.config.appspace+id).data
|
||||
);
|
||||
path=ipc.config.socketRoot+ipc.config.appspace+id;
|
||||
}
|
||||
|
||||
if(ipc.of[id]){
|
||||
if(!ipc.of[id].socket.destroyed){
|
||||
ipc.log(
|
||||
'Already Connected to'.notice,
|
||||
id.variable,
|
||||
'- So executing success without connection'.notice
|
||||
);
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
ipc.of[id].destroy();
|
||||
}
|
||||
|
||||
ipc.of[id] = new Client(ipc.config,ipc.log);
|
||||
ipc.of[id].id = id;
|
||||
ipc.of[id].path = path;
|
||||
|
||||
ipc.of[id].connect();
|
||||
|
||||
callback(ipc);
|
||||
}
|
||||
|
||||
function connectNet(id,host,port,callback){
|
||||
if(!id){
|
||||
ipc.log(
|
||||
'Service id required'.warn,
|
||||
'Requested service connection without specifying service id. Aborting connection attempt'.notice
|
||||
);
|
||||
return;
|
||||
}
|
||||
if(typeof host=='number'){
|
||||
callback=port;
|
||||
port=host;
|
||||
host=false;
|
||||
}
|
||||
if(typeof host=='function'){
|
||||
callback=host;
|
||||
host=false;
|
||||
port=false;
|
||||
}
|
||||
if(!host){
|
||||
ipc.log(
|
||||
'Server host not specified, so defaulting to'.notice,
|
||||
'ipc.config.networkHost'.variable,
|
||||
ipc.config.networkHost.data
|
||||
);
|
||||
host=ipc.config.networkHost;
|
||||
}
|
||||
|
||||
if(typeof port=='function'){
|
||||
callback=port;
|
||||
port=false;
|
||||
}
|
||||
if(!port){
|
||||
ipc.log(
|
||||
'Server port not specified, so defaulting to'.notice,
|
||||
'ipc.config.networkPort'.variable,
|
||||
ipc.config.networkPort
|
||||
);
|
||||
port=ipc.config.networkPort;
|
||||
}
|
||||
|
||||
if(typeof callback == 'string'){
|
||||
UDPType=callback;
|
||||
callback=false;
|
||||
}
|
||||
if(!callback)
|
||||
callback=function(){};
|
||||
|
||||
if(ipc.of[id]){
|
||||
if(!ipc.of[id].socket.destroyed){
|
||||
ipc.log(
|
||||
'Already Connected to'.notice,
|
||||
id.variable,
|
||||
'- So executing success without connection'.notice
|
||||
);
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
ipc.of[id].destroy();
|
||||
}
|
||||
|
||||
ipc.of[id] = new Client(ipc.config,ipc.log);
|
||||
ipc.of[id].id = id;
|
||||
ipc.of[id].path = host;
|
||||
ipc.of[id].port = port;
|
||||
|
||||
ipc.of[id].connect();
|
||||
|
||||
callback(ipc);
|
||||
}
|
||||
|
||||
module.exports=ipc;
|
||||
22
node_modules/ipc/node_modules/colors/MIT-LICENSE.txt
generated
vendored
Normal file
22
node_modules/ipc/node_modules/colors/MIT-LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2010
|
||||
|
||||
Marak Squires
|
||||
Alexis Sellier (cloudhead)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
77
node_modules/ipc/node_modules/colors/ReadMe.md
generated
vendored
Normal file
77
node_modules/ipc/node_modules/colors/ReadMe.md
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
# colors.js - get color and style in your node.js console ( and browser ) like what
|
||||
|
||||
<img src="http://i.imgur.com/goJdO.png" border = "0"/>
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
npm install colors
|
||||
|
||||
## colors and styles!
|
||||
|
||||
- bold
|
||||
- italic
|
||||
- underline
|
||||
- inverse
|
||||
- yellow
|
||||
- cyan
|
||||
- white
|
||||
- magenta
|
||||
- green
|
||||
- red
|
||||
- grey
|
||||
- blue
|
||||
- rainbow
|
||||
- zebra
|
||||
- random
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
var colors = require('./colors');
|
||||
|
||||
console.log('hello'.green); // outputs green text
|
||||
console.log('i like cake and pies'.underline.red) // outputs red underlined text
|
||||
console.log('inverse the color'.inverse); // inverses the color
|
||||
console.log('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)
|
||||
```
|
||||
|
||||
# Creating Custom themes
|
||||
|
||||
```js
|
||||
|
||||
var colors = require('colors');
|
||||
|
||||
colors.setTheme({
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red'
|
||||
});
|
||||
|
||||
// outputs red text
|
||||
console.log("this is an error".error);
|
||||
|
||||
// outputs yellow text
|
||||
console.log("this is a warning".warn);
|
||||
```
|
||||
|
||||
|
||||
### Contributors
|
||||
|
||||
Marak (Marak Squires)
|
||||
Alexis Sellier (cloudhead)
|
||||
mmalecki (Maciej Małecki)
|
||||
nicoreed (Nico Reed)
|
||||
morganrallen (Morgan Allen)
|
||||
JustinCampbell (Justin Campbell)
|
||||
ded (Dustin Diaz)
|
||||
|
||||
|
||||
#### , Marak Squires , Justin Campbell, Dustin Diaz (@ded)
|
||||
342
node_modules/ipc/node_modules/colors/colors.js
generated
vendored
Normal file
342
node_modules/ipc/node_modules/colors/colors.js
generated
vendored
Normal file
@@ -0,0 +1,342 @@
|
||||
/*
|
||||
colors.js
|
||||
|
||||
Copyright (c) 2010
|
||||
|
||||
Marak Squires
|
||||
Alexis Sellier (cloudhead)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
var isHeadless = false;
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
isHeadless = true;
|
||||
}
|
||||
|
||||
if (!isHeadless) {
|
||||
var exports = {};
|
||||
var module = {};
|
||||
var colors = exports;
|
||||
exports.mode = "browser";
|
||||
} else {
|
||||
exports.mode = "console";
|
||||
}
|
||||
|
||||
//
|
||||
// Prototypes the string object to have additional method calls that add terminal colors
|
||||
//
|
||||
var addProperty = function (color, func) {
|
||||
exports[color] = function (str) {
|
||||
return func.apply(str);
|
||||
};
|
||||
String.prototype.__defineGetter__(color, func);
|
||||
};
|
||||
|
||||
function stylize(str, style) {
|
||||
|
||||
var styles;
|
||||
|
||||
if (exports.mode === 'console') {
|
||||
styles = {
|
||||
//styles
|
||||
'bold' : ['\x1B[1m', '\x1B[22m'],
|
||||
'italic' : ['\x1B[3m', '\x1B[23m'],
|
||||
'underline' : ['\x1B[4m', '\x1B[24m'],
|
||||
'inverse' : ['\x1B[7m', '\x1B[27m'],
|
||||
'strikethrough' : ['\x1B[9m', '\x1B[29m'],
|
||||
//text colors
|
||||
//grayscale
|
||||
'white' : ['\x1B[37m', '\x1B[39m'],
|
||||
'grey' : ['\x1B[90m', '\x1B[39m'],
|
||||
'black' : ['\x1B[30m', '\x1B[39m'],
|
||||
//colors
|
||||
'blue' : ['\x1B[34m', '\x1B[39m'],
|
||||
'cyan' : ['\x1B[36m', '\x1B[39m'],
|
||||
'green' : ['\x1B[32m', '\x1B[39m'],
|
||||
'magenta' : ['\x1B[35m', '\x1B[39m'],
|
||||
'red' : ['\x1B[31m', '\x1B[39m'],
|
||||
'yellow' : ['\x1B[33m', '\x1B[39m'],
|
||||
//background colors
|
||||
//grayscale
|
||||
'whiteBG' : ['\x1B[47m', '\x1B[49m'],
|
||||
'greyBG' : ['\x1B[49;5;8m', '\x1B[49m'],
|
||||
'blackBG' : ['\x1B[40m', '\x1B[49m'],
|
||||
//colors
|
||||
'blueBG' : ['\x1B[44m', '\x1B[49m'],
|
||||
'cyanBG' : ['\x1B[46m', '\x1B[49m'],
|
||||
'greenBG' : ['\x1B[42m', '\x1B[49m'],
|
||||
'magentaBG' : ['\x1B[45m', '\x1B[49m'],
|
||||
'redBG' : ['\x1B[41m', '\x1B[49m'],
|
||||
'yellowBG' : ['\x1B[43m', '\x1B[49m']
|
||||
};
|
||||
} else if (exports.mode === 'browser') {
|
||||
styles = {
|
||||
//styles
|
||||
'bold' : ['<b>', '</b>'],
|
||||
'italic' : ['<i>', '</i>'],
|
||||
'underline' : ['<u>', '</u>'],
|
||||
'inverse' : ['<span style="background-color:black;color:white;">', '</span>'],
|
||||
'strikethrough' : ['<del>', '</del>'],
|
||||
//text colors
|
||||
//grayscale
|
||||
'white' : ['<span style="color:white;">', '</span>'],
|
||||
'grey' : ['<span style="color:gray;">', '</span>'],
|
||||
'black' : ['<span style="color:black;">', '</span>'],
|
||||
//colors
|
||||
'blue' : ['<span style="color:blue;">', '</span>'],
|
||||
'cyan' : ['<span style="color:cyan;">', '</span>'],
|
||||
'green' : ['<span style="color:green;">', '</span>'],
|
||||
'magenta' : ['<span style="color:magenta;">', '</span>'],
|
||||
'red' : ['<span style="color:red;">', '</span>'],
|
||||
'yellow' : ['<span style="color:yellow;">', '</span>'],
|
||||
//background colors
|
||||
//grayscale
|
||||
'whiteBG' : ['<span style="background-color:white;">', '</span>'],
|
||||
'greyBG' : ['<span style="background-color:gray;">', '</span>'],
|
||||
'blackBG' : ['<span style="background-color:black;">', '</span>'],
|
||||
//colors
|
||||
'blueBG' : ['<span style="background-color:blue;">', '</span>'],
|
||||
'cyanBG' : ['<span style="background-color:cyan;">', '</span>'],
|
||||
'greenBG' : ['<span style="background-color:green;">', '</span>'],
|
||||
'magentaBG' : ['<span style="background-color:magenta;">', '</span>'],
|
||||
'redBG' : ['<span style="background-color:red;">', '</span>'],
|
||||
'yellowBG' : ['<span style="background-color:yellow;">', '</span>']
|
||||
};
|
||||
} else if (exports.mode === 'none') {
|
||||
return str + '';
|
||||
} else {
|
||||
console.log('unsupported mode, try "browser", "console" or "none"');
|
||||
}
|
||||
return styles[style][0] + str + styles[style][1];
|
||||
}
|
||||
|
||||
function applyTheme(theme) {
|
||||
|
||||
//
|
||||
// Remark: This is a list of methods that exist
|
||||
// on String that you should not overwrite.
|
||||
//
|
||||
var stringPrototypeBlacklist = [
|
||||
'__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor',
|
||||
'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt',
|
||||
'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring',
|
||||
'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight'
|
||||
];
|
||||
|
||||
Object.keys(theme).forEach(function (prop) {
|
||||
if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
|
||||
console.log('warn: '.red + ('String.prototype' + prop).magenta + ' is probably something you don\'t want to override. Ignoring style name');
|
||||
}
|
||||
else {
|
||||
if (typeof(theme[prop]) === 'string') {
|
||||
addProperty(prop, function () {
|
||||
return exports[theme[prop]](this);
|
||||
});
|
||||
}
|
||||
else {
|
||||
addProperty(prop, function () {
|
||||
var ret = this;
|
||||
for (var t = 0; t < theme[prop].length; t++) {
|
||||
ret = exports[theme[prop][t]](ret);
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Iterate through all default styles and colors
|
||||
//
|
||||
var x = ['bold', 'underline', 'strikethrough', 'italic', 'inverse', 'grey', 'black', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta', 'greyBG', 'blackBG', 'yellowBG', 'redBG', 'greenBG', 'blueBG', 'whiteBG', 'cyanBG', 'magentaBG'];
|
||||
x.forEach(function (style) {
|
||||
|
||||
// __defineGetter__ at the least works in more browsers
|
||||
// http://robertnyman.com/javascript/javascript-getters-setters.html
|
||||
// Object.defineProperty only works in Chrome
|
||||
addProperty(style, function () {
|
||||
return stylize(this, style);
|
||||
});
|
||||
});
|
||||
|
||||
function sequencer(map) {
|
||||
return function () {
|
||||
if (!isHeadless) {
|
||||
return this.replace(/( )/, '$1');
|
||||
}
|
||||
var exploded = this.split(""), i = 0;
|
||||
exploded = exploded.map(map);
|
||||
return exploded.join("");
|
||||
};
|
||||
}
|
||||
|
||||
var rainbowMap = (function () {
|
||||
var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta']; //RoY G BiV
|
||||
return function (letter, i, exploded) {
|
||||
if (letter === " ") {
|
||||
return letter;
|
||||
} else {
|
||||
return stylize(letter, rainbowColors[i++ % rainbowColors.length]);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
exports.themes = {};
|
||||
|
||||
exports.addSequencer = function (name, map) {
|
||||
addProperty(name, sequencer(map));
|
||||
};
|
||||
|
||||
exports.addSequencer('rainbow', rainbowMap);
|
||||
exports.addSequencer('zebra', function (letter, i, exploded) {
|
||||
return i % 2 === 0 ? letter : letter.inverse;
|
||||
});
|
||||
|
||||
exports.setTheme = function (theme) {
|
||||
if (typeof theme === 'string') {
|
||||
try {
|
||||
exports.themes[theme] = require(theme);
|
||||
applyTheme(exports.themes[theme]);
|
||||
return exports.themes[theme];
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
applyTheme(theme);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
addProperty('stripColors', function () {
|
||||
return ("" + this).replace(/\x1B\[\d+m/g, '');
|
||||
});
|
||||
|
||||
// please no
|
||||
function zalgo(text, options) {
|
||||
var soul = {
|
||||
"up" : [
|
||||
'̍', '̎', '̄', '̅',
|
||||
'̿', '̑', '̆', '̐',
|
||||
'͒', '͗', '͑', '̇',
|
||||
'̈', '̊', '͂', '̓',
|
||||
'̈', '͊', '͋', '͌',
|
||||
'̃', '̂', '̌', '͐',
|
||||
'̀', '́', '̋', '̏',
|
||||
'̒', '̓', '̔', '̽',
|
||||
'̉', 'ͣ', 'ͤ', 'ͥ',
|
||||
'ͦ', 'ͧ', 'ͨ', 'ͩ',
|
||||
'ͪ', 'ͫ', 'ͬ', 'ͭ',
|
||||
'ͮ', 'ͯ', '̾', '͛',
|
||||
'͆', '̚'
|
||||
],
|
||||
"down" : [
|
||||
'̖', '̗', '̘', '̙',
|
||||
'̜', '̝', '̞', '̟',
|
||||
'̠', '̤', '̥', '̦',
|
||||
'̩', '̪', '̫', '̬',
|
||||
'̭', '̮', '̯', '̰',
|
||||
'̱', '̲', '̳', '̹',
|
||||
'̺', '̻', '̼', 'ͅ',
|
||||
'͇', '͈', '͉', '͍',
|
||||
'͎', '͓', '͔', '͕',
|
||||
'͖', '͙', '͚', '̣'
|
||||
],
|
||||
"mid" : [
|
||||
'̕', '̛', '̀', '́',
|
||||
'͘', '̡', '̢', '̧',
|
||||
'̨', '̴', '̵', '̶',
|
||||
'͜', '͝', '͞',
|
||||
'͟', '͠', '͢', '̸',
|
||||
'̷', '͡', ' ҉'
|
||||
]
|
||||
},
|
||||
all = [].concat(soul.up, soul.down, soul.mid),
|
||||
zalgo = {};
|
||||
|
||||
function randomNumber(range) {
|
||||
var r = Math.floor(Math.random() * range);
|
||||
return r;
|
||||
}
|
||||
|
||||
function is_char(character) {
|
||||
var bool = false;
|
||||
all.filter(function (i) {
|
||||
bool = (i === character);
|
||||
});
|
||||
return bool;
|
||||
}
|
||||
|
||||
function heComes(text, options) {
|
||||
var result = '', counts, l;
|
||||
options = options || {};
|
||||
options["up"] = options["up"] || true;
|
||||
options["mid"] = options["mid"] || true;
|
||||
options["down"] = options["down"] || true;
|
||||
options["size"] = options["size"] || "maxi";
|
||||
text = text.split('');
|
||||
for (l in text) {
|
||||
if (is_char(l)) {
|
||||
continue;
|
||||
}
|
||||
result = result + text[l];
|
||||
counts = {"up" : 0, "down" : 0, "mid" : 0};
|
||||
switch (options.size) {
|
||||
case 'mini':
|
||||
counts.up = randomNumber(8);
|
||||
counts.min = randomNumber(2);
|
||||
counts.down = randomNumber(8);
|
||||
break;
|
||||
case 'maxi':
|
||||
counts.up = randomNumber(16) + 3;
|
||||
counts.min = randomNumber(4) + 1;
|
||||
counts.down = randomNumber(64) + 3;
|
||||
break;
|
||||
default:
|
||||
counts.up = randomNumber(8) + 1;
|
||||
counts.mid = randomNumber(6) / 2;
|
||||
counts.down = randomNumber(8) + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
var arr = ["up", "mid", "down"];
|
||||
for (var d in arr) {
|
||||
var index = arr[d];
|
||||
for (var i = 0 ; i <= counts[index]; i++) {
|
||||
if (options[index]) {
|
||||
result = result + soul[index][randomNumber(soul[index].length)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return heComes(text);
|
||||
}
|
||||
|
||||
|
||||
// don't summon zalgo
|
||||
addProperty('zalgo', function () {
|
||||
return zalgo(this);
|
||||
});
|
||||
76
node_modules/ipc/node_modules/colors/example.html
generated
vendored
Normal file
76
node_modules/ipc/node_modules/colors/example.html
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<title>Colors Example</title>
|
||||
<script src="colors.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
var test = colors.red("hopefully colorless output");
|
||||
|
||||
document.write('Rainbows are fun!'.rainbow + '<br/>');
|
||||
document.write('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
|
||||
document.write('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
|
||||
//document.write('zalgo time!'.zalgo);
|
||||
document.write(test.stripColors);
|
||||
document.write("a".grey + " b".black);
|
||||
|
||||
document.write("Zebras are so fun!".zebra);
|
||||
|
||||
document.write(colors.rainbow('Rainbows are fun!'));
|
||||
document.write("This is " + "not".strikethrough + " fun.");
|
||||
|
||||
document.write(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
|
||||
document.write(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
|
||||
//document.write(colors.zalgo('zalgo time!'));
|
||||
document.write(colors.stripColors(test));
|
||||
document.write(colors.grey("a") + colors.black(" b"));
|
||||
|
||||
colors.addSequencer("america", function(letter, i, exploded) {
|
||||
if(letter === " ") return letter;
|
||||
switch(i%3) {
|
||||
case 0: return letter.red;
|
||||
case 1: return letter.white;
|
||||
case 2: return letter.blue;
|
||||
}
|
||||
});
|
||||
|
||||
colors.addSequencer("random", (function() {
|
||||
var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
|
||||
|
||||
return function(letter, i, exploded) {
|
||||
return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]];
|
||||
};
|
||||
})());
|
||||
|
||||
document.write("AMERICA! F--K YEAH!".america);
|
||||
document.write("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random);
|
||||
|
||||
//
|
||||
// Custom themes
|
||||
//
|
||||
|
||||
colors.setTheme({
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red'
|
||||
});
|
||||
|
||||
// outputs red text
|
||||
document.write("this is an error".error);
|
||||
|
||||
// outputs yellow text
|
||||
document.write("this is a warning".warn);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
77
node_modules/ipc/node_modules/colors/example.js
generated
vendored
Normal file
77
node_modules/ipc/node_modules/colors/example.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
var colors = require('./colors');
|
||||
|
||||
//colors.mode = "browser";
|
||||
|
||||
var test = colors.red("hopefully colorless output");
|
||||
console.log('Rainbows are fun!'.rainbow);
|
||||
console.log('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
|
||||
console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
|
||||
//console.log('zalgo time!'.zalgo);
|
||||
console.log(test.stripColors);
|
||||
console.log("a".grey + " b".black);
|
||||
console.log("Zebras are so fun!".zebra);
|
||||
console.log('background color attack!'.black.whiteBG)
|
||||
|
||||
//
|
||||
// Remark: .strikethrough may not work with Mac OS Terminal App
|
||||
//
|
||||
console.log("This is " + "not".strikethrough + " fun.");
|
||||
console.log(colors.rainbow('Rainbows are fun!'));
|
||||
console.log(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
|
||||
console.log(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
|
||||
//console.log(colors.zalgo('zalgo time!'));
|
||||
console.log(colors.stripColors(test));
|
||||
console.log(colors.grey("a") + colors.black(" b"));
|
||||
|
||||
colors.addSequencer("america", function(letter, i, exploded) {
|
||||
if(letter === " ") return letter;
|
||||
switch(i%3) {
|
||||
case 0: return letter.red;
|
||||
case 1: return letter.white;
|
||||
case 2: return letter.blue;
|
||||
}
|
||||
});
|
||||
|
||||
colors.addSequencer("random", (function() {
|
||||
var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
|
||||
|
||||
return function(letter, i, exploded) {
|
||||
return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]];
|
||||
};
|
||||
})());
|
||||
|
||||
console.log("AMERICA! F--K YEAH!".america);
|
||||
console.log("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random);
|
||||
|
||||
//
|
||||
// Custom themes
|
||||
//
|
||||
|
||||
// Load theme with JSON literal
|
||||
colors.setTheme({
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red'
|
||||
});
|
||||
|
||||
// outputs red text
|
||||
console.log("this is an error".error);
|
||||
|
||||
// outputs yellow text
|
||||
console.log("this is a warning".warn);
|
||||
|
||||
// outputs grey text
|
||||
console.log("this is an input".input);
|
||||
|
||||
// Load a theme from file
|
||||
colors.setTheme('./themes/winston-dark.js');
|
||||
|
||||
console.log("this is an input".input);
|
||||
|
||||
29
node_modules/ipc/node_modules/colors/package.json
generated
vendored
Normal file
29
node_modules/ipc/node_modules/colors/package.json
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "colors",
|
||||
"description": "get colors in your node.js console like what",
|
||||
"version": "0.6.2",
|
||||
"author": {
|
||||
"name": "Marak Squires"
|
||||
},
|
||||
"homepage": "https://github.com/Marak/colors.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Marak/colors.js/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"ansi",
|
||||
"terminal",
|
||||
"colors"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "http://github.com/Marak/colors.js.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.1.90"
|
||||
},
|
||||
"main": "colors",
|
||||
"readme": "# colors.js - get color and style in your node.js console ( and browser ) like what\n\n<img src=\"http://i.imgur.com/goJdO.png\" border = \"0\"/>\n\n\n## Installation\n\n npm install colors\n\n## colors and styles!\n\n- bold\n- italic\n- underline\n- inverse\n- yellow\n- cyan\n- white\n- magenta\n- green\n- red\n- grey\n- blue\n- rainbow\n- zebra\n- random\n\n## Usage\n\n``` js\nvar colors = require('./colors');\n\nconsole.log('hello'.green); // outputs green text\nconsole.log('i like cake and pies'.underline.red) // outputs red underlined text\nconsole.log('inverse the color'.inverse); // inverses the color\nconsole.log('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)\n```\n\n# Creating Custom themes\n\n```js\n\nvar colors = require('colors');\n\ncolors.setTheme({\n silly: 'rainbow',\n input: 'grey',\n verbose: 'cyan',\n prompt: 'grey',\n info: 'green',\n data: 'grey',\n help: 'cyan',\n warn: 'yellow',\n debug: 'blue',\n error: 'red'\n});\n\n// outputs red text\nconsole.log(\"this is an error\".error);\n\n// outputs yellow text\nconsole.log(\"this is a warning\".warn);\n```\n\n\n### Contributors \n\nMarak (Marak Squires)\nAlexis Sellier (cloudhead)\nmmalecki (Maciej Małecki)\nnicoreed (Nico Reed)\nmorganrallen (Morgan Allen)\nJustinCampbell (Justin Campbell)\nded (Dustin Diaz)\n\n\n#### , Marak Squires , Justin Campbell, Dustin Diaz (@ded)\n",
|
||||
"readmeFilename": "ReadMe.md",
|
||||
"_id": "colors@0.6.2",
|
||||
"_from": "colors@"
|
||||
}
|
||||
70
node_modules/ipc/node_modules/colors/test.js
generated
vendored
Normal file
70
node_modules/ipc/node_modules/colors/test.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
var assert = require('assert'),
|
||||
colors = require('./colors');
|
||||
|
||||
var s = 'string';
|
||||
|
||||
function a(s, code) {
|
||||
return '\x1B[' + code.toString() + 'm' + s + '\x1B[39m';
|
||||
}
|
||||
|
||||
function aE(s, color, code) {
|
||||
assert.equal(s[color], a(s, code));
|
||||
assert.equal(colors[color](s), a(s, code));
|
||||
assert.equal(s[color], colors[color](s));
|
||||
assert.equal(s[color].stripColors, s);
|
||||
assert.equal(s[color].stripColors, colors.stripColors(s));
|
||||
}
|
||||
|
||||
function h(s, color) {
|
||||
return '<span style="color:' + color + ';">' + s + '</span>';
|
||||
}
|
||||
|
||||
var stylesColors = ['white', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'];
|
||||
var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']);
|
||||
|
||||
colors.mode = 'console';
|
||||
assert.equal(s.bold, '\x1B[1m' + s + '\x1B[22m');
|
||||
assert.equal(s.italic, '\x1B[3m' + s + '\x1B[23m');
|
||||
assert.equal(s.underline, '\x1B[4m' + s + '\x1B[24m');
|
||||
assert.equal(s.strikethrough, '\x1B[9m' + s + '\x1B[29m');
|
||||
assert.equal(s.inverse, '\x1B[7m' + s + '\x1B[27m');
|
||||
assert.ok(s.rainbow);
|
||||
aE(s, 'white', 37);
|
||||
aE(s, 'grey', 90);
|
||||
aE(s, 'black', 30);
|
||||
aE(s, 'blue', 34);
|
||||
aE(s, 'cyan', 36);
|
||||
aE(s, 'green', 32);
|
||||
aE(s, 'magenta', 35);
|
||||
aE(s, 'red', 31);
|
||||
aE(s, 'yellow', 33);
|
||||
assert.equal(s, 'string');
|
||||
|
||||
colors.setTheme({error:'red'});
|
||||
|
||||
assert.equal(typeof("astring".red),'string');
|
||||
assert.equal(typeof("astring".error),'string');
|
||||
|
||||
colors.mode = 'browser';
|
||||
assert.equal(s.bold, '<b>' + s + '</b>');
|
||||
assert.equal(s.italic, '<i>' + s + '</i>');
|
||||
assert.equal(s.underline, '<u>' + s + '</u>');
|
||||
assert.equal(s.strikethrough, '<del>' + s + '</del>');
|
||||
assert.equal(s.inverse, '<span style="background-color:black;color:white;">' + s + '</span>');
|
||||
assert.ok(s.rainbow);
|
||||
stylesColors.forEach(function (color) {
|
||||
assert.equal(s[color], h(s, color));
|
||||
assert.equal(colors[color](s), h(s, color));
|
||||
});
|
||||
|
||||
assert.equal(typeof("astring".red),'string');
|
||||
assert.equal(typeof("astring".error),'string');
|
||||
|
||||
colors.mode = 'none';
|
||||
stylesAll.forEach(function (style) {
|
||||
assert.equal(s[style], s);
|
||||
assert.equal(colors[style](s), s);
|
||||
});
|
||||
|
||||
assert.equal(typeof("astring".red),'string');
|
||||
assert.equal(typeof("astring".error),'string');
|
||||
12
node_modules/ipc/node_modules/colors/themes/winston-dark.js
generated
vendored
Normal file
12
node_modules/ipc/node_modules/colors/themes/winston-dark.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
module['exports'] = {
|
||||
silly: 'rainbow',
|
||||
input: 'black',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red'
|
||||
};
|
||||
12
node_modules/ipc/node_modules/colors/themes/winston-light.js
generated
vendored
Normal file
12
node_modules/ipc/node_modules/colors/themes/winston-light.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
module['exports'] = {
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red'
|
||||
};
|
||||
24
node_modules/ipc/node_modules/event-pubsub/LICENSE
generated
vendored
Normal file
24
node_modules/ipc/node_modules/event-pubsub/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org>
|
||||
119
node_modules/ipc/node_modules/event-pubsub/README.md
generated
vendored
Normal file
119
node_modules/ipc/node_modules/event-pubsub/README.md
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
Event PubSub
|
||||
============
|
||||
|
||||
Pubsub events for Node and the browser allowing event scoping and multiple scopes.
|
||||
Easy for any developer level. No frills, just high speed pubsub events!
|
||||
|
||||
[Pretty GitHub.io site](http://riaevangelist.github.io/event-pubsub/)
|
||||
|
||||
[](https://npmjs.org/package/event-pubsub)
|
||||
|
||||
**EXAMPLE FILES**
|
||||
|
||||
1. [Node Pubsub Event Examples](https://github.com/RIAEvangelist/event-pubsub/tree/master/examples/node)
|
||||
2. [Browser Pubsub Event Examples](https://github.com/RIAEvangelist/event-pubsub/tree/master/examples/browser)
|
||||
|
||||
**Node Install**
|
||||
``npm install event-pubsub``
|
||||
|
||||
**Browser Install**
|
||||
*see browser examples above or below*
|
||||
|
||||
---
|
||||
### Basic Example
|
||||
---
|
||||
***NOTE - the only diffeence between node and browser code is how the ``events`` variable is created***
|
||||
* node ``var events = new require('../../event-pubsub.js')();``
|
||||
* browser ``var events = new window.pubsub();``
|
||||
|
||||
#### Node
|
||||
|
||||
var events = new require('../../event-pubsub.js')();
|
||||
|
||||
events.on(
|
||||
'hello',
|
||||
function(data){
|
||||
console.log('hello event recieved ', data);
|
||||
}
|
||||
);
|
||||
|
||||
events.on(
|
||||
'*',
|
||||
function(type){
|
||||
console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
|
||||
}
|
||||
);
|
||||
|
||||
events.on(
|
||||
'removeEvents',
|
||||
function(){
|
||||
events.off('*');
|
||||
console.log('Removed all events');
|
||||
}
|
||||
);
|
||||
|
||||
/************************************\
|
||||
* trigger events for testing
|
||||
* **********************************/
|
||||
events.trigger(
|
||||
'hello',
|
||||
'world'
|
||||
);
|
||||
|
||||
events.trigger(
|
||||
'removeEvents'
|
||||
);
|
||||
|
||||
|
||||
#### Browser
|
||||
##### HTML
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>PubSub Example</title>
|
||||
<script src='../../event-pubsub-browser.js'></script>
|
||||
<script src='yourAmazingCode.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
...
|
||||
</body>
|
||||
</html>
|
||||
|
||||
##### Inside Your Amazing Code
|
||||
|
||||
var events = new window.pubsub();
|
||||
|
||||
events.on(
|
||||
'hello',
|
||||
function(data){
|
||||
console.log('hello event recieved ', data);
|
||||
}
|
||||
);
|
||||
|
||||
events.on(
|
||||
'*',
|
||||
function(type){
|
||||
console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
|
||||
}
|
||||
);
|
||||
|
||||
events.on(
|
||||
'removeEvents',
|
||||
function(){
|
||||
events.off('*');
|
||||
console.log('Removed all events');
|
||||
}
|
||||
);
|
||||
|
||||
/************************************\
|
||||
* trigger events for testing
|
||||
* **********************************/
|
||||
events.trigger(
|
||||
'hello',
|
||||
'world'
|
||||
);
|
||||
|
||||
events.trigger(
|
||||
'removeEvents'
|
||||
);
|
||||
128
node_modules/ipc/node_modules/event-pubsub/event-pubsub-browser.js
generated
vendored
Normal file
128
node_modules/ipc/node_modules/event-pubsub/event-pubsub-browser.js
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
window.pubsub=(
|
||||
function(){
|
||||
|
||||
function sub(type,handler){
|
||||
checkScope.apply(this);
|
||||
|
||||
if(!this._events_[type])
|
||||
this._events_[type]=[];
|
||||
|
||||
this._events_[type].push(handler);
|
||||
}
|
||||
|
||||
function unsub(type,handler){
|
||||
checkScope.apply(this);
|
||||
|
||||
if(type=='*'){
|
||||
var params=Array.prototype.slice.call(arguments,1);
|
||||
for(
|
||||
var keys = Object.keys(this._events_),
|
||||
count = keys.length,
|
||||
i=0;
|
||||
i<count;
|
||||
i++
|
||||
){
|
||||
var args=params.unshift(keys[i]);
|
||||
this.off.call(args);
|
||||
}
|
||||
}
|
||||
|
||||
if(!this._events_[type])
|
||||
return;
|
||||
|
||||
if(!handler){
|
||||
delete this._events_[type];
|
||||
return;
|
||||
}
|
||||
|
||||
if(this._events_[type].length<2){
|
||||
delete this._events_[type];
|
||||
return;
|
||||
}
|
||||
|
||||
for(var i=0,
|
||||
count=this._events_[type].length;
|
||||
i<count;
|
||||
i++
|
||||
){
|
||||
if(this._events_[type][i]==handler)
|
||||
this._events_[type].splice(i,1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function pub(type){
|
||||
checkScope.apply(this);
|
||||
|
||||
if(this._events_['*'] && type!='*'){
|
||||
var params=Array.prototype.slice.call(arguments);
|
||||
params.unshift('*');
|
||||
this.trigger.apply(this,params);
|
||||
}
|
||||
|
||||
if(!this._events_[type])
|
||||
return;
|
||||
|
||||
for(var i=0,
|
||||
events=this._events_[type],
|
||||
count=events.length,
|
||||
args=Array.prototype.slice.call(arguments,1);
|
||||
i<count;
|
||||
i++){
|
||||
events[i].apply(this, args);
|
||||
}
|
||||
}
|
||||
|
||||
function checkScope(){
|
||||
if(!this._events_)
|
||||
this._events_={};
|
||||
}
|
||||
|
||||
function init(scope){
|
||||
if(!scope)
|
||||
return {
|
||||
on:sub,
|
||||
off:unsub,
|
||||
trigger:pub
|
||||
};
|
||||
|
||||
scope.on=(
|
||||
function(scope){
|
||||
return function(){
|
||||
sub.apply(
|
||||
scope,
|
||||
Array.prototype.slice.call(arguments)
|
||||
);
|
||||
}
|
||||
}
|
||||
)(scope);
|
||||
|
||||
scope.off=(
|
||||
function(scope){
|
||||
return function(){
|
||||
unsub.apply(
|
||||
scope,
|
||||
Array.prototype.slice.call(arguments)
|
||||
);
|
||||
}
|
||||
}
|
||||
)(scope);
|
||||
|
||||
scope.trigger=(
|
||||
function(scope){
|
||||
return function(){
|
||||
pub.apply(
|
||||
scope,
|
||||
Array.prototype.slice.call(arguments)
|
||||
);
|
||||
}
|
||||
}
|
||||
)(scope);
|
||||
|
||||
scope._events_={};
|
||||
}
|
||||
|
||||
return init;
|
||||
|
||||
}
|
||||
)();
|
||||
122
node_modules/ipc/node_modules/event-pubsub/event-pubsub.js
generated
vendored
Normal file
122
node_modules/ipc/node_modules/event-pubsub/event-pubsub.js
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
function sub(type,handler){
|
||||
checkScope.apply(this);
|
||||
|
||||
if(!this._events_[type])
|
||||
this._events_[type]=[];
|
||||
|
||||
this._events_[type].push(handler);
|
||||
}
|
||||
|
||||
function unsub(type,handler){
|
||||
checkScope.apply(this);
|
||||
|
||||
if(type=='*'){
|
||||
var params=Array.prototype.slice.call(arguments,1);
|
||||
for(
|
||||
var keys = Object.keys(this._events_),
|
||||
count = keys.length,
|
||||
i=0;
|
||||
i<count;
|
||||
i++
|
||||
){
|
||||
var args=params.unshift(keys[i]);
|
||||
this.off.call(args);
|
||||
}
|
||||
}
|
||||
|
||||
if(!this._events_[type])
|
||||
return;
|
||||
|
||||
if(!handler){
|
||||
delete this._events_[type];
|
||||
return;
|
||||
}
|
||||
|
||||
if(this._events_[type].length<2){
|
||||
delete this._events_[type];
|
||||
return;
|
||||
}
|
||||
|
||||
for(var i=0,
|
||||
count=this._events_[type].length;
|
||||
i<count;
|
||||
i++
|
||||
){
|
||||
if(this._events_[type][i]==handler)
|
||||
this._events_[type].splice(i,1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function pub(type){
|
||||
checkScope.apply(this);
|
||||
|
||||
if(this._events_['*'] && type!='*'){
|
||||
var params=Array.prototype.slice.call(arguments);
|
||||
params.unshift('*');
|
||||
this.trigger.apply(this,params);
|
||||
}
|
||||
|
||||
if(!this._events_[type])
|
||||
return;
|
||||
|
||||
for(var i=0,
|
||||
events=this._events_[type],
|
||||
count=events.length,
|
||||
args=Array.prototype.slice.call(arguments,1);
|
||||
i<count;
|
||||
i++){
|
||||
events[i].apply(this, args);
|
||||
}
|
||||
}
|
||||
|
||||
function checkScope(){
|
||||
if(!this._events_)
|
||||
this._events_={};
|
||||
}
|
||||
|
||||
function init(scope){
|
||||
if(!scope)
|
||||
return {
|
||||
on:sub,
|
||||
off:unsub,
|
||||
trigger:pub
|
||||
};
|
||||
|
||||
scope.on=(
|
||||
function(scope){
|
||||
return function(){
|
||||
sub.apply(
|
||||
scope,
|
||||
Array.prototype.slice.call(arguments)
|
||||
);
|
||||
}
|
||||
}
|
||||
)(scope);
|
||||
|
||||
scope.off=(
|
||||
function(scope){
|
||||
return function(){
|
||||
unsub.apply(
|
||||
scope,
|
||||
Array.prototype.slice.call(arguments)
|
||||
);
|
||||
}
|
||||
}
|
||||
)(scope);
|
||||
|
||||
scope.trigger=(
|
||||
function(scope){
|
||||
return function(){
|
||||
pub.apply(
|
||||
scope,
|
||||
Array.prototype.slice.call(arguments)
|
||||
);
|
||||
}
|
||||
}
|
||||
)(scope);
|
||||
|
||||
scope._events_={};
|
||||
}
|
||||
|
||||
module.exports=init
|
||||
15
node_modules/ipc/node_modules/event-pubsub/examples/browser/basic.html
generated
vendored
Normal file
15
node_modules/ipc/node_modules/event-pubsub/examples/browser/basic.html
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Basic PubSub Example</title>
|
||||
<script src='../../event-pubsub-browser.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
<ul id='events'>
|
||||
<li>
|
||||
<h1>PubSub Basic Events Example</h1>
|
||||
</li>
|
||||
</ul>
|
||||
<script src='basic.js'></script>
|
||||
</body>
|
||||
</html>
|
||||
75
node_modules/ipc/node_modules/event-pubsub/examples/browser/basic.js
generated
vendored
Normal file
75
node_modules/ipc/node_modules/event-pubsub/examples/browser/basic.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
var events = new window.pubsub();
|
||||
|
||||
/************************************\
|
||||
*
|
||||
* The events var was instantiated
|
||||
* as it's own scope
|
||||
*
|
||||
* **********************************/
|
||||
|
||||
events.on(
|
||||
'hello',
|
||||
function(data){
|
||||
eventLog.log('hello event recieved ', data);
|
||||
}
|
||||
);
|
||||
|
||||
events.on(
|
||||
'hello',
|
||||
function(data){
|
||||
eventLog.log('Second handler listening to hello event got',data);
|
||||
events.trigger(
|
||||
'world',
|
||||
{
|
||||
type:'myObject',
|
||||
data:{
|
||||
x:'YAY, Objects!'
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
events.on(
|
||||
'world',
|
||||
function(data){
|
||||
eventLog.log('World event got',data);
|
||||
events.off('*');
|
||||
eventLog.log('Removed all events')
|
||||
}
|
||||
);
|
||||
|
||||
/**********************************\
|
||||
*
|
||||
* Demonstrate * event (on all events)
|
||||
* remove this for less verbose
|
||||
* example
|
||||
*
|
||||
* ********************************/
|
||||
events.on(
|
||||
'*',
|
||||
function(type){
|
||||
eventLog.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
|
||||
}
|
||||
);
|
||||
|
||||
/*******************************\
|
||||
*
|
||||
* Prep HTML for logging
|
||||
*
|
||||
* *****************************/
|
||||
var eventLog=document.getElementById('events');
|
||||
//not using console.log incase it doesn't work in some browser. *TLDT (Too lazy didn't test)*
|
||||
eventLog.log=_log_;
|
||||
function _log_ (){
|
||||
var events=Array.prototype.slice.call(arguments),
|
||||
newEvent=document.createElement('li');
|
||||
|
||||
newEvent.innerHTML=events.join(' ');
|
||||
this.appendChild(newEvent);
|
||||
}
|
||||
|
||||
events.trigger(
|
||||
'hello',
|
||||
'world'
|
||||
);
|
||||
15
node_modules/ipc/node_modules/event-pubsub/examples/browser/multipleScopes.html
generated
vendored
Normal file
15
node_modules/ipc/node_modules/event-pubsub/examples/browser/multipleScopes.html
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Basic PubSub Example</title>
|
||||
<script src='../../event-pubsub-browser.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
<ul id='events'>
|
||||
<li>
|
||||
<h1>PubSub Multiple Event Scopes Example</h1>
|
||||
</li>
|
||||
</ul>
|
||||
<script src='multipleScopes.js'></script>
|
||||
</body>
|
||||
</html>
|
||||
103
node_modules/ipc/node_modules/event-pubsub/examples/browser/multipleScopes.js
generated
vendored
Normal file
103
node_modules/ipc/node_modules/event-pubsub/examples/browser/multipleScopes.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
/************************************\
|
||||
* instantiating myEvents scope
|
||||
* **********************************/
|
||||
var myEvents=new window.pubsub();
|
||||
|
||||
/************************************\
|
||||
* instantiating myEvents2 scope
|
||||
* **********************************/
|
||||
var myEvents2=new window.pubsub();
|
||||
|
||||
|
||||
/************************************\
|
||||
* binding myEvents events
|
||||
* **********************************/
|
||||
myEvents.on(
|
||||
'hello',
|
||||
function(data){
|
||||
eventLog.log('myEvents hello event recieved ', data);
|
||||
}
|
||||
);
|
||||
|
||||
myEvents.on(
|
||||
'hello',
|
||||
function(data){
|
||||
eventLog.log('Second handler listening to myEvents hello event got',data);
|
||||
myEvents.trigger(
|
||||
'world',
|
||||
{
|
||||
type:'myObject',
|
||||
data:{
|
||||
x:'YAY, Objects!'
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
myEvents.on(
|
||||
'world',
|
||||
function(data){
|
||||
eventLog.log('myEvents World event got',data);
|
||||
}
|
||||
);
|
||||
|
||||
/**********************************\
|
||||
*
|
||||
* Demonstrate * event (on all events)
|
||||
* remove this for less verbose
|
||||
* example
|
||||
*
|
||||
* ********************************/
|
||||
myEvents.on(
|
||||
'*',
|
||||
function(type){
|
||||
eventLog.log('myEvents Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
|
||||
}
|
||||
);
|
||||
|
||||
/************************************\
|
||||
* binding myEvents2 events
|
||||
* **********************************/
|
||||
myEvents2.on(
|
||||
'hello',
|
||||
function(data){
|
||||
eventLog.log('myEvents2 Hello event should never be called ', data);
|
||||
}
|
||||
);
|
||||
|
||||
myEvents2.on(
|
||||
'world',
|
||||
function(data){
|
||||
eventLog.log('myEvents2 World event ',data);
|
||||
}
|
||||
);
|
||||
|
||||
/*******************************\
|
||||
*
|
||||
* Prep HTML for logging
|
||||
*
|
||||
* *****************************/
|
||||
var eventLog=document.getElementById('events');
|
||||
//not using console.log incase it doesn't work in some browser. *TLDT (Too lazy didn't test)*
|
||||
eventLog.log=_log_;
|
||||
function _log_ (){
|
||||
var events=Array.prototype.slice.call(arguments),
|
||||
newEvent=document.createElement('li');
|
||||
|
||||
newEvent.innerHTML=events.join(' ');
|
||||
this.appendChild(newEvent);
|
||||
}
|
||||
|
||||
/************************************\
|
||||
* trigger events for testing
|
||||
* **********************************/
|
||||
myEvents.trigger(
|
||||
'hello',
|
||||
'world'
|
||||
);
|
||||
|
||||
myEvents2.trigger(
|
||||
'world',
|
||||
'is round'
|
||||
);
|
||||
15
node_modules/ipc/node_modules/event-pubsub/examples/browser/objectScope.html
generated
vendored
Normal file
15
node_modules/ipc/node_modules/event-pubsub/examples/browser/objectScope.html
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Basic PubSub Example</title>
|
||||
<script src='../../event-pubsub-browser.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
<ul id='events'>
|
||||
<li>
|
||||
<h1>PubSub Events inside of and using an Object as the scope Example</h1>
|
||||
</li>
|
||||
</ul>
|
||||
<script src='objectScope.js'></script>
|
||||
</body>
|
||||
</html>
|
||||
73
node_modules/ipc/node_modules/event-pubsub/examples/browser/objectScope.js
generated
vendored
Normal file
73
node_modules/ipc/node_modules/event-pubsub/examples/browser/objectScope.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/************************************\
|
||||
*
|
||||
* The events var was instantiated
|
||||
* as it's own scope
|
||||
*
|
||||
* **********************************/
|
||||
|
||||
var thing={
|
||||
id:'my thing'
|
||||
}
|
||||
/******************************\
|
||||
*
|
||||
* Create events in the scope
|
||||
* of the "thing" object
|
||||
*
|
||||
* ****************************/
|
||||
new window.pubsub(thing);
|
||||
|
||||
thing.on(
|
||||
'getID',
|
||||
function(){
|
||||
eventLog.log('things id is : ',this.id);
|
||||
}
|
||||
);
|
||||
|
||||
thing.on(
|
||||
'setID',
|
||||
function(id){
|
||||
eventLog.log('setting id to : ',id);
|
||||
this.id=id;
|
||||
this.trigger('getID');
|
||||
}
|
||||
);
|
||||
|
||||
/**********************************\
|
||||
*
|
||||
* Demonstrate * event (on all events)
|
||||
* remove this for less verbose
|
||||
* example
|
||||
*
|
||||
* ********************************/
|
||||
thing.on(
|
||||
'*',
|
||||
function(type){
|
||||
eventLog.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
|
||||
}
|
||||
);
|
||||
|
||||
/*******************************\
|
||||
*
|
||||
* Prep HTML for logging
|
||||
*
|
||||
* *****************************/
|
||||
var eventLog=document.getElementById('events');
|
||||
//not using console.log incase it doesn't work in some browser. *TLDT (Too lazy didn't test)*
|
||||
eventLog.log=_log_;
|
||||
function _log_ (){
|
||||
var events=Array.prototype.slice.call(arguments),
|
||||
newEvent=document.createElement('li');
|
||||
|
||||
newEvent.innerHTML=events.join(' ');
|
||||
this.appendChild(newEvent);
|
||||
}
|
||||
|
||||
/************************************\
|
||||
* trigger events for testing
|
||||
* **********************************/
|
||||
thing.trigger('getID');
|
||||
|
||||
thing.trigger(
|
||||
'setID',
|
||||
'your thing'
|
||||
)
|
||||
62
node_modules/ipc/node_modules/event-pubsub/examples/node/basic.js
generated
vendored
Normal file
62
node_modules/ipc/node_modules/event-pubsub/examples/node/basic.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
var events = new require('../../event-pubsub.js')();
|
||||
|
||||
/************************************\
|
||||
*
|
||||
* The events var was instantiated
|
||||
* as it's own scope
|
||||
*
|
||||
* **********************************/
|
||||
|
||||
events.on(
|
||||
'hello',
|
||||
function(data){
|
||||
console.log('hello event recieved ', data);
|
||||
}
|
||||
);
|
||||
|
||||
events.on(
|
||||
'hello',
|
||||
function(data){
|
||||
console.log('Second handler listening to hello event got',data);
|
||||
events.trigger(
|
||||
'world',
|
||||
{
|
||||
type:'myObject',
|
||||
data:{
|
||||
x:'YAY, Objects!'
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
events.on(
|
||||
'world',
|
||||
function(data){
|
||||
console.log('World event got',data);
|
||||
events.off('*');
|
||||
console.log('Removed all events');
|
||||
}
|
||||
);
|
||||
|
||||
/**********************************\
|
||||
*
|
||||
* Demonstrate * event (on all events)
|
||||
* remove this for less verbose
|
||||
* example
|
||||
*
|
||||
* ********************************/
|
||||
events.on(
|
||||
'*',
|
||||
function(type){
|
||||
console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
|
||||
}
|
||||
);
|
||||
|
||||
/************************************\
|
||||
* trigger events for testing
|
||||
* **********************************/
|
||||
events.trigger(
|
||||
'hello',
|
||||
'world'
|
||||
);
|
||||
90
node_modules/ipc/node_modules/event-pubsub/examples/node/multipleScopes.js
generated
vendored
Normal file
90
node_modules/ipc/node_modules/event-pubsub/examples/node/multipleScopes.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
var pubsub = require('../../event-pubsub.js');
|
||||
|
||||
/************************************\
|
||||
* instantiating myEvents scope
|
||||
* **********************************/
|
||||
var myEvents=new pubsub();
|
||||
|
||||
/************************************\
|
||||
* instantiating myEvents2 scope
|
||||
* **********************************/
|
||||
var myEvents2=new pubsub();
|
||||
|
||||
|
||||
/************************************\
|
||||
* binding myEvents events
|
||||
* **********************************/
|
||||
myEvents.on(
|
||||
'hello',
|
||||
function(data){
|
||||
console.log('myEvents hello event recieved ', data);
|
||||
}
|
||||
);
|
||||
|
||||
myEvents.on(
|
||||
'hello',
|
||||
function(data){
|
||||
console.log('Second handler listening to myEvents hello event got',data);
|
||||
myEvents.trigger(
|
||||
'world',
|
||||
{
|
||||
type:'myObject',
|
||||
data:{
|
||||
x:'YAY, Objects!'
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
myEvents.on(
|
||||
'world',
|
||||
function(data){
|
||||
console.log('myEvents World event got',data);
|
||||
}
|
||||
);
|
||||
|
||||
/**********************************\
|
||||
*
|
||||
* Demonstrate * event (on all events)
|
||||
* remove this for less verbose
|
||||
* example
|
||||
*
|
||||
* ********************************/
|
||||
myEvents.on(
|
||||
'*',
|
||||
function(type){
|
||||
console.log('myEvents Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
|
||||
}
|
||||
);
|
||||
|
||||
/************************************\
|
||||
* binding myEvents2 events
|
||||
* **********************************/
|
||||
myEvents2.on(
|
||||
'hello',
|
||||
function(data){
|
||||
console.log('myEvents2 Hello event should never be called ', data);
|
||||
}
|
||||
);
|
||||
|
||||
myEvents2.on(
|
||||
'world',
|
||||
function(data){
|
||||
console.log('myEvents2 World event ',data);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/************************************\
|
||||
* trigger events for testing
|
||||
* **********************************/
|
||||
myEvents.trigger(
|
||||
'hello',
|
||||
'world'
|
||||
);
|
||||
|
||||
myEvents2.trigger(
|
||||
'world',
|
||||
'is round'
|
||||
);
|
||||
56
node_modules/ipc/node_modules/event-pubsub/examples/node/objectScope.js
generated
vendored
Normal file
56
node_modules/ipc/node_modules/event-pubsub/examples/node/objectScope.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
var pubsub = require('../../event-pubsub.js');
|
||||
|
||||
/************************************\
|
||||
*
|
||||
* The events var was instantiated
|
||||
* as it's own scope
|
||||
*
|
||||
* **********************************/
|
||||
|
||||
var thing={
|
||||
id:'my thing'
|
||||
}
|
||||
/******************************\
|
||||
*
|
||||
* Create events in the scope
|
||||
* of the "thing" object
|
||||
*
|
||||
* ****************************/
|
||||
new pubsub(thing);
|
||||
|
||||
thing.on(
|
||||
'getID',
|
||||
function(){
|
||||
console.log('things id is : ',this.id);
|
||||
}
|
||||
);
|
||||
|
||||
thing.on(
|
||||
'setID',
|
||||
function(id){
|
||||
console.log('setting id to : ',id);
|
||||
this.id=id;
|
||||
this.trigger('getID');
|
||||
}
|
||||
);
|
||||
|
||||
/**********************************\
|
||||
*
|
||||
* Demonstrate * event (on all events)
|
||||
* remove this for less verbose
|
||||
* example
|
||||
*
|
||||
* ********************************/
|
||||
thing.on(
|
||||
'*',
|
||||
function(type){
|
||||
console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
|
||||
}
|
||||
);
|
||||
|
||||
thing.trigger('getID');
|
||||
|
||||
thing.trigger(
|
||||
'setID',
|
||||
'your thing'
|
||||
)
|
||||
39
node_modules/ipc/node_modules/event-pubsub/package.json
generated
vendored
Normal file
39
node_modules/ipc/node_modules/event-pubsub/package.json
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "event-pubsub",
|
||||
"version": "1.0.3",
|
||||
"description": "Pubsub events for Node and the browser allowing event scoping and multiple scopes. Easy for any developer level. No frills, just high speed pubsub events!",
|
||||
"main": "event-pubsub.js",
|
||||
"directories": {
|
||||
"example": "examples"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/RIAEvangelist/event-pubsub.git"
|
||||
},
|
||||
"keywords": [
|
||||
"event",
|
||||
"events",
|
||||
"pubsub",
|
||||
"node",
|
||||
"browser"
|
||||
],
|
||||
"author": {
|
||||
"name": "Brandon Nozaki Miller"
|
||||
},
|
||||
"license": "Unlicense",
|
||||
"bugs": {
|
||||
"url": "https://github.com/RIAEvangelist/event-pubsub/issues"
|
||||
},
|
||||
"homepage": "http://riaevangelist.github.io/event-pubsub/",
|
||||
"readme": "Event PubSub\n============\n\nPubsub events for Node and the browser allowing event scoping and multiple scopes. \nEasy for any developer level. No frills, just high speed pubsub events!\n\n[Pretty GitHub.io site](http://riaevangelist.github.io/event-pubsub/) \n\n[](https://npmjs.org/package/event-pubsub)\n\n**EXAMPLE FILES** \n\n1. [Node Pubsub Event Examples](https://github.com/RIAEvangelist/event-pubsub/tree/master/examples/node) \n2. [Browser Pubsub Event Examples](https://github.com/RIAEvangelist/event-pubsub/tree/master/examples/browser)\n\n**Node Install** \n``npm install event-pubsub``\n\n**Browser Install** \n*see browser examples above or below*\n\n---\n### Basic Example\n---\n***NOTE - the only diffeence between node and browser code is how the ``events`` variable is created*** \n* node ``var events = new require('../../event-pubsub.js')();``\n* browser ``var events = new window.pubsub();``\n\n#### Node\n\n var events = new require('../../event-pubsub.js')();\n\n events.on(\n 'hello',\n function(data){\n console.log('hello event recieved ', data);\n }\n );\n \n events.on(\n '*',\n function(type){\n console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);\n }\n );\n \n events.on(\n 'removeEvents',\n function(){\n events.off('*');\n console.log('Removed all events');\n }\n );\n \n /************************************\\\n * trigger events for testing\n * **********************************/\n events.trigger(\n 'hello',\n 'world'\n );\n \n events.trigger(\n 'removeEvents'\n );\n \n\n#### Browser\n##### HTML\n\n <!DOCTYPE html>\n <html>\n <head>\n <title>PubSub Example</title>\n <script src='../../event-pubsub-browser.js'></script>\n <script src='yourAmazingCode.js'></script>\n </head>\n <body>\n ...\n </body>\n </html>\n\n##### Inside Your Amazing Code\n\n var events = new window.pubsub();\n\n events.on(\n 'hello',\n function(data){\n console.log('hello event recieved ', data);\n }\n );\n \n events.on(\n '*',\n function(type){\n console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);\n }\n );\n \n events.on(\n 'removeEvents',\n function(){\n events.off('*');\n console.log('Removed all events');\n }\n );\n \n /************************************\\\n * trigger events for testing\n * **********************************/\n events.trigger(\n 'hello',\n 'world'\n );\n \n events.trigger(\n 'removeEvents'\n );\n",
|
||||
"readmeFilename": "README.md",
|
||||
"_id": "event-pubsub@1.0.3",
|
||||
"dist": {
|
||||
"shasum": "c81c49b101cdb4892d8fa2631b443184db2de6aa"
|
||||
},
|
||||
"_from": "event-pubsub@1.0.3",
|
||||
"_resolved": "https://registry.npmjs.org/event-pubsub/-/event-pubsub-1.0.3.tgz"
|
||||
}
|
||||
46
node_modules/ipc/package.json
generated
vendored
Normal file
46
node_modules/ipc/package.json
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "node-ipc",
|
||||
"version": "1.0.0",
|
||||
"description": "A nodejs module for local and remote Inter Process Communication (IPC), Neural Networking, and able to facilitate machine learning.",
|
||||
"main": "node-ipc.js",
|
||||
"directories": {
|
||||
"example": "example"
|
||||
},
|
||||
"dependencies": {
|
||||
"event-pubsub": "~1.0.3",
|
||||
"colors": "~0.6.2"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [
|
||||
"IPC",
|
||||
"Neural Networking",
|
||||
"Machine Learning",
|
||||
"inter",
|
||||
"process",
|
||||
"communication",
|
||||
"unix",
|
||||
"TCP",
|
||||
"UDP",
|
||||
"domain",
|
||||
"sockets",
|
||||
"threaded",
|
||||
"communication",
|
||||
"multi",
|
||||
"process",
|
||||
"shared",
|
||||
"memory"
|
||||
],
|
||||
"author": "Brandon Nozaki Miller",
|
||||
"license": "Unlicenced",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/RIAEvangelist/node-ipc.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/RIAEvangelist/node-ipc/issues"
|
||||
},
|
||||
"homepage": "http://riaevangelist.github.io/node-ipc/"
|
||||
}
|
||||
Reference in New Issue
Block a user