@steelbreeze/broker
Advanced tools
Comparing version 1.0.0-beta.5 to 1.0.0-beta.6
@@ -15,6 +15,11 @@ const broker = require('../lib/index'); // replace with @steelbreeze/broker | ||
// publish a message on the devices topic of the /events broker every second | ||
setInterval( () => { | ||
var timer = setInterval( () => { | ||
client.publish('devices', `Hello at ${new Date()}`); | ||
client.publish('device/1/2/3', `Hello at ${new Date()}`); | ||
}, 1000); | ||
client.publish('device/1/2/3', `Hello at ${new Date()}`, cancelTimer); | ||
}, 1000); | ||
function cancelTimer() { | ||
console.log("Unable to connect"); | ||
} |
@@ -11,5 +11,5 @@ /** Specifies the location of a message broker server. */ | ||
export declare function client(config: HTTPConfig): { | ||
publish: (topicName: string, data: string) => void; | ||
publish: (topicName: string, data: string, onError: ((err: Error) => void) | undefined) => void; | ||
subscribe: (topicName: string, callback: (data: string) => void) => void; | ||
}; | ||
export {}; |
@@ -18,4 +18,5 @@ "use strict"; | ||
*/ | ||
function publish(topicName, data) { | ||
function publish(topicName, data, onError) { | ||
var post = http.request({ hostname: config.host, port: config.port, path: config.path + "/" + topicName, method: 'POST', headers: { 'Content-Type': 'text/plain', 'Content-Length': Buffer.byteLength(data) } }); | ||
post.on('error', onError || (function () { })); | ||
post.write(data); | ||
@@ -22,0 +23,0 @@ post.end(); |
{ | ||
"name": "@steelbreeze/broker", | ||
"version": "1.0.0-beta.5", | ||
"version": "1.0.0-beta.6", | ||
"description": "Lightweight publish and subscribe using Server-Sent Events for node and express", | ||
@@ -33,5 +33,6 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/node": "^10.5.1", | ||
"@types/express": "^4.16.0", | ||
"express": "^4.16.3" | ||
} | ||
} | ||
} |
@@ -22,5 +22,6 @@ import * as http from 'http'; | ||
*/ | ||
function publish(topicName: string, data: string): void { | ||
function publish(topicName: string, data: string, onError: ((err: Error) => void) | undefined): void { | ||
var post = http.request({ hostname: config.host, port: config.port, path: `${config.path}/${topicName}`, method: 'POST', headers: { 'Content-Type': 'text/plain', 'Content-Length': Buffer.byteLength(data) } }); | ||
post.on('error', onError || (() => { })); | ||
post.write(data); | ||
@@ -27,0 +28,0 @@ post.end(); |
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
21742
349
3