pusher-js 7.4.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/PULL_REQUEST_TEMPLATE.md +4 -0
- package/.github/workflows/release_pr.yml +4 -3
- package/CHANGELOG.md +12 -2
- package/README.md +1 -1
- package/dist/node/pusher.js +82 -27
- package/dist/node/pusher.js.map +1 -1
- package/dist/react-native/pusher.js +13 -2
- package/dist/react-native/pusher.js.map +1 -1
- package/dist/web/pusher-with-encryption.js +64 -8
- package/dist/web/pusher-with-encryption.js.map +1 -1
- package/dist/web/pusher-with-encryption.min.js +2 -2
- package/dist/web/pusher-with-encryption.min.js.map +1 -1
- package/dist/web/pusher.js +64 -8
- package/dist/web/pusher.js.map +1 -1
- package/dist/web/pusher.min.js +2 -2
- package/dist/web/pusher.min.js.map +1 -1
- package/dist/worker/pusher-with-encryption.worker.js +63 -7
- package/dist/worker/pusher-with-encryption.worker.js.map +1 -1
- package/dist/worker/pusher-with-encryption.worker.min.js +2 -2
- package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -1
- package/dist/worker/pusher.worker.js +63 -7
- package/dist/worker/pusher.worker.js.map +1 -1
- package/dist/worker/pusher.worker.min.js +2 -2
- package/dist/worker/pusher.worker.min.js.map +1 -1
- package/package.json +1 -1
- package/spec/javascripts/unit/core/watchlist_spec.js +48 -0
- package/src/core/pusher.ts +0 -1
- package/src/core/user.ts +5 -0
- package/src/core/watchlist.ts +31 -0
- package/src/runtimes/isomorphic/auth/xhr_auth.ts +1 -1
- package/types/src/core/user.d.ts +2 -0
- package/types/src/core/watchlist.d.ts +8 -0
package/package.json
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var WatchlistFacade = require("core/watchlist").default;
|
|
2
|
+
|
|
3
|
+
describe("WatchlistFacade", function () {
|
|
4
|
+
var connection;
|
|
5
|
+
var pusher;
|
|
6
|
+
|
|
7
|
+
beforeEach(function() {
|
|
8
|
+
connection = jasmine.createSpy('connection');
|
|
9
|
+
pusher = jasmine.createSpy('pusher');
|
|
10
|
+
pusher.connection = connection;
|
|
11
|
+
|
|
12
|
+
spyOn(pusher.connection, 'bind')
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should bind to pusher_internal:user_presence events', function() {
|
|
16
|
+
new WatchlistFacade(pusher);
|
|
17
|
+
expect(connection.bind).toHaveBeenCalledWith('message', jasmine.any(Function));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('#handleEvent', function() {
|
|
21
|
+
var watchlistFacade;
|
|
22
|
+
|
|
23
|
+
beforeEach(function() {
|
|
24
|
+
watchlistFacade = new WatchlistFacade(pusher);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const watchlistEvents = [
|
|
28
|
+
{ name: 'online', user_ids: ['1'] },
|
|
29
|
+
{ name: 'offline', user_ids: ['2', '3', '4'] },
|
|
30
|
+
{ name: 'subscribe', user_ids: ['5', '6'], channel_name: 'presence-chat' }
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
it(`should emit ${watchlistEvents.length} events`, function() {
|
|
34
|
+
const pusherEvent = {
|
|
35
|
+
event: 'pusher_internal:watchlist_events',
|
|
36
|
+
data: { events: watchlistEvents }
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
spyOn(watchlistFacade, 'emit').and.callThrough();
|
|
40
|
+
watchlistFacade.handleEvent(pusherEvent);
|
|
41
|
+
|
|
42
|
+
expect(watchlistFacade.emit).toHaveBeenCalledTimes(watchlistEvents.length)
|
|
43
|
+
watchlistEvents.forEach(function(event) {
|
|
44
|
+
expect(watchlistFacade.emit).toHaveBeenCalledWith(event.name, event);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
})
|
|
48
|
+
});
|
package/src/core/pusher.ts
CHANGED
package/src/core/user.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
UserAuthenticationCallback
|
|
6
6
|
} from './auth/options';
|
|
7
7
|
import Channel from './channels/channel';
|
|
8
|
+
import WatchlistFacade from './watchlist';
|
|
8
9
|
import EventsDispatcher from './events/dispatcher';
|
|
9
10
|
import flatPromise from './utils/flat_promise';
|
|
10
11
|
|
|
@@ -14,6 +15,7 @@ export default class UserFacade extends EventsDispatcher {
|
|
|
14
15
|
user_data: any = null;
|
|
15
16
|
serverToUserChannel: Channel = null;
|
|
16
17
|
signinDonePromise: Promise<any> = null;
|
|
18
|
+
watchlist: WatchlistFacade;
|
|
17
19
|
private _signinDoneResolve: Function = null;
|
|
18
20
|
|
|
19
21
|
public constructor(pusher: Pusher) {
|
|
@@ -30,6 +32,9 @@ export default class UserFacade extends EventsDispatcher {
|
|
|
30
32
|
this._newSigninPromiseIfNeeded();
|
|
31
33
|
}
|
|
32
34
|
});
|
|
35
|
+
|
|
36
|
+
this.watchlist = new WatchlistFacade(pusher);
|
|
37
|
+
|
|
33
38
|
this.pusher.connection.bind('message', event => {
|
|
34
39
|
var eventName = event.event;
|
|
35
40
|
if (eventName === 'pusher:signin_success') {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Logger from './logger';
|
|
2
|
+
import Pusher from './pusher';
|
|
3
|
+
import EventsDispatcher from './events/dispatcher';
|
|
4
|
+
|
|
5
|
+
export default class WatchlistFacade extends EventsDispatcher {
|
|
6
|
+
private pusher: Pusher;
|
|
7
|
+
|
|
8
|
+
public constructor(pusher: Pusher) {
|
|
9
|
+
super(function(eventName, data) {
|
|
10
|
+
Logger.debug(`No callbacks on watchlist events for ${eventName}`);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
this.pusher = pusher;
|
|
14
|
+
this.bindWatchlistInternalEvent();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
handleEvent(pusherEvent) {
|
|
18
|
+
pusherEvent.data.events.forEach(watchlistEvent => {
|
|
19
|
+
this.emit(watchlistEvent.name, watchlistEvent);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private bindWatchlistInternalEvent() {
|
|
24
|
+
this.pusher.connection.bind('message', pusherEvent => {
|
|
25
|
+
var eventName = pusherEvent.event;
|
|
26
|
+
if (eventName === 'pusher_internal:watchlist_events') {
|
|
27
|
+
this.handleEvent(pusherEvent);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -60,7 +60,7 @@ const ajax: AuthTransport = function(
|
|
|
60
60
|
suffix = UrlStore.buildLogSuffix('authenticationEndpoint');
|
|
61
61
|
break;
|
|
62
62
|
case AuthRequestType.ChannelAuthorization:
|
|
63
|
-
suffix = `Clients must be
|
|
63
|
+
suffix = `Clients must be authorized to join private or presence channels. ${UrlStore.buildLogSuffix(
|
|
64
64
|
'authorizationEndpoint'
|
|
65
65
|
)}`;
|
|
66
66
|
break;
|
package/types/src/core/user.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Pusher from './pusher';
|
|
2
2
|
import Channel from './channels/channel';
|
|
3
|
+
import WatchlistFacade from './watchlist';
|
|
3
4
|
import EventsDispatcher from './events/dispatcher';
|
|
4
5
|
export default class UserFacade extends EventsDispatcher {
|
|
5
6
|
pusher: Pusher;
|
|
@@ -7,6 +8,7 @@ export default class UserFacade extends EventsDispatcher {
|
|
|
7
8
|
user_data: any;
|
|
8
9
|
serverToUserChannel: Channel;
|
|
9
10
|
signinDonePromise: Promise<any>;
|
|
11
|
+
watchlist: WatchlistFacade;
|
|
10
12
|
private _signinDoneResolve;
|
|
11
13
|
constructor(pusher: Pusher);
|
|
12
14
|
signin(): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Pusher from './pusher';
|
|
2
|
+
import EventsDispatcher from './events/dispatcher';
|
|
3
|
+
export default class WatchlistFacade extends EventsDispatcher {
|
|
4
|
+
private pusher;
|
|
5
|
+
constructor(pusher: Pusher);
|
|
6
|
+
handleEvent(pusherEvent: any): void;
|
|
7
|
+
private bindWatchlistInternalEvent;
|
|
8
|
+
}
|