noice-json-rpc
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -150,7 +150,13 @@ "use strict"; | ||
} | ||
else if (prop.substr(0, 2) === 'on' && prop.length > 3) { | ||
else if (prop === 'on') { | ||
target[prop] = (method, handler) => this.on(`${prefix}${method}`, handler); | ||
} | ||
else if (prop === 'emit') { | ||
target[prop] = (method, params) => this.notify(`${prefix}${method}`, params); | ||
} | ||
else if (prop.substr(0, 2) === 'on' && prop.length > 3) { // TODO: deprecate this | ||
const method = prop[2].toLowerCase() + prop.substr(3); | ||
target[prop] = (handler) => this.on(`${prefix}${method}`, handler); | ||
} | ||
else if (prop.substr(0, 4) === 'emit' && prop.length > 5) { | ||
else if (prop.substr(0, 4) === 'emit' && prop.length > 5) { // TODO: deprecate this | ||
const method = prop[4].toLowerCase() + prop.substr(5); | ||
@@ -321,7 +327,13 @@ target[prop] = (params) => this.notify(`${prefix}${method}`, params); | ||
} | ||
else if (prop.substr(0, 2) === 'on' && prop.length > 3) { | ||
else if (prop === 'on') { | ||
target[prop] = (method, handler) => this.on(`${prefix}${method}`, handler); | ||
} | ||
else if (prop === 'emit') { | ||
target[prop] = (method, params) => this.notify(`${prefix}${method}`, params); | ||
} | ||
else if (prop.substr(0, 2) === 'on' && prop.length > 3) { // TODO deprecate this | ||
const method = prop[2].toLowerCase() + prop.substr(3); | ||
target[prop] = (handler) => this.on(`${prefix}${method}`, handler); | ||
} | ||
else if (prop.substr(0, 4) === 'emit' && prop.length > 5) { | ||
else if (prop.substr(0, 4) === 'emit' && prop.length > 5) { // TODO deprecate this | ||
const method = prop[4].toLowerCase() + prop.substr(5); | ||
@@ -328,0 +340,0 @@ target[prop] = (params) => this.notify(`${prefix}${method}`, params); |
{ | ||
"name": "noice-json-rpc", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Noice Json RPC exposes a clean ES6 Proxy and Promise based interface for JSON-RPC2 Clients and Servers", | ||
@@ -50,2 +50,3 @@ "main": "lib/noice-json-rpc.js", | ||
"chrome-remote-debug-protocol": "^1.0.1", | ||
"devtools-protocol": "0.0.555290", | ||
"coveralls": "^2.11.11", | ||
@@ -52,0 +53,0 @@ "istanbul": "^0.4.5", |
@@ -11,7 +11,7 @@ # Noice Json Rpc | ||
Noice Json Rpc takes in a websocket like object. It calls `send(msg:str)` function and expects messages to come from `on('message', handler)`. It works out of the box with WebSockets but it can also work with stdin/stdout, worker threads, iframes or any other mechanism in which strings can be sent or received. | ||
Noice Json Rpc takes in a websocket like object. It calls `send(msg:str)` function and expects messages to come from `on('message', handler)`. It works out of the box with WebSockets but it can also work with stdin/stdout, worker threads, iframes or any other mechanism in which strings can be sent or received. | ||
Its only dependency is `events.EventEmitter`. | ||
Using ES6 proxies it exposes a clean client-server api. Since its written in TypeScript, the api object can be cast to work off an interface specific to the domain. e.g [chrome-remote-debug-protocol](https://github.com/nojvek/chrome-remote-debug-protocol) | ||
Using ES6 proxies it exposes a clean client-server api. Since its written in TypeScript, the api object can be cast to work off an interface specific to the domain. e.g [ChromeDevTools/devtools-protocol](https://github.com/ChromeDevTools/devtools-protocol/blob/master/types/protocol.d.ts) | ||
@@ -22,20 +22,22 @@ ## [Example](tests/example.ts) | ||
import * as WebSocket from 'ws' | ||
import WebSocketServer = WebSocket.Server | ||
import * as rpc from 'noice-json-rpc' | ||
import DevToolsProtocol from 'devtools-protocol' | ||
import * as rpc from '../lib/noice-json-rpc' | ||
async function setupClient() { | ||
try { | ||
const api = new rpc.Client(new WebSocket("ws://localhost:8080"), {logConsole: true}).api() | ||
const rpcClient = new rpc.Client(new WebSocket('ws://localhost:8080'), {logConsole: true}) | ||
const api: DevToolsProtocol.ProtocolApi = rpcClient.api() | ||
await Promise.all([ | ||
api.Runtime.enable(), | ||
api.Debugger.enable(), | ||
api.Profiler.enable(), | ||
api.Runtime.run(), | ||
]) | ||
await api.Runtime.run() | ||
await api.Profiler.start() | ||
await new Promise((resolve) => api.Runtime.onExecutionContextDestroyed(resolve)); // Wait for event | ||
await api.Profiler.stop() | ||
await new Promise(resolve => api.Runtime.on('executionContextDestroyed', resolve)); // Wait for event | ||
const result = await api.Profiler.stop() | ||
console.log('Result', result) | ||
} catch (e) { | ||
@@ -46,29 +48,2 @@ console.error(e) | ||
function setupServer() { | ||
const wssServer = new WebSocketServer({port: 8080}); | ||
const api = new rpc.Server(wssServer).api(); | ||
const enable = () => {} | ||
api.Debugger.expose({enable}) | ||
api.Profiler.expose({enable}) | ||
api.Runtime.expose({ | ||
enable, | ||
run() {} | ||
}) | ||
api.Profiler.expose({ | ||
enable, | ||
start() { | ||
setTimeout(() => { | ||
api.Runtime.emitExecutionContextDestroyed() | ||
}, 1000) | ||
}, | ||
stop() { | ||
return {data: "noice!"} | ||
} | ||
}) | ||
} | ||
setupServer() | ||
setupClient() | ||
@@ -81,3 +56,2 @@ ``` | ||
Client > {"id":1,"method":"Runtime.enable"} | ||
Client > {"id":2,"method":"Debugger.enable"} | ||
Client > {"id":3,"method":"Profiler.enable"} | ||
@@ -84,0 +58,0 @@ Client > {"id":4,"method":"Runtime.run"} |
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
28471
546
15
65