Comparing version 2.1.2 to 2.1.4
@@ -5,3 +5,3 @@ | ||
module.exports = function () { | ||
return (socket, next) => { | ||
return (socket) => { | ||
socket._antena_receptor = this; | ||
@@ -12,3 +12,2 @@ socket.on("error", onerror); | ||
Messaging.input(socket, receive_initial); | ||
return true; | ||
}; | ||
@@ -15,0 +14,0 @@ }; |
{ | ||
"name": "antena", | ||
"description": "Isomorphic communication library for node and browsers", | ||
"version": "2.1.2", | ||
"version": "2.1.4", | ||
"author": { | ||
@@ -13,3 +13,3 @@ "name": "Laurent Christophe", | ||
"posix-socket": "0.0.7", | ||
"ws": "^6.0.0" | ||
"ws": "^6.1.3" | ||
}, | ||
@@ -16,0 +16,0 @@ "keywords": [ |
129
README.md
# Antena | ||
Antena is yet an other JavaScript communication library. | ||
Antena normalizes the server-client model for node and browsers. | ||
Antena normalises the server-client model for node and browsers. | ||
In Antena, the server is called receptor and its clients are called emitters. | ||
Both receptors and emitters can perform push notifications but only emitters can perform synchronous pull requests. | ||
For node emitters, synchronous pull requests are implemented using `https://www.npmjs.com/package/posix-socket` which is much faster than using the synchronous methods of `child_process` and `fs`. | ||
For node emitters, synchronous pull requests are implemented using [posix-socket](https://www.npmjs.com/package/posix-socket) which is much faster than using the synchronous methods of `child_process` and `fs`. | ||
```js | ||
const AntenaReceptor = require("antena/receptor"); | ||
const receptor = AntenaReceptor(); | ||
receptor.onpush = (session, message) => { | ||
console.assert(session === "antena-rocks"); | ||
receptor.push(session, message+"World"); | ||
}; | ||
receptor.onpull = (session, message, callback) => { | ||
callback(message+"World!!!"); | ||
receptor.onpull = (session, query, callback) => { | ||
console.assert(session === "antena-rocks"); | ||
callback(query+"World!!!"); | ||
}; | ||
// For Node Emitters | ||
const serverN = require("net").createServer(8080); | ||
const onconnection = receptor.ConnectionListener(); | ||
serverN.on("connection", onconnection); | ||
// For Browser Emitters | ||
const serverB = require("http").createServer(8000); | ||
const onrequest = receptor.RequestMiddleware("foobar"); | ||
serverB.on("request", (request, response) => { | ||
onrequest(request, response, () => { | ||
// Request not handled by antena | ||
}); | ||
}); | ||
const onupgrade = receptor.UpgradeMiddleware("foobar"); | ||
serverB.on("upgrade", (request, socket, head) => { | ||
onupgrade(request, response, () => { | ||
// Upgrade not handled by Antena | ||
}); | ||
}); | ||
``` | ||
```js | ||
const AntenaEmitter = require("antena/emitter"); | ||
const session = "antena-rocks"; | ||
const emitter = AntenaEmitter(8080, session); // Node Emitter | ||
const emitter = AntenaBrowser("foobar", session); // Browser Emitter | ||
emitter.push("Hello"); | ||
@@ -28,41 +54,4 @@ emitter.onpush = (message) => { | ||
```js | ||
const server = require("net").createServer(); | ||
server.on("connection", receptor.ConnectionListener()); | ||
``` | ||
### `receptor = require("antena/receptor")()` | ||
```js | ||
const server = require("http").createServer(); | ||
const onrequest = receptor.RequestMiddleware(); | ||
server.on("request", (request, response) => { | ||
if (!onrequest(request, response)) { | ||
// handle request | ||
} | ||
}); | ||
const onupgrade = receptor.UpgradeMiddleware(); | ||
server.on("upgrade", (request, socket, head) => { | ||
if (!onupgrade(request, socket, head) { | ||
// handle upgrade | ||
} | ||
}); | ||
``` | ||
```js | ||
const server = require("http").createServer(); | ||
const onrequest = receptor.RequestMiddleware(); | ||
server.on("request", (request, response) => { | ||
onrequest(request, response, () => { | ||
// handle request | ||
}); | ||
}); | ||
const onupgrade = receptor.UpgradeMiddleware(); | ||
server.on("upgrade", (request, socket, head) => { | ||
onupgrade(request, socket, head, () => { | ||
// handle upgrade | ||
}); | ||
}); | ||
``` | ||
### receptor = require("antena/receptor")() | ||
Create a new receptor. | ||
@@ -72,5 +61,5 @@ | ||
### receptor.push(session, message); | ||
### `receptor.push(session, message)` | ||
Push a message to a emitter identified by its session. | ||
Push a message to an emitter identified by its session. | ||
@@ -81,3 +70,3 @@ * `receptor :: antena.Receptor` | ||
### receptor.onpush = (session, message) => { ... } | ||
### `receptor.onpush = (session, message) => { ... }` | ||
@@ -90,3 +79,3 @@ Handler for `emitter.push(message)`. | ||
### receptor.onpull = (session, query, callback) => { ... } | ||
### `receptor.onpull = (session, query, callback) => { ... }` | ||
@@ -101,3 +90,3 @@ Handler for `emitter.pull(message)`. | ||
### onconnection = receptor.ConnectionListener(); | ||
### `onconnection = receptor.ConnectionListener()` | ||
@@ -110,3 +99,3 @@ Create a listener for the `connection` event of a `net.Server`. | ||
### onrequest = receptor.RequestMiddleware([splitter]); | ||
### `onrequest = receptor.RequestMiddleware([splitter])` | ||
@@ -122,9 +111,9 @@ Create a middleware for the `request` event of a `http(s).Server`. | ||
* `next()`: | ||
If defined, this function will be called if the request was not handled by Antena. | ||
* `handled :: boolean` | ||
Indicate whether the request was handled by antena. | ||
Called if the request was not handled by Antena (if defined). | ||
* `handled :: boolean`: | ||
Indicates whether the request was handled by Antena. | ||
### onupgrade = receptor.UpgradeMiddleware([splitter]); | ||
### `onupgrade = receptor.UpgradeMiddleware([splitter])` | ||
Create middleware for the `upgrade` event of a `http(s).Server`. | ||
Create a middleware for the `upgrade` event of a `http(s).Server`. | ||
@@ -139,21 +128,23 @@ * `receptor :: antena.Receptor` | ||
* `next()`: | ||
If defined, this function will be called if the upgrade request was not handled by Antena. | ||
Called if the upgrade request was not handled by Antena (if defined). | ||
* `handled :: boolean` | ||
Indicate whether the request was handled by antena. | ||
Indicate whether the upgrade request was handled by Antena. | ||
## Emitter | ||
### emitter = require("antena/emitter")(address, session) | ||
### `emitter = require("antena/emitter")(address, session)` | ||
* `address :: object | string | number | antena.Receptor`: | ||
Antena will choose between the three mode below: | ||
* Browser: if `window` is defined | ||
* `string`, splitter; eg `"__antena__"` is an alias for `{splitter:"__antena__"}` | ||
* `object`, options: | ||
Antena will choose one of the below three mode: | ||
* If `window` is defined, Antena will perform a browser connection. | ||
The address should then be: | ||
* `object`: | ||
An option object with the following fields: | ||
* `secure :: boolean`, default: `location.protocol === "https:` | ||
* `hostname :: string`, default: `location.hostname` | ||
* `port :: number`, default: `location.port` | ||
* `splitter :: string`: default: `"__antena__"` | ||
* Node: if `window` is not defined and `address` is not an object | ||
* `number`, port number; eg `8080`: is an alias for `"[::1]:8080"` | ||
* `splitter :: string`, default: `"__antena__"` | ||
* `string`, alias for `{splitter:address}`. | ||
* Else, if `address` is not an object, Antena will perform a node connection. | ||
The address should then be: | ||
* `string` | ||
@@ -164,6 +155,8 @@ * Port string; eg `"8080"`: alias for `"[::1]:8080"` | ||
* IPv6 and port: eg `[::1]:8080` | ||
* Mock: if `window` is not defined and `address` is an object, address must be an `antena.Receptor` | ||
* `session :: string` | ||
* `number`, alias for `"[::1]:"+address` | ||
* Else, the address should be `antena.Receptor` and Antena will perform a local mock connection. | ||
* `session :: string`: | ||
All subsequent push/pull requests will be tagged with this string. | ||
### emitter.push(message) | ||
### `emitter.push(message)` | ||
@@ -175,3 +168,3 @@ Push a message to the emitter's receptor. | ||
### emitter.onpush = (message) => { ... } | ||
### `emitter.onpush = (message) => { ... }` | ||
@@ -183,3 +176,3 @@ Listen for pushes from the emitter's receptor. | ||
### result = emitter.pull(query) | ||
### `result = emitter.pull(query)` | ||
@@ -186,0 +179,0 @@ Pull a result from the emitter's receptor. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21115
433
173
Updatedws@^6.1.3