Skip to content

Commit

Permalink
Pass socket to onMessage
Browse files Browse the repository at this point in the history
Some sort of state mechanism needed to be passed to this method, otherwise its usefulness is limited.
  • Loading branch information
kpdecker committed Sep 5, 2015
1 parent 54dbbde commit 02bdd44
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/listener.js
Expand Up @@ -69,7 +69,7 @@ internals.Listener.prototype._add = function (ws) {
socket.authenticate(function () {

if (self._settings.onConnect) {
self._settings.onConnect(ws);
self._settings.onConnect(socket);
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion lib/socket.js
Expand Up @@ -262,7 +262,7 @@ internals.Socket.prototype._processMessage = function (request) {
id: request.id
};

self._listener._settings.onMessage(request.data, function (data) {
self._listener._settings.onMessage(self, request.data, function (data) {

if (data instanceof Error) {
response.error = data.message;
Expand Down
4 changes: 2 additions & 2 deletions test/socket.js
Expand Up @@ -503,7 +503,7 @@ describe('Socket', function () {

it('calls onMessage callback', function (done) {

var onMessage = function (message, reply) {
var onMessage = function (socket, message, reply) {

expect(message).to.equal('winning');
reply('hello');
Expand Down Expand Up @@ -536,7 +536,7 @@ describe('Socket', function () {

var client;

var onMessage = function (message, reply) {
var onMessage = function (socket, message, reply) {

expect(message).to.equal('winning');
reply(new Error('failed'));
Expand Down

0 comments on commit 02bdd44

Please sign in to comment.