Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

javascript-protocol-framework

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

javascript-protocol-framework - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

docs/protocol.md

0

docs/_temp.md

@@ -0,0 +0,0 @@

@@ -0,0 +0,0 @@ ## Components

@@ -7,2 +7,4 @@ # Roadmap

* Add stacks in sessions!
*
* Build in support for replies

@@ -9,0 +11,0 @@ * Turn CommandStacks into event emitters which emit an event whenever a command

47

docs/session.md
# Session
The protocol contains all the stateless
## Creating an instance
Creating an instance of a session is pretty straight-forward:
var session = new Session(myProtocol, myStateObject);
## Implementing session.cast and feeding session.receive
### session.cast
### session.receive
Implementing receive
### Extending
You can also extend the session and make them prototype methods to make your
life a little easier:
// Extending
var AdvancedSession(mySpecialSocket) {
this._socket = mySpecialSocket;
var self = this;
this._socket.on('message', function(msg) {
this.receive(msg);
});
arguments.pop();
this.super_(arguments);
}
inherits(AdvancedSession, Session);
AdvancedSession.prototype.cast = function(json) {
this._socket.emit(json);
}
// Using
var session = new AdvancedSession(socket, myProtocol, myStateObject);

@@ -6,19 +6,43 @@ # Transportation Layer

## Available layers
Sometimes, the transportation is rather easy, as illustrated by these three
patterns.
* None yet..
**Singleton pattern**
## Implementing your own
session._out = session._in;
Lets assume we have a hypothetical session:
**Unit-testing pattern**
var session = getSessionSomehow()
session1._out = session2._in.bind(session2);
session2._out = session1._in.bind(session1);
## session.cast
**json-tcp**
The session will call cast whenever it needs to transport something to another
var transport = require('json-tcp').init;
var socket1 = getSocketSomehow();
var socket2 = getSocketSomehow();
### Object Specifications
transport(socket1);
transport(socket2);
socket1._parseMessage = session1._in.bind(session1);
socket2._parseMessage = session2._in.bind(session2);
socket1._out = socket1.send;
socket2._out = socket2.send;
Note that this json-tcp package makes it easy
var transport = require('json-tcp').full;
transport(socket1, session1);
## Implementing your own
### Data Specs
Every javascript object going out of the session will conform to this prototype.
Every object going into the session must also confrom to this prototype.
{

@@ -31,11 +55,21 @@ command: {String}

### Session._out(data)
You must implement this method and transport the data to another session.
### Session._in(data)
Call this method with the data you got in another session in your _out
implementation.
### Implementing a layer using inheritance
You can also extend the session and make them prototype methods to make your
life a little easier:
var AdvancedSession(mySpecialSocket, config) {
var AdvancedSession(config) {
this._socket = mySpecialSocket;
this._socket = config.socket;

@@ -45,6 +79,6 @@ var self = this;

this._socket.on('message', function(msg) {
self.receive(msg);
self._in(msg);
});
this.super_(config);
this.super_.constructor(config);
}

@@ -54,3 +88,3 @@

AdvancedSession.prototype.cast = function(json) {
AdvancedSession.prototype._out = function(json) {
this._socket.emit(json);

@@ -62,2 +96,6 @@ }

var session = new AdvancedSession(socket, config);
var session = new AdvancedSession({
socket: yourMessagifiedSocket,
protocol: yourProtocol,
state: {},
});

@@ -0,0 +0,0 @@ var jpf = require('./../../')

@@ -0,0 +0,0 @@ module.exports = function(grunt) {

@@ -0,0 +0,0 @@ module.exports = {

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

{
"name": "javascript-protocol-framework",
"version": "0.1.0",
"version": "0.1.1",
"description": "A communication protocol framework.",

@@ -40,3 +40,3 @@ "main": "index.js",

"author": "Christophe Bol",
"license": "LGPLv3",
"license": "MIT",
"bugs": {

@@ -43,0 +43,0 @@ "url": "https://github.com/boljen/javascript-protocol-framework/issues"

@@ -9,4 +9,2 @@ # Javascript Protocol Framework

This library is fully unit-tested, browser compatible and very flexible.
## Installation

@@ -16,2 +14,14 @@

## Example
// Server-side protocol
protocol.addCommand('ping', function(message) {
message.reply('pong');
});
// Client-side session
client.write('ping', function(message) {
message.data === 'pong'
})
## Goals

@@ -22,8 +32,12 @@

* Must work cross platform (NodeJS, browser)
* Make business logic agnostic of the used transportation layer
* Make business logic independend from the used transportation layer
## Documentation
*No time*
* [Transportation Layer](docs/transport.md)
See the 'full' implementation of the
[json-tcp module](https://github.com/boljen/node-json-tcp/blob/master/docs/full.md)
for an example.
## Test

@@ -40,5 +54,4 @@

## License
LGPLv3
MIT
require('./stack.js');
require('./protocol.js');
require('./session.js');

@@ -0,0 +0,0 @@ var Protocol = require('./../').Protocol

@@ -0,0 +0,0 @@ var proto = require('./../')

@@ -0,0 +0,0 @@ var Stack = require('./../').Stack;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc