microscope-ws

0.2.0 • Public • Published

microscope-ws

microscope websocket WsApplication class and Hubs

WsApplication

Sample (Application.js):

Define basic WsApplication class.

 
// Imports
var WsApplication = require('../libs/WsApplication');
 
// WsApplication class
var Application = WsApplication.extend({
    appRoot: __dirname,
    initialize: function () {}
});
 
module.exports = Application;
 

Sample (./bin/www):

Run basic http server and instantiate WsApplication with server in constructor param

 
// Imports
var fs          = require('fs');
var path        = require('path');
var http        = require('http');
var Application = require('../Application');
 
// create simple http server and serve html file.
var server = http.createServer(function (request, response) {
    var filePath = path.join(__dirname + '/../index.html');
    fs.readFile(filePath, function (err, html) {
        if (err) { throw err; }
        response.writeHeader(200, {"Content-Type": "text/html"});  
        response.write(html);  
        response.end();  
    });
});
 
// create microscope WsApplication attach to server
var application = new Application({ server: server });
 
//run server
server.listen(3000);
 

Package Sidebar

Install

npm i microscope-ws

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • bhtz