speaking and not speaking working nicely with sockets
This commit is contained in:
+16
-20
@@ -56,6 +56,8 @@ io.on("connection", function (socket: any) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
socket.join(relationshipId);
|
socket.join(relationshipId);
|
||||||
|
|
||||||
|
console.log(`${socket.id} now in rooms ${socket.rooms}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ==== UPDATES ====
|
// ==== UPDATES ====
|
||||||
@@ -72,28 +74,22 @@ io.on("connection", function (socket: any) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// tell everyone in a room when someone is starting to speak
|
// tell everyone in a room when someone is starting to speak
|
||||||
socket.on(
|
socket.on(SocketChannels.SEND_STARTED_SPEAKING, (relationshipId: string) => {
|
||||||
SocketChannels.SEND_STARTED_SPEAKING_TO_SERVER,
|
console.log(`started speaking in ${relationshipId}`);
|
||||||
(relationshipId: string) => {
|
io.in(relationshipId).emit(
|
||||||
console.log("started speaking");
|
SocketChannels.SEND_STARTED_SPEAKING,
|
||||||
socket.emit(
|
relationshipId
|
||||||
SocketChannels.SEND_STARTED_SPEAKING_TO_CLIENT,
|
);
|
||||||
relationshipId
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// tell everyone in a room when someone is stopping to speak
|
// tell everyone in a room when someone is stopping to speak
|
||||||
socket.on(
|
socket.on(SocketChannels.SEND_STOPPED_SPEAKING, (relationshipId: string) => {
|
||||||
SocketChannels.SEND_STOPPED_SPEAKING_TO_SERVER,
|
console.log(`stopped speaking in ${relationshipId}`);
|
||||||
(relationshipId: string) => {
|
io.in(relationshipId).emit(
|
||||||
console.log("stopped speaking");
|
SocketChannels.SEND_STOPPED_SPEAKING,
|
||||||
socket.emit(
|
relationshipId
|
||||||
SocketChannels.SEND_STOPPED_SPEAKING_TO_CLIENT,
|
);
|
||||||
relationshipId
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// ==== DISCONNECT ====
|
// ==== DISCONNECT ====
|
||||||
socket.on("disconnect", () => {
|
socket.on("disconnect", () => {
|
||||||
|
|||||||
@@ -3,11 +3,8 @@ enum SocketChannels {
|
|||||||
SEND_AUDIO_CLIP = "SEND_AUDIO_CLIP",
|
SEND_AUDIO_CLIP = "SEND_AUDIO_CLIP",
|
||||||
SEND_USER_STATUS_UPDATE = "SEND_USER_STATUS_UPDATE",
|
SEND_USER_STATUS_UPDATE = "SEND_USER_STATUS_UPDATE",
|
||||||
|
|
||||||
SEND_STARTED_SPEAKING_TO_SERVER = "SEND_STARTED_SPEAKING_TO_SERVER",
|
SEND_STARTED_SPEAKING = "SEND_STARTED_SPEAKING",
|
||||||
SEND_STOPPED_SPEAKING_TO_SERVER = "SEND_STOPPED_SPEAKING_TO_SERVER",
|
SEND_STOPPED_SPEAKING = "SEND_STOPPED_SPEAKING",
|
||||||
|
|
||||||
SEND_STARTED_SPEAKING_TO_CLIENT = "SEND_STARTED_SPEAKING_TO_CLIENT",
|
|
||||||
SEND_STOPPED_SPEAKING_TO_CLIENT = "SEND_STOPPED_SPEAKING_TO_CLIENT",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SocketChannels;
|
export default SocketChannels;
|
||||||
|
|||||||
@@ -139,18 +139,23 @@ export function useGetAllContactBasicDetails() {
|
|||||||
const [speakingRooms, setSpeakingRooms] = useState<string[]>([]);
|
const [speakingRooms, setSpeakingRooms] = useState<string[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
socket.on(SocketChannels.SEND_STARTED_SPEAKING_TO_CLIENT, () => {
|
socket.on(
|
||||||
console.log("yayaya someone started speaking!!!!");
|
SocketChannels.SEND_STARTED_SPEAKING,
|
||||||
|
(relationshipId: string) => {
|
||||||
|
console.log(`yayaya someone started speaking in ${relationshipId}!!!!`);
|
||||||
|
|
||||||
// setSpeakingRooms((prevSpeakingRooms) => [
|
setSpeakingRooms((prevSpeakingRooms) => [
|
||||||
// ...prevSpeakingRooms,
|
...prevSpeakingRooms,
|
||||||
// relationshipId,
|
relationshipId,
|
||||||
// ]);
|
]);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
socket.on(
|
socket.on(
|
||||||
SocketChannels.SEND_STOPPED_SPEAKING_TO_CLIENT,
|
SocketChannels.SEND_STOPPED_SPEAKING,
|
||||||
(relationshipId: string) => {
|
(relationshipId: string) => {
|
||||||
|
console.log(`stopped speaking in ${relationshipId}!!!!`);
|
||||||
|
|
||||||
setSpeakingRooms((prevSpeakingRooms) =>
|
setSpeakingRooms((prevSpeakingRooms) =>
|
||||||
prevSpeakingRooms.filter(
|
prevSpeakingRooms.filter(
|
||||||
(relationshipRoomId) => relationshipRoomId !== relationshipId
|
(relationshipRoomId) => relationshipRoomId !== relationshipId
|
||||||
@@ -160,8 +165,8 @@ export function useGetAllContactBasicDetails() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.removeAllListeners(SocketChannels.SEND_STARTED_SPEAKING_TO_CLIENT);
|
socket.removeAllListeners(SocketChannels.SEND_STARTED_SPEAKING);
|
||||||
socket.removeAllListeners(SocketChannels.SEND_STOPPED_SPEAKING_TO_CLIENT);
|
socket.removeAllListeners(SocketChannels.SEND_STOPPED_SPEAKING);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -192,6 +197,8 @@ export function useGetAllContactBasicDetails() {
|
|||||||
// if this contact/conversation is in the list of speaking ones, then change isSpeaking
|
// if this contact/conversation is in the list of speaking ones, then change isSpeaking
|
||||||
if (speakingRooms.includes(contactDet.relationship._id.toString())) {
|
if (speakingRooms.includes(contactDet.relationship._id.toString())) {
|
||||||
contactDet.isSpeaking = true;
|
contactDet.isSpeaking = true;
|
||||||
|
} else {
|
||||||
|
contactDet.isSpeaking = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,13 +132,23 @@ export default function SelectedConversation() {
|
|||||||
const socketStartedSpeaking = () => {
|
const socketStartedSpeaking = () => {
|
||||||
// send the room name and the update type
|
// send the room name and the update type
|
||||||
|
|
||||||
socket.emit(SocketChannels.SEND_STARTED_SPEAKING_TO_SERVER, selectedConvo);
|
// only send if we are in a relationship
|
||||||
|
if (convoDetailsResponse.ourRelationship._id.toString())
|
||||||
|
socket.emit(
|
||||||
|
SocketChannels.SEND_STARTED_SPEAKING,
|
||||||
|
convoDetailsResponse.ourRelationship._id.toString()
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const socketStopSpeaking = () => {
|
const socketStopSpeaking = () => {
|
||||||
// send the room name and the update type
|
// send the room name and the update type
|
||||||
|
|
||||||
socket.emit(SocketChannels.SEND_STOPPED_SPEAKING_TO_SERVER, selectedConvo);
|
// only send if we are in a relationship
|
||||||
|
if (convoDetailsResponse.ourRelationship._id.toString())
|
||||||
|
socket.emit(
|
||||||
|
SocketChannels.SEND_STOPPED_SPEAKING,
|
||||||
|
convoDetailsResponse.ourRelationship._id.toString()
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// hot keys for closing this window
|
// hot keys for closing this window
|
||||||
|
|||||||
Reference in New Issue
Block a user