@eleven-am/pondsocket-express 0.0.7 → 0.0.8

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.
Files changed (2) hide show
  1. package/README.md +15 -15
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -174,7 +174,7 @@ const endpoint = pond.createEndpoint('/api/socket', (req, res) => {
174
174
  const role = getRoleFromToken(token);
175
175
 
176
176
  // Handle socket connection and authentication for valid users
177
- res.accept({ role }); // Assign the user's role to the socket
177
+ res.accept({role}); // Assign the user's role to the socket
178
178
  } else {
179
179
  // Reject the connection for invalid users or without a token
180
180
  res.reject('Invalid token', 401);
@@ -185,9 +185,9 @@ const endpoint = pond.createEndpoint('/api/socket', (req, res) => {
185
185
  const profanityChannel = endpoint.createChannel('/channel/:id', async (req, res) => {
186
186
  // When joining the channel, any joinParams passed from the client will be available in the request payload
187
187
  // Also any previous assigns on the socket will be available in the request payload as well
188
- const { role } = req.user.assigns;
189
- const { username } = req.joinParams;
190
- const { id } = req.event.params;
188
+ const {role} = req.user.assigns;
189
+ const {username} = req.joinParams;
190
+ const {id} = req.event.params;
191
191
 
192
192
  // maybe retrieve the previous messages from the database
193
193
  const messages = await getMessagesFromDatabase(id);
@@ -195,7 +195,7 @@ const profanityChannel = endpoint.createChannel('/channel/:id', async (req, res)
195
195
  // Check if the user has the required role to join the channel
196
196
  if (role === 'admin') {
197
197
  // Accept the join request
198
- res.accept({ username, profanityCount: 0 })
198
+ res.accept({username, profanityCount: 0})
199
199
  // optionally you can track the presence of the user in the channel
200
200
  .trackPresence({
201
201
  username,
@@ -204,7 +204,7 @@ const profanityChannel = endpoint.createChannel('/channel/:id', async (req, res)
204
204
  onlineSince: Date.now(),
205
205
  })
206
206
  // and send the user the channel history
207
- .sendToUsers('history', { messages }, [req.user.id]);
207
+ .sendToUsers('history', {messages}, [req.user.id]);
208
208
 
209
209
  // Alternatively, you can also send messages to the user, NOTE that the user would be automatically subscribed to the channel.
210
210
  // res.send('history', { messages }, { username, profanityCount: 0 })
@@ -216,19 +216,19 @@ const profanityChannel = endpoint.createChannel('/channel/:id', async (req, res)
216
216
  // });
217
217
  } else {
218
218
  // Reject the join request
219
- res.reject('You do not have the required role to join this channel', 403);
219
+ res.decline('You do not have the required role to join this channel', 403);
220
220
  }
221
221
  });
222
222
 
223
223
  // Attach message event listener to the profanityChannel
224
224
  profanityChannel.onEvent('message', (req, res) => {
225
- const { text } = req.event.payload;
225
+ const {text} = req.event.payload;
226
226
 
227
227
  // Check for profanity
228
228
  if (isTextProfane(text)) {
229
229
  // Reject the message if it contains profanity
230
- res.reject('Profanity is not allowed', 400, {
231
- profanityCount: req.user.assigns.profanityCount + 1
230
+ res.decline('Profanity is not allowed', 400, {
231
+ profanityCount: req.user.assigns.profanityCount + 1
232
232
  });
233
233
 
234
234
  // note that profanityCount is updated so req.user.assigns.profanityCount will be updated
@@ -237,9 +237,9 @@ profanityChannel.onEvent('message', (req, res) => {
237
237
  res.evictUser('You have been kicked from the channel for using profanity');
238
238
  } else {
239
239
  // you can broadcast a message to all users or In the channel that profanity is not allowed
240
- res.broadcast('profanity-warning', { message: 'Profanity is not allowed' })
240
+ res.broadcast('profanity-warning', {message: 'Profanity is not allowed'})
241
241
  // or you can send a message to the user that profanity is not allowed
242
- .sendToUsers('profanity-warning', { message: `You have used profanity ${profanityCount} times. You will be kicked from the channel if you use profanity more than 3 times.` }, [req.user.id]);
242
+ .sendToUsers('profanity-warning', {message: `You have used profanity ${profanityCount} times. You will be kicked from the channel if you use profanity more than 3 times.`}, [req.user.id]);
243
243
  }
244
244
  } else {
245
245
  // Accept the message to allow broadcasting to other clients in the channel
@@ -251,8 +251,8 @@ profanityChannel.onEvent('message', (req, res) => {
251
251
  });
252
252
 
253
253
  profanityChannel.onEvent('presence/:presence', (req, res) => {
254
- const { presence } = req.event.params;
255
- const { username } = req.user.assigns;
254
+ const {presence} = req.event.params;
255
+ const {username} = req.user.assigns;
256
256
 
257
257
  // Handle presence events
258
258
  res.updatePresence({
@@ -264,7 +264,7 @@ profanityChannel.onEvent('presence/:presence', (req, res) => {
264
264
  });
265
265
 
266
266
  profanityChannel.onLeave((event) => {
267
- const { username } = event.assigns;
267
+ const {username} = event.assigns;
268
268
 
269
269
  // When a user leaves the channel, PondSocket will automatically remove the user from the presence list and inform other users in the channel
270
270
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket-express",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
@@ -29,17 +29,17 @@
29
29
  "pipeline": "npm run lint && npm run build && npm run push"
30
30
  },
31
31
  "dependencies": {
32
- "@eleven-am/pondsocket": "^0.1.141"
32
+ "@eleven-am/pondsocket": "^0.1.142"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/jest": "^29.5.11",
35
+ "@types/jest": "^29.5.12",
36
36
  "@types/express": "^4.17.21",
37
- "@typescript-eslint/eslint-plugin": "^6.19.0",
37
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
38
38
  "eslint-plugin-file-progress": "^1.3.0",
39
39
  "eslint-plugin-import": "^2.29.1",
40
40
  "jest": "^29.7.0",
41
- "prettier": "^3.2.4",
42
- "ts-jest": "^29.1.1",
41
+ "prettier": "^3.2.5",
42
+ "ts-jest": "^29.1.2",
43
43
  "ts-loader": "^9.5.1",
44
44
  "ts-node": "^10.9.2",
45
45
  "typescript": "^5.3.3"