Skip to content

Commit

Permalink
feat('player'): emit 'message-processed' after a Table Manager messag…
Browse files Browse the repository at this point in the history
…e is processed
  • Loading branch information
richardschneider committed Oct 16, 2016
1 parent 395ac40 commit 414f223
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -102,10 +102,16 @@ Emitted when the player needs to play a card from dummy. `player.playFromDummy(

#### Event 'message'

* Table Manager messagee without the trailing CRLF
* Table Manager message without the trailing CRLF

Emitted when a Table Manager message is received.

#### Event 'message-processed'

* Table Manager message without the trailing CRLF

Emitted after a Table Manager message is processed.

#### Event 'sent'

* Table Manager message without the trailing CRLF
Expand Down
6 changes: 6 additions & 0 deletions lib/player.js
Expand Up @@ -238,9 +238,15 @@ BridgePlayer.prototype.connect = function connect(table) {
this.send(`${this.seat.name} ready for ${this.game.contract.leader()}'s card to trick 1`);
}
})

// Misc.
.on('endOfSession', () => this.state = 'done')
.on('data', m => self.emit('message-processed', m))
;
this.state = 'connecting';
this.send(`connecting "${this.teamName}" as ${this.seat.name} using protocol version 18`);

return this;
};

module.exports = BridgePlayer;
17 changes: 17 additions & 0 deletions test/player.js
Expand Up @@ -70,4 +70,21 @@ describe('Bridge Player', () => {
.connect(table);
});

it('should emit "message-processed" event', done => {
let messageSeen = false,
table = new TestTable();
let player = new Player()
.on('end', () => {
messageSeen.should.equal(true);
done();
})
.on('error', done)
.on('message-processed', () => {
player.state.should.equal('done');
messageSeen = true;
})
.connect(table);
});


});

0 comments on commit 414f223

Please sign in to comment.