You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Implement PubNub Access Manager v3 integration in SyncManager
- Add grantToken(), setAuthToken(), parseToken() methods
- Add automatic token refresh via onTokenExpired callback
- Add accessdenied event for 403 Forbidden handling
- Include -pnpres presence channel in default token grants
- Add PAM Admin/Follower mode UI to demo
- Switch demo to light theme with improved readability
- Add architecture diagram to README
- Use absolute GitHub raw URLs for images (NPM compatibility)
- Add 21 new unit tests for Access Manager features
- Bump version to 1.1.2
|`masterchanged`|`{ newMasterId, previousRole }`| Another user claimed master |
114
+
|`userjoined`|`{ userId, occupancy }`| A user joined the room |
115
+
|`userleft`|`{ userId, occupancy }`| A user left the room |
116
+
|`connected`|`{ roomId }`| Successfully connected to a room |
117
+
|`disconnected`|`{ roomId }`| Disconnected from a room |
118
+
|`accessdenied`|`{ reason }`| Access Manager denied a request (403) |
119
+
120
+
---
121
+
122
+
## Access Manager (Optional Security)
123
+
124
+
PubNub Access Manager lets you secure Watch Party rooms with time-limited, per-user tokens. Access Manager is **completely optional** — if you don't need it, the library works without any token configuration.
125
+
126
+
### Why Use Access Manager?
127
+
128
+
- Prevent unauthorized users from joining or controlling Watch Party rooms
129
+
- Restrict **Master** (publish) access to specific users
130
+
- Issue time-limited tokens that automatically expire
131
+
- Revoke access at any time
132
+
133
+
### Server-Side Token Granting (Recommended)
134
+
135
+
In production, your server authenticates users and grants scoped tokens. The client never sees the Secret Key.
136
+
137
+
```
138
+
Client → Your Server → PubNub grantToken() → token → Client → SyncManager
139
+
```
140
+
141
+
**Server-side (Node.js):**
142
+
143
+
```javascript
144
+
importPubNubfrom'pubnub';
145
+
146
+
constpubnub=newPubNub({
147
+
publishKey:'pub-c-xxx',
148
+
subscribeKey:'sub-c-xxx',
149
+
secretKey:'sec-c-xxx', // Never expose this to clients
'shaka-sync-friday-movie-pnpres': { read:true }, // Required for presence events
161
+
},
162
+
},
163
+
});
164
+
165
+
// Send `token` to the authenticated client
166
+
```
167
+
168
+
**Client-side:**
169
+
170
+
```javascript
171
+
constsyncManager=newSyncManager(player, {
172
+
publishKey:'pub-c-xxx',
173
+
subscribeKey:'sub-c-xxx',
174
+
PubNub: PubNub,
175
+
authToken: token, // Token from your server
176
+
});
177
+
178
+
syncManager.connect('friday-movie');
100
179
```
101
180
181
+
### Automatic Token Refresh
182
+
183
+
Tokens expire. Provide an `onTokenExpired` callback to seamlessly refresh tokens without interrupting the session:
184
+
185
+
```javascript
186
+
constsyncManager=newSyncManager(player, {
187
+
publishKey:'pub-c-xxx',
188
+
subscribeKey:'sub-c-xxx',
189
+
PubNub: PubNub,
190
+
authToken: initialToken,
191
+
onTokenExpired:async () => {
192
+
constres=awaitfetch('/api/pubnub/token');
193
+
const { token } =awaitres.json();
194
+
return token;
195
+
},
196
+
});
197
+
```
198
+
199
+
When a `403 Forbidden` response is detected, the library automatically calls `onTokenExpired`, applies the new token, and retries the failed operation.
200
+
201
+
### Runtime Token Updates
202
+
203
+
Update the token at any time without reconnecting:
204
+
205
+
```javascript
206
+
syncManager.setAuthToken(newToken);
207
+
```
208
+
209
+
### Role-Based Tokens
210
+
211
+
Issue different tokens for different roles:
212
+
213
+
| Role | Channel Permissions | Presence Channel (`-pnpres`) | Use Case |
1. Enable **Access Manager** on your keyset in the [PubNub Admin Portal](https://admin.pubnub.com)
266
+
2. Store your **Secret Key** securely on your server
267
+
3. Implement a server endpoint that authenticates users and calls `grantToken()`
268
+
4. Pass the token to the client via `authToken` in the SyncManager config
269
+
5. Optionally add an `onTokenExpired` callback for automatic refresh
270
+
102
271
---
103
272
104
273
## How Sync Works
105
274
106
-
<imgsrc="assets/shaka-player-diagram.png"alt="PubNub Shaka Player Sync Architecture"width="100%">
275
+
<imgsrc="https://raw.githubusercontent.com/PubNubDevelopers/Shaka-Player-Sync/main/assets/shaka-player-diagram.png"alt="PubNub Shaka Player Sync Architecture"width="100%">
0 commit comments