@@ -22,7 +22,7 @@ wss.on('connection', (ws) => {
22
22
console . log ( 'Message published to RabbitMQ' ) ;
23
23
24
24
// Notify the user that their message has been processed successfully
25
- ws . send ( JSON . stringify ( { status : 'su9ccess ' , message : 'Match request sent!' } ) ) ;
25
+ ws . send ( JSON . stringify ( { status : 'success ' , message : 'Match request sent!' } ) ) ;
26
26
} else if ( action === 'cancel' ) {
27
27
await publishCancelRequest ( { userId } ) ;
28
28
console . log ( 'Cancel request published to RabbitMQ' ) ;
@@ -50,8 +50,9 @@ wss.on('connection', (ws) => {
50
50
* @param {string|array } userId - User ID or an array of user IDs to notify.
51
51
* @param {string } message - The message to send.
52
52
* @param {string } type - The type of message (e.g., 'match' or 'rejection').
53
+ * @param {object } [data] - Additional data (e.g., collaboration URL).
53
54
*/
54
- function notifyUsers ( userId , message , type ) {
55
+ function notifyUsers ( userId , message , type , data = { } ) {
55
56
console . log ( `Notifying user(s): ${ userId } , Message: ${ message } , Type: ${ type } ` ) ;
56
57
57
58
const userIds = Array . isArray ( userId ) ? userId : [ userId ] ; // Convert to array if single user
@@ -60,12 +61,14 @@ function notifyUsers(userId, message, type) {
60
61
if ( client . readyState === WebSocket . OPEN && userIds . includes ( client . userId ) ) {
61
62
console . log ( `Notifying client: ${ client . userId } ` ) ;
62
63
client . send ( JSON . stringify ( {
63
- userId : client . userId ,
64
+ userId : client . userId ,
64
65
message,
65
- type
66
+ type,
67
+ ...data // Include additional data such as collaboration URL
66
68
} ) ) ;
67
69
}
68
70
} ) ;
69
71
}
70
72
73
+
71
74
module . exports = { notifyUsers } ;
0 commit comments