-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
47 lines (39 loc) · 1.12 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Include the manager
var HubManager = require('./index.js');
// Create an instance that will listen on the port 1883
var hm = new HubManager(1883, 27017);
/**
* Authentication callback
* @return true to accept the client connection, false otherwise
*/
var auth_conn = function (client, username, password) {
// check the database...
// if (client == 'guy') ...
// password.toString() might be needed as well if compared to a db result
return true;
}
/**
* Subscription accept callback
* @return true to allow the client to subscribe on this topic, false otherwise
*/
var auth_subs = function (client, topic) {
return true;
}
/**
* Publish accept callback
* @return true to allow the client to publish to a topic, false otherwise
*/
var auth_publ = function (client, topic, payload) {
return true
}
// Set the connection / sub / pub accept callbacks
hm.authorizeClientConnection(auth_conn);
hm.authorizeClientSubscription(auth_subs);
hm.authorizeClientPublish(auth_publ);
// Add a ready callback
hm.onServerReady(function() {
console.log('Server is ready yeah');
})
// Setup the MQTT broker
hm.setup();
// ...