-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (26 loc) · 913 Bytes
/
app.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
var path = require('path'),
util = require('util'),
config = require('./config'),
azure = require('azure'),
http = require('http'),
express = require('express'),
app = express(),
WebSocketServer = require('ws').Server;
app.use(express.static(__dirname + '/public'));
var server = http.createServer(app);
//server.listen(process.env.PORT);
server.listen(9999);
var wss = new WebSocketServer({server: server});
var serviceBusService = azure.createServiceBusService(config.sbConnectionString);
wss.on('connection', function(ws) {
console.log("New connection to WS");
var loop = setInterval(function() {
serviceBusService.receiveSubscriptionMessage(config.sbTopic, config.sbSubscription, function(error, receivedMessage) {
if(!error) {
ws.send(new Buffer(receivedMessage.body, "base64"));
} else {
console.log("Error: " + error);
}
});
}, 500);
});