Skip to content

Commit dad9730

Browse files
committed
trigger can be called with no socketID. Fixes #37.
If the 'socketId' is a function, treat it as a callback instead. This means that you can call `trigger` and avoid passing `null, fn(..) {}` at the end.
1 parent f2e3d12 commit dad9730

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lib/pusher.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ Pusher.prototype.authenticate = function(socketId, channel, data) {
119119
* @see RequestError
120120
*/
121121
Pusher.prototype.trigger = function(channels, event, data, socketId, callback) {
122+
if (typeof socketId === "function") {
123+
callback = socketId;
124+
socketId = undefined;
125+
}
126+
122127
if (socketId) {
123128
validateSocketId(socketId);
124129
}

tests/integration/pusher/trigger.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("Pusher", function() {
5151
)
5252
.reply(200, "{}");
5353

54-
pusher.trigger("one", "my_event", { some: "data "}, null, done);
54+
pusher.trigger("one", "my_event", { some: "data "}, done);
5555
});
5656

5757
it("should send the event to multiple channels", function(done) {
@@ -67,7 +67,7 @@ describe("Pusher", function() {
6767
)
6868
.reply(200, "{}");
6969

70-
pusher.trigger(["one", "two", "three"], "my_event", { some: "data "}, null, done);
70+
pusher.trigger(["one", "two", "three"], "my_event", { some: "data "}, done);
7171
});
7272

7373
it("should serialize arrays into JSON", function(done) {
@@ -83,7 +83,7 @@ describe("Pusher", function() {
8383
)
8484
.reply(200, "{}");
8585

86-
pusher.trigger("one", "my_event", [1,2,4], null, done);
86+
pusher.trigger("one", "my_event", [1,2,4], done);
8787
});
8888

8989
it("should not serialize strings into JSON", function(done) {
@@ -99,7 +99,7 @@ describe("Pusher", function() {
9999
)
100100
.reply(200, "{}");
101101

102-
pusher.trigger("test", "test_event", "test string", null, done);
102+
pusher.trigger("test", "test_event", "test string", done);
103103
});
104104

105105
it("should add socket_id to the request body", function(done) {
@@ -131,7 +131,7 @@ describe("Pusher", function() {
131131
)
132132
.reply(200, "OK");
133133

134-
pusher.trigger("test_channel", "my_event", { some: "data "}, null, function(error, request, response) {
134+
pusher.trigger("test_channel", "my_event", { some: "data "}, function(error, request, response) {
135135
expect(error).to.be(null);
136136
expect(response.statusCode).to.equal(200);
137137
done();
@@ -151,7 +151,7 @@ describe("Pusher", function() {
151151
)
152152
.reply(400, "Error");
153153

154-
pusher.trigger("test_channel", "my_event", { some: "data "}, null, function(error, request, response) {
154+
pusher.trigger("test_channel", "my_event", { some: "data "}, function(error, request, response) {
155155
expect(error).to.be.a(Pusher.RequestError);
156156
expect(error.message).to.equal("Unexpected status code 400");
157157
expect(error.url).to.match(
@@ -176,7 +176,7 @@ describe("Pusher", function() {
176176
)
177177
.reply(200, "OK");
178178

179-
pusher.trigger("test_-=@,.;channel", "my_event", { some: "data "}, null, function(error, request, response) {
179+
pusher.trigger("test_-=@,.;channel", "my_event", { some: "data "}, function(error, request, response) {
180180
expect(error).to.be(null);
181181
expect(response.statusCode).to.equal(200);
182182
done();

0 commit comments

Comments
 (0)