Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "standard",
"parser": "babel-eslint",
"rules": {
"yoda": 0,
"semi": [2, "always"],
"no-extra-semi": 2,
"semi-spacing": [2, { "before": false, "after": true }]
}
}
20 changes: 10 additions & 10 deletions examples/latency/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
* Module dependencies.
*/

var express = require('express')
, app = express()
, server = require('http').createServer(app)
, enchilada = require('enchilada')
, io = require('engine.io').attach(server);
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var enchilada = require('enchilada');
var io = require('engine.io').attach(server);

app.use(enchilada({
src: __dirname + '/public',
debug: true
}));
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res, next){
app.get('/', function (req, res, next) {
res.sendfile('index.html');
});

io.on('connection', function(socket){
socket.on('message', function(v){
io.on('connection', function (socket) {
socket.on('message', function (v) {
socket.send('pong');
});
});

var port = process.env.PORT || 3000;
server.listen(port, function(){
console.log('\033[96mlistening on localhost:' + port + ' \033[39m');
server.listen(port, function () {
console.log('\x1B[96mlistening on localhost:' + port + ' \x1B[39m');
});
25 changes: 12 additions & 13 deletions examples/latency/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
* Module dependencies.
*/

var SmoothieChart = require("smoothie").SmoothieChart
, TimeSeries = require("smoothie").TimeSeries
, eio = require("engine.io-client");

var SmoothieChart = require('smoothie').SmoothieChart;
var TimeSeries = require('smoothie').TimeSeries;
var eio = require('engine.io-client');

// helper

function $(id){ return document.getElementById(id); }
function $ (id) { return document.getElementById(id); }

// chart

var smoothie;
var time;

function render(){
function render () {
if (smoothie) smoothie.stop();
$('chart').width = document.body.clientWidth;
smoothie = new SmoothieChart();
Expand All @@ -33,25 +32,25 @@ function render(){
// socket
var socket = new eio.Socket();
var last;
function send(){
last = new Date;
function send () {
last = new Date();
socket.send('ping');
$('transport').innerHTML = socket.transport.name;
}
socket.on('open', function(){
socket.on('open', function () {
if ($('chart').getContext) {
render();
window.onresize = render;
}
send();
});
socket.on('close', function(){
socket.on('close', function () {
if (smoothie) smoothie.stop();
$('transport').innerHTML = '(disconnected)';
});
socket.on('message', function(){
var latency = new Date - last;
socket.on('message', function () {
var latency = new Date() - last;
$('latency').innerHTML = latency + 'ms';
if (time) time.append(+new Date, latency);
if (time) time.append(+new Date(), latency);
setTimeout(send, 100);
});
41 changes: 27 additions & 14 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var babel = require("gulp-babel");
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const babel = require('gulp-babel');
const eslint = require('gulp-eslint');

var TESTS = 'test/*.js';
var REPORTER = 'dot';
const TESTS = 'test/*.js';
const REPORTER = 'dot';

gulp.task("default", ["transpile"]);
gulp.task('default', ['transpile']);

gulp.task('test', function(){
return gulp.src(TESTS, {read: false})
gulp.task('test', ['lint'], function () {
return gulp.src(TESTS, {read: false})
.pipe(mocha({
slow: 500,
reporter: REPORTER,
bail: true
}))
.once('error', function(){
.once('error', function (err) {
console.error(err.stack);
process.exit(1);
})
.once('end', function(){
.once('end', function () {
process.exit();
});
});

gulp.task('lint', function () {
return gulp.src([
'**/*.js',
'!node_modules/**',
'!coverage/**'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

// By default, individual js files are transformed by babel and exported to /dist
gulp.task("transpile", function(){
return gulp.src(["lib/*.js","lib/transports/*.js"], { base: 'lib' })
.pipe(babel({ "presets": ["es2015"] }))
.pipe(gulp.dest("dist"));
gulp.task('transpile', function () {
return gulp.src(['lib/**/*.js'], { base: 'lib' })
.pipe(babel({ 'presets': ['es2015'] }))
.pipe(gulp.dest('dist'));
});
12 changes: 6 additions & 6 deletions lib/engine.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var http = require('http');
* @api public
*/

exports = module.exports = function() {
exports = module.exports = function () {
// backwards compatible use as `.attach`
// if first argument is an http server
if (arguments.length && arguments[0] instanceof http.Server) {
Expand Down Expand Up @@ -88,8 +88,8 @@ exports.parser = require('engine.io-parser');

exports.listen = listen;

function listen(port, options, fn) {
if ('function' == typeof options) {
function listen (port, options, fn) {
if ('function' === typeof options) {
fn = options;
options = {};
}
Expand All @@ -106,7 +106,7 @@ function listen(port, options, fn) {
engine.httpServer = server;

return engine;
};
}

/**
* Captures upgrade requests for a http.Server.
Expand All @@ -119,8 +119,8 @@ function listen(port, options, fn) {

exports.attach = attach;

function attach(server, options) {
function attach (server, options) {
var engine = new exports.Server(options);
engine.attach(server, options);
return engine;
};
}
Loading