Skip to content

Commit 0820503

Browse files
committed
feat: rename events
1 parent 3b9bf79 commit 0820503

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/index.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type UserToFollow = {
99
};
1010
type OnUserFollowedPayload = {
1111
userToFollow: UserToFollow;
12-
action: "follow" | "unfollow";
12+
action: "FOLLOW" | "UNFOLLOW";
1313
};
1414

1515
const serverDebug = debug("server");
@@ -87,35 +87,36 @@ try {
8787
},
8888
);
8989

90-
socket.on("on-user-follow", async (payload: OnUserFollowedPayload) => {
90+
socket.on("user-follow", async (payload: OnUserFollowedPayload) => {
9191
const roomID = `follow_${payload.userToFollow.socketId}`;
92+
9293
switch (payload.action) {
93-
case "follow":
94+
case "FOLLOW": {
9495
await socket.join(roomID);
9596

9697
const sockets = await io.in(roomID).fetchSockets();
9798
const followedBy = sockets.map((socket) => socket.id);
9899

99-
// Notify the user to follow that someone has followed them
100-
// More precisely, send the list of users that are following them
101-
// so that they can make decisions based on that
102100
io.to(payload.userToFollow.socketId).emit(
103-
"follow-room-user-change",
101+
"user-follow-room-change",
104102
followedBy,
105103
);
106104

107105
break;
108-
case "unfollow":
106+
}
107+
case "UNFOLLOW": {
109108
await socket.leave(roomID);
110-
const _sockets = await io.in(roomID).fetchSockets();
111-
const _followedBy = _sockets.map((socket) => socket.id);
109+
110+
const sockets = await io.in(roomID).fetchSockets();
111+
const followedBy = sockets.map((socket) => socket.id);
112112

113113
io.to(payload.userToFollow.socketId).emit(
114-
"follow-room-user-change",
115-
_followedBy,
114+
"user-follow-room-change",
115+
followedBy,
116116
);
117117

118118
break;
119+
}
119120
}
120121
});
121122

0 commit comments

Comments
 (0)