Skip to content

Commit

Permalink
updated deps, removed ws, fixed license, cleaned loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
fed135 committed Mar 29, 2016
1 parent 66e77a2 commit f1118db
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 541 deletions.
340 changes: 0 additions & 340 deletions LICENSE

This file was deleted.

11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ Allow you to easily use different socket types, hassle-free

| **Type** | **Library used** | **Status** |
|---|---|---|
| IPC | | DEV |
| TCP | | DEV |
| UDP | | DEV |
| WebSocket | [socket.io](https://github.com/socketio/socket.io) | DEV |
| IPC | | IN-DEV |
| TCP | | - |
| UDP | | - |


## Encoders
Expand All @@ -38,7 +37,7 @@ Perform batch operation of payloads.

| **Type** | **Library used** | **Status** |
|---|---|---|
| Bundler | | DEV |
| Bundler | | IN-DEV |

---

Expand Down Expand Up @@ -74,7 +73,7 @@ The framework is flexible enough so that you can load your own custom adapters,
server.on('connection', function(client) {} // Handler, where client is an instance of Kalm.Client

server.broadcast('someOtherEvent', 'hello!');


## Performance analysis

Expand Down
34 changes: 14 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kalm",
"version": "1.1.0",
"description": "A Kalm Application.",
"version": "0.0.1",
"description": "The socket optimizer",
"main": "./index.js",
"scripts": {
"test": "mocha tests/unit/index.js"
Expand All @@ -11,41 +11,35 @@
"url": "git+https://github.com/fed135/Kalm.git"
},
"keywords": [
"framework",
"socket",
"tcp",
"udp",
"ws",
"client",
"server",
"service",
"peer",
"micro-service",
"low-latency",
"light",
"ipc"
],
"author": "frederic charette",
"licenses": [
{
"type": "GNU GPL V2",
"url": "https://github.com/fed135/Kalm/blob/master/LICENSE"
}
"ipc",
"messaging",
"queue"
],
"author": "frederic charette <fredericcharette@gmail.com>",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/fed135/Kalm/issues"
},
"homepage": "https://github.com/fed135/Kalm#readme",
"devDependencies": {
"chai": "2.3.0",
"mocha": "2.2.4"
"chai": "3.4.x",
"mocha": "2.4.x",
"coveralls": "2.11.x",
"istanbul": "0.4.x"
},
"dependencies": {
"debug": "2.2.x",
"socket.io": "1.4.x",
"ipc-light": "1.0.x",
"mixin-deep": "1.1.x",
"msgpack-decode": "1.0.x",
"msgpack-lite": "0.1.x",
"signals": "1.0.x",
"walk": "2.3.x"
"msgpack-lite": "0.1.x"
}
}
50 changes: 49 additions & 1 deletion src/adapters/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,59 @@
/**
* Adapters
* @exports {object}
*/

'use strict';

/* Requires ------------------------------------------------------------------*/

var ipc = require('./ipc.adapter');
var tcp = require('./tcp.adapter');
var udp = require('./udp.adapter');
var ws = require('./ws.adapter');

module.exports = {
var debug = require('debug')('kalm');

/* Local variables -----------------------------------------------------------*/

var list = {
ipc: ipc,
tcp: tcp,
udp: udp,
ws: ws
};

/* Methods -------------------------------------------------------------------*/

/**
* Returns the selected adapter
* @method resolve
* @param {string} name The name of the adapter to return
* @returns {object|undefined} The adapter
*/
function resolve(name) {
if (list[name]) {
return list[name];
}
else {
debug('error: no adapter "' + name + '" found');
return;
}
}

/**
* Registers a new adapter
* @method register
* @param {string} name The name of the adapter
* @param {object} mod The body of the adapter
*/
function register(name, mod) {
list[name] = mod;
}

/* Exports -------------------------------------------------------------------*/

module.exports = {
resolve: resolve,
register: register
};
79 changes: 25 additions & 54 deletions src/adapters/ipc.adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,81 +11,52 @@
var net = require('net');
var fs = require('fs');

/* Methods -------------------------------------------------------------------*/
/* Local variables -----------------------------------------------------------*/

IPC.defaultPath = '/tmp/app.socket-';
var defaultPath = '/tmp/app.socket-';

/**
* IPC adapter
* @constructor
* @param {Kalm} K The Kalm instance
*/
function IPC(options, handler) {
this.options = options;
this.handler = handler;
this.server = null;
}
/* Methods -------------------------------------------------------------------*/

/**
* Listens for ipc connections on the selected port.
* Listens for ipc connections, updates the 'listener' property of the server
* @method listen
* @memberof IPC
* @param {object} options The config object for that adapter
* @param {function} handler The central handling method for requests
* @param {function} callback The success callback for the operation
* @param {Kalm.Server} server The server object
* @param {function} callback The callback for the operation
*/
IPC.prototype.listen = function(callback) {
var _self = this;

fs.unlink(this.path, function bindSocket() {
_self.server = net.createServer(_self.handler);
_self.server.listen(IPC.defaultPath + _self.options.port, callback);
function listen(server, callback) {
fs.unlink(this.path, function _bindSocket() {
server.listener = net.createServer(server._handleRequest);
server.listener.listen(defaultPath + server.options.port, callback);
});
};

/**
* Sends a message with a socket client, then pushes it back to its peer
* @method send
* @memberof IPC
* @param {Buffer} payload The body of the request
* @param {Socket} socket The socket to use
* @param {Buffer} payload The body of the request
*/
IPC.prototype.send = function(socket, payload) {
function send(socket, payload) {
socket.write(payload);
};

/**
* Creates a client and adds the listeners to it
* @method createClient
* @memberof IPC
* @param {Service} peer The peer to create the socket for
* @returns {Socket} The created ipc client
* Creates a client and adds the data listener(s) to it
* @method createSocket
* @param {Kalm.Client} client The client to create the socket for
* @returns {Socket} The created ipc socket
*/
IPC.prototype.createClient = function(peer, handler) {
return net.connect(IPC.defaultPath + this.options.port);
};

/**
* Calls the disconnect method on a socket
* @method removeClient
* @memberof IPC
* @param {Socket} socket The socket to disconnect
*/
IPC.prototype.removeClient = function(socket) {
socket.disconnect();
};
function createSocket(client) {
var socket = net.connect(defaultPath + this.options.port);
socket.on('data', client._handleRequest.bind(client));

/**
* Stops listening for ipc connections and closes the server
* @method stop
* @memberof IPC
* @param {function|null} callback The callback method
*/
IPC.prototype.stop = function(callback) {
if (this.server) this.server.close(callback);
else callback();
return socket;
};

/* Exports -------------------------------------------------------------------*/

module.exports = IPC;
module.exports = {
listen: listen,
send: send,
createSocket: createSocket
};
101 changes: 0 additions & 101 deletions src/adapters/ws.adapter.js

This file was deleted.

Loading

0 comments on commit f1118db

Please sign in to comment.