I am attempting to create a HTML5 / JS app and use an Azure Mobile Service for my backend.
Based on ScottGu's post where he demonstrates source control and npm module support, I am wondering if it possible to use socket.io to enable realtime notifications and the use of WebSockets.
I can see how one may be able to bring in the module and make use of it for each specific request (e.g. when a client POSTS to a resource, add a hook to broadcast the resource's creation to all clients) but I am unsure how to set up and share the socket.io object.
NB. I am aware of the built-in support for push based notifications for iOS, Windows, and Google but it doesn't (yet) provide an out of the box solution for web based projects - hence wanting to use socket.io (or any SignalR-esque equivalent).
WebSocket should be fine on Azure Mobile Services, because it is just "downgrading" a HTTP connection back to a Socket with framing (more like reliable UDP). But there are few caveats:
I would rather setup a different set of machines dedicated for Socket.IO server so it don't fail on browsers/proxies that doesn't support WebSocket. Then when someone POST to API on Azure Mobile Services, the API will queue a message to a message queue and signal all your Socket.IO servers to broadcast the message.
Support for Socket.IO has been added using startup script extension
var path = require('path');
exports.startup = function (context, done) {
var io = require('socket.io')(context.app.server);
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});
context.app.get('/public/chat.html', function(req, res) {
res.sendfile(path.resolve(__dirname, '../public/chat.html'));
});
done();
}
For details see: http://azure.microsoft.com/blog/2014/08/26/how-to-use-socket-io-with-azure-mobile-service-node-backend/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With