Skip to content

Commit

Permalink
added begin event
Browse files Browse the repository at this point in the history
vstirbu committed Feb 23, 2015
1 parent 8a6fb88 commit aff69b3
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/server/cloak/index.js
Original file line number Diff line number Diff line change
@@ -125,6 +125,9 @@ module.exports = (function() {
if (config.autoJoinLobby) {
lobby.addMember(user);
}
if (config.clientEvents && config.clientEvents.begin) {
config.clientEvents.begin(user);
}
});

socket.on('cloak-resume', function(data) {
20 changes: 16 additions & 4 deletions test/clientEvents.js
Original file line number Diff line number Diff line change
@@ -10,29 +10,41 @@ module.exports = _.extend(suite, {

clientEvents: function(test) {

test.expect(4);
test.expect(8);

var server = this.server;
var client = suite.createClient();
var detected;
var eventsOrder = [];
var currentUser;

server.configure({
port: this.port,
clientEvents: {
begin: function (user) {
currentUser = user.id;
eventsOrder.push('begin');
test.ok(true, 'begin event happened');
},
disconnect: function (user) {
if (!detected) {
eventsOrder.push('disconnect');
test.ok(true, 'disconnect event happened');
test.equal(user.id, client.currentUser());
test.equal(user.id, currentUser);
client._connect();
detected = true;
}
},
resume: function (user) {
test.ok(true, 'resume event happened');
eventsOrder.push('resume');
test.equal(user.id, client.currentUser());
setTimeout(function () {
test.done();
});
test.equal(user.id, currentUser);
test.deepEqual(eventsOrder, ['begin', 'disconnect', 'resume']);
setTimeout(function () {
test.done();
});
}
}
});

0 comments on commit aff69b3

Please sign in to comment.