Commit 5bde9d73 authored by Felipe Pereira's avatar Felipe Pereira

Correcoes de bugs no professor

parent 10e2ed72
......@@ -62,6 +62,7 @@
<br><br>
<button type="submit" class="pure-button pure-button-primary" name='botao_submit' value='enviado' onClick="tentaLogar()";>Deslogar</button>
</div>
<center id='grafico'></center>
</div>
<!--*******************************************************************************************!-->
......
var socket = io("localhost:8081/");
var socket = io("https://stroop-node-brunomeyer1.c9users.io:8081/");
var login = null;
var senha = null;
......@@ -117,7 +117,6 @@ function abre_informacao_teste(obj){
Ex1 : Congruente 1
Ex2 : Incongruente 1*/
function plotaGraficoX(indice,idHTML){
var vetLinhas = [];
var j;
var auxVetY = [];
......@@ -146,8 +145,8 @@ function plotaGraficoX(indice,idHTML){
name: dados[i].nome
};
}
document.getElementById("grafico").innerHTML+=idHTML+"<br><div id='"+idHTML+"'></div>"
document.getElementById("grafico").innerHTML+=idHTML+"<br><html><div id='"+idHTML+"'></div></html>"
Plotly.newPlot(idHTML, vetLinhas);
vetLinhas = [];
auxVetY = [];
......@@ -157,6 +156,7 @@ function plotaGraficoX(indice,idHTML){
function geraGraficos(){
document.getElementById("grafico").innerHTML = "";
if(dados){
console.log(dados);
......@@ -180,126 +180,7 @@ function geraGraficos(){
}
//Criar uma funcao para criar cada teste
//~ for(var i = 0; i < dados.length; i++){
//~ vetLinhas[vetLinhas.length] = {
//~ x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
//~ y: buscaTempoResposta(dados[i].stringResposta[0]),
//~ type: 'scatter',
//~ mode:'lines+markers',
//~ name: dados[i].nome
//~ };
//~ for(j = 0; j < dados[i].stringResposta[0].length; j++){
//~ if(!dados[i].stringResposta[0][j].acertou){
//~ auxVetX[auxVetX.length] = j+1;
//~ auxVetY[auxVetY.length] = dados[i].stringResposta[0][j].tempo;
//~ }
//~ }
//~ vetLinhas[vetLinhas.length] = {
//~ x: auxVetX,
//~ y: auxVetY,
//~ type: 'scatter',
//~ mode:'markers',
//~ marker:{color:'rgb(200,20,20)'},
//~ name: dados[i].nome
//~ };
//~ }
//~
//~ document.getElementById("grafico").innerHTML+="Congruente 1<br><div id='congruente1'></div>"
//~ Plotly.newPlot('congruente1', vetLinhas);
//~ vetLinhas = [];
//~ auxVetY = [];
//~ auxVetX = [];
//~
//~ for(var i = 0; i < dados.length; i++){
//~ vetLinhas[vetLinhas.length] = {
//~ x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
//~ y: buscaTempoResposta(dados[i].stringResposta[1]),
//~ type: 'scatter',
//~ mode:'lines+markers',
//~ name: dados[i].nome
//~ };
//~ for(j = 0; j < dados[i].stringResposta[1].length; j++){
//~ if(!dados[i].stringResposta[1][j].acertou){
//~ auxVetX[auxVetX.length] = j+1;
//~ auxVetY[auxVetY.length] = dados[i].stringResposta[1][j].tempo;
//~ }
//~ }
//~ vetLinhas[vetLinhas.length] = {
//~ x: auxVetX,
//~ y: auxVetY,
//~ type: 'scatter',
//~ mode:'markers',
//~ marker:{color:'rgb(200,20,20)'},
//~ name: dados[i].nome
//~ };
//~ }
//~
//~ document.getElementById("grafico").innerHTML+="Congruente 2<br><div id='congruente2'> </div>"
//~ Plotly.newPlot('congruente2', vetLinhas);
//~ vetLinhas = [];
//~ auxVetY = [];
//~ auxVetX = [];
//~
//~ for(var i = 0; i < dados.length; i++){
//~ vetLinhas[vetLinhas.length] = {
//~ x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
//~ y: buscaTempoResposta(dados[i].stringResposta[2]),
//~ type: 'scatter',
//~ mode:'lines+markers',
//~ name: dados[i].nome
//~ };
//~ for(j = 0; j < dados[i].stringResposta[2].length; j++){
//~ if(!dados[i].stringResposta[2][j].acertou){
//~ auxVetX[auxVetX.length] = j+1;
//~ auxVetY[auxVetY.length] = dados[i].stringResposta[2][j].tempo;
//~ }
//~ }
//~ vetLinhas[vetLinhas.length] = {
//~ x: auxVetX,
//~ y: auxVetY,
//~ type: 'scatter',
//~ mode:'markers',
//~ marker:{color:'rgb(200,20,20)'},
//~ name: dados[i].nome
//~ };
//~ }
//~
//~ document.getElementById("grafico").innerHTML+="Incongruente 1<br><div id='incongruente1'> </div>"
//~ Plotly.newPlot('incongruente1', vetLinhas);
//~ vetLinhas = [];
//~ auxVetY = [];
//~ auxVetX = [];
//~
//~ for(var i = 0; i < dados.length; i++){
//~ vetLinhas[vetLinhas.length] = {
//~ x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
//~ y: buscaTempoResposta(dados[i].stringResposta[3]),
//~ type: 'scatter',
//~ mode:'lines+markers',
//~ name: dados[i].nome
//~ };
//~ for(j = 0; j < dados[i].stringResposta[3].length; j++){
//~ if(!dados[i].stringResposta[3][j].acertou){
//~ auxVetX[auxVetX.length] = j+1;
//~ auxVetY[auxVetY.length] = dados[i].stringResposta[3][j].tempo;
//~ }
//~ }
//~ vetLinhas[vetLinhas.length] = {
//~ x: auxVetX,
//~ y: auxVetY,
//~ type: 'scatter',
//~ mode:'markers',
//~ marker:{color:'rgb(200,20,20)'},
//~ name: dados[i].nome
//~ };
//~ }
//~ document.getElementById("grafico").innerHTML+="Incongruente 2<br><div id='incongruente2'> </div>"
//~ Plotly.newPlot('incongruente2', vetLinhas);
//~
}
}
......
var socket = io("localhost:8081/");
var socket = io("https://stroop-node-brunomeyer1.c9users.io:8081/");
function enviarDados(dados){
socket.emit("teste",data);
......
1.7.1 / 2016-11-28
===================
1.7.0 / 2016-11-27
===================
* [docs] Comment connected socket availability for adapters (#2081)
* [docs] Fixed grammar issues in the README.md (#2159)
* [feature] serve sourcemap for socket.io-client (#2482)
* [feature] Add a `local` flag (#2628)
* [chore] Bump engine.io to version 1.8.1 (#2765)
* [chore] Update client location and serve minified file (#2766)
1.6.0 / 2016-11-20
==================
* [fix] Make ETag header comply with standard. (#2603)
* [feature] Loading client script on demand. (#2567)
* [test] Fix leaking clientSocket (#2721)
* [feature] Add support for all event emitter methods (#2601)
* [chore] Update year to 2016 (#2456)
* [feature] Add support for socket middleware (#2306)
* [feature] add support for Server#close(callback) (#2748)
* [fix] Don't drop query variables on handshake (#2745)
* [example] Add disconnection/reconnection logs to the chat example (#2675)
* [perf] Minor code optimizations (#2219)
* [chore] Bump debug to version 2.3.3 (#2754)
* [chore] Bump engine.io to version 1.8.0 (#2755)
* [chore] Bump socket.io-adapter to version 0.5.0 (#2756)
1.5.1 / 2016-10-24
==================
......
(The MIT License)
Copyright (c) 2014-2015 Automattic <dev@cloudup.com>
Copyright (c) 2014-2016 Automattic <dev@cloudup.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
......
......@@ -147,7 +147,7 @@ server.listen(3000);
__Potential drawbacks__:
* in some situations, when it is not possible to determine `origin` it may have value of `*`
* As this function will be executed for every request, it is advised to make this function work as fast as possible
* If `socket.io` is used together with `Express`, the CORS headers will be affected only for `socket.io` requests. For Express can use [cors](https://github.com/expressjs/cors)
* If `socket.io` is used together with `Express`, the CORS headers will be affected only for `socket.io` requests. For Express can use [cors](https://github.com/expressjs/cors).
### Server#sockets:Namespace
......@@ -183,7 +183,7 @@ server.listen(3000);
Initializes and retrieves the given `Namespace` by its pathname
identifier `nsp`.
If the namespace was already initialized it returns it right away.
If the namespace was already initialized it returns it immediately.
### Server#emit
......@@ -198,9 +198,14 @@ server.listen(3000);
For other available methods, see `Namespace` below.
### Server#close
### Server#close([fn:Function])
Closes socket.io server
Closes socket.io server.
The optional `fn` is passed to the `server.close([callback])` method of the
core `net` module and is called on error or when all connections are closed.
The callback is expected to implement the common single argument `err`
signature (if any).
```js
var Server = require('socket.io');
......@@ -280,7 +285,7 @@ server.listen(3000);
### Namespace#use(fn:Function):Namespace
Registers a middleware, which is a function that gets executed for
every incoming `Socket` and receives as parameter the socket and a
every incoming `Socket`, and receives as parameters the socket and a
function to optionally defer execution to the next registered
middleware.
......@@ -304,6 +309,25 @@ server.listen(3000);
It should be noted the `Socket` doesn't relate directly to the actual
underlying TCP/IP `socket` and it is only the name of the class.
### Socket#use(fn:Function):Socket
Registers a middleware, which is a function that gets executed for
every incoming `Packet` and receives as parameter the packet and a
function to optionally defer execution to the next registered
middleware.
```js
var io = require('socket.io')();
io.on('connection', function(socket){
socket.use(function(packet, next){
if (packet.doge === true) return next();
next(new Error('Not a doge error'));
});
```
Errors passed to middleware callbacks are sent as special `error`
packets to clients.
### Socket#rooms:Object
A hash of strings identifying the rooms this client is in, indexed by
......@@ -424,7 +448,7 @@ These are reserved events (along with `connect`, `newListener` and `removeListen
### Client
The `Client` class represents an incoming transport (engine.io)
connection. A `Client` can be associated with many multiplexed `Socket`
connection. A `Client` can be associated with many multiplexed `Socket`s
that belong to different `Namespace`s.
### Client#conn
......
......@@ -9,6 +9,7 @@ var engine = require('engine.io');
var client = require('socket.io-client');
var clientVersion = require('socket.io-client/package').version;
var Client = require('./client');
var Emitter = require('events').EventEmitter;
var Namespace = require('./namespace');
var Adapter = require('socket.io-adapter');
var debug = require('debug')('socket.io:server');
......@@ -24,7 +25,8 @@ module.exports = Server;
* Socket.IO client source.
*/
var clientSource = read(require.resolve('socket.io-client/socket.io.js'), 'utf-8');
var clientSource = undefined;
var clientSourceMap = undefined;
/**
* Server constructor.
......@@ -94,6 +96,16 @@ Server.prototype.checkRequest = function(req, fn) {
Server.prototype.serveClient = function(v){
if (!arguments.length) return this._serveClient;
this._serveClient = v;
if (v && !clientSource) {
clientSource = read(require.resolve('socket.io-client/dist/socket.io.min.js'), 'utf-8');
try {
clientSourceMap = read(require.resolve('socket.io-client/dist/socket.io.js.map'), 'utf-8');
} catch(err) {
debug('could not load sourcemap file');
}
}
return this;
};
......@@ -249,11 +261,14 @@ Server.prototype.attach = function(srv, opts){
Server.prototype.attachServe = function(srv){
debug('attaching client serving req handler');
var url = this._path + '/socket.io.js';
var urlMap = this._path + '/socket.io.js.map';
var evs = srv.listeners('request').slice(0);
var self = this;
srv.removeAllListeners('request');
srv.on('request', function(req, res) {
if (0 === req.url.indexOf(url)) {
if (0 === req.url.indexOf(urlMap)) {
self.serveMap(req, res);
} else if (0 === req.url.indexOf(url)) {
self.serve(req, res);
} else {
for (var i = 0; i < evs.length; i++) {
......@@ -272,9 +287,13 @@ Server.prototype.attachServe = function(srv){
*/
Server.prototype.serve = function(req, res){
// Per the standard, ETags must be quoted:
// https://tools.ietf.org/html/rfc7232#section-2.3
var expectedEtag = '"' + clientVersion + '"';
var etag = req.headers['if-none-match'];
if (etag) {
if (clientVersion == etag) {
if (expectedEtag == etag) {
debug('serve client 304');
res.writeHead(304);
res.end();
......@@ -284,11 +303,42 @@ Server.prototype.serve = function(req, res){
debug('serve client source');
res.setHeader('Content-Type', 'application/javascript');
res.setHeader('ETag', clientVersion);
res.setHeader('ETag', expectedEtag);
res.setHeader('X-SourceMap', 'socket.io.js.map');
res.writeHead(200);
res.end(clientSource);
};
/**
* Handles a request serving `/socket.io.js.map`
*
* @param {http.Request} req
* @param {http.Response} res
* @api private
*/
Server.prototype.serveMap = function(req, res){
// Per the standard, ETags must be quoted:
// https://tools.ietf.org/html/rfc7232#section-2.3
var expectedEtag = '"' + clientVersion + '"';
var etag = req.headers['if-none-match'];
if (etag) {
if (expectedEtag == etag) {
debug('serve client 304');
res.writeHead(304);
res.end();
return;
}
}
debug('serve client sourcemap');
res.setHeader('Content-Type', 'application/json');
res.setHeader('ETag', expectedEtag);
res.writeHead(200);
res.end(clientSourceMap);
};
/**
* Binds socket.io to an engine.io instance.
*
......@@ -342,10 +392,11 @@ Server.prototype.of = function(name, fn){
/**
* Closes server connection
*
* @param {Function} [fn] optional, called as `fn([err])` on error OR all conns closed
* @api public
*/
Server.prototype.close = function(){
Server.prototype.close = function(fn){
for (var id in this.nsps['/'].sockets) {
if (this.nsps['/'].sockets.hasOwnProperty(id)) {
this.nsps['/'].sockets[id].onclose();
......@@ -354,8 +405,10 @@ Server.prototype.close = function(){
this.engine.close();
if(this.httpServer){
this.httpServer.close();
if (this.httpServer) {
this.httpServer.close(fn);
} else {
fn && fn();
}
};
......@@ -363,18 +416,23 @@ Server.prototype.close = function(){
* Expose main namespace (/).
*/
['on', 'to', 'in', 'use', 'emit', 'send', 'write', 'clients', 'compress'].forEach(function(fn){
var emitterMethods = Object.keys(Emitter.prototype).filter(function(key){
return typeof Emitter.prototype[key] === 'function';
});
emitterMethods.concat(['to', 'in', 'use', 'send', 'write', 'clients', 'compress']).forEach(function(fn){
Server.prototype[fn] = function(){
var nsp = this.sockets[fn];
return nsp.apply(this.sockets, arguments);
return this.sockets[fn].apply(this.sockets, arguments);
};
});
Namespace.flags.forEach(function(flag){
Server.prototype.__defineGetter__(flag, function(){
this.sockets.flags = this.sockets.flags || {};
this.sockets.flags[flag] = true;
return this;
Object.defineProperty(Server.prototype, flag, {
get: function() {
this.sockets.flags = this.sockets.flags || {};
this.sockets.flags[flag] = true;
return this;
}
});
});
......
......@@ -31,7 +31,8 @@ exports.events = [
exports.flags = [
'json',
'volatile'
'volatile',
'local'
];
/**
......@@ -69,10 +70,12 @@ Namespace.prototype.__proto__ = Emitter.prototype;
*/
exports.flags.forEach(function(flag){
Namespace.prototype.__defineGetter__(flag, function(){
this.flags = this.flags || {};
this.flags[flag] = true;
return this;
Object.defineProperty(Namespace.prototype, flag, {
get: function() {
this.flags = this.flags || {};
this.flags[flag] = true;
return this;
}
});
});
......@@ -137,7 +140,7 @@ Namespace.prototype.run = function(socket, fn){
*/
Namespace.prototype.to =
Namespace.prototype['in'] = function(name){
Namespace.prototype.in = function(name){
this.rooms = this.rooms || [];
if (!~this.rooms.indexOf(name)) this.rooms.push(name);
return this;
......
......@@ -8,6 +8,7 @@ var parser = require('socket.io-parser');
var url = require('url');
var debug = require('debug')('socket.io:socket');
var hasBin = require('has-binary');
var assign = require('object-assign');
/**
* Module exports.
......@@ -68,6 +69,7 @@ function Socket(nsp, client, query){
this.connected = true;
this.disconnected = false;
this.handshake = this.buildHandshake(query);
this.fns = [];
}
/**
......@@ -81,10 +83,12 @@ Socket.prototype.__proto__ = Emitter.prototype;
*/
flags.forEach(function(flag){
Socket.prototype.__defineGetter__(flag, function(){
this.flags = this.flags || {};
this.flags[flag] = true;
return this;
Object.defineProperty(Socket.prototype, flag, {
get: function() {
this.flags = this.flags || {};
this.flags[flag] = true;
return this;
}
});
});
......@@ -94,8 +98,10 @@ flags.forEach(function(flag){
* @api public
*/
Socket.prototype.__defineGetter__('request', function(){
return this.conn.request;
Object.defineProperty(Socket.prototype, 'request', {
get: function() {
return this.conn.request;
}
});
/**
......@@ -109,13 +115,7 @@ Socket.prototype.buildHandshake = function(query){
function buildQuery(){
var requestQuery = url.parse(self.request.url, true).query;
//if socket-specific query exist, replace query strings in requestQuery
if(query){
query.t = requestQuery.t;
query.EIO = requestQuery.EIO;
query.transport = requestQuery.transport;
return query;
}
return requestQuery || {};
return assign({}, query, requestQuery);
}
return {
headers: this.request.headers,
......@@ -283,6 +283,8 @@ Socket.prototype.leaveAll = function(){
/**
* Called by `Namespace` upon successful
* middleware execution (ie: authorization).
* Socket is added to namespace array before
* call to join, so adapters can access it.
*
* @api private
*/
......@@ -345,7 +347,7 @@ Socket.prototype.onevent = function(packet){
args.push(this.ack(packet.id));
}
emit.apply(this, args);
this.dispatch(args);
};
/**
......@@ -482,3 +484,63 @@ Socket.prototype.compress = function(compress){
this.flags.compress = compress;
return this;
};
/**
* Dispatch incoming event to socket listeners.
*
* @param {Array} event that will get emitted
* @api private
*/
Socket.prototype.dispatch = function(event){
debug('dispatching an event %j', event);
var self = this;
this.run(event, function(err){
process.nextTick(function(){
if (err) {
return self.emit('error', err.data || err.message);
}
emit.apply(self, event);
});
});
}
/**
* Sets up socket middleware.
*
* @param {Function} middleware function (event, next)
* @return {Socket} self
* @api public
*/
Socket.prototype.use = function(fn){
this.fns.push(fn);
return this;
};
/**
* Executes the middleware for an incoming event.
*
* @param {Array} event that will get emitted
* @param {Function} last fn call in the middleware
* @api private
*/
Socket.prototype.run = function(event, fn){
var fns = this.fns.slice(0);
if (!fns.length) return fn(null);
function run(i){
fns[i](event, function(err){
// upon error, short-circuit
if (err) return fn(err);
// if no middleware left, summon callback
if (!fns[i + 1]) return fn(null);
// go on to next
run(i + 1);
});
}
run(0);
};