working sending data but not specific to room
This commit is contained in:
+18
-4
@@ -71,14 +71,28 @@ io.on("connection", function (socket: any) {
|
||||
(relationshipId: string, data: any) => {}
|
||||
);
|
||||
|
||||
// tell everyone in a room when someone is starting to speak
|
||||
socket.on(
|
||||
SocketChannels.SEND_STARTED_SPEAKING,
|
||||
(relationshipId: string, data: any) => {}
|
||||
SocketChannels.SEND_STARTED_SPEAKING_TO_SERVER,
|
||||
(relationshipId: string) => {
|
||||
console.log("started speaking");
|
||||
socket.emit(
|
||||
SocketChannels.SEND_STARTED_SPEAKING_TO_CLIENT,
|
||||
relationshipId
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// tell everyone in a room when someone is stopping to speak
|
||||
socket.on(
|
||||
SocketChannels.SEND_STOPPED_SPEAKING,
|
||||
(relationshipId: string, data: any) => {}
|
||||
SocketChannels.SEND_STOPPED_SPEAKING_TO_SERVER,
|
||||
(relationshipId: string) => {
|
||||
console.log("stopped speaking");
|
||||
socket.emit(
|
||||
SocketChannels.SEND_STOPPED_SPEAKING_TO_CLIENT,
|
||||
relationshipId
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// ==== DISCONNECT ====
|
||||
|
||||
@@ -2,8 +2,12 @@ enum SocketChannels {
|
||||
JOIN_ROOM = "JOIN_ROOM",
|
||||
SEND_AUDIO_CLIP = "SEND_AUDIO_CLIP",
|
||||
SEND_USER_STATUS_UPDATE = "SEND_USER_STATUS_UPDATE",
|
||||
SEND_STARTED_SPEAKING = "SEND_STARTED_SPEAKING",
|
||||
SEND_STOPPED_SPEAKING = "SEND_STOPPED_SPEAKING",
|
||||
|
||||
SEND_STARTED_SPEAKING_TO_SERVER = "SEND_STARTED_SPEAKING_TO_SERVER",
|
||||
SEND_STOPPED_SPEAKING_TO_SERVER = "SEND_STOPPED_SPEAKING_TO_SERVER",
|
||||
|
||||
SEND_STARTED_SPEAKING_TO_CLIENT = "SEND_STARTED_SPEAKING_TO_CLIENT",
|
||||
SEND_STOPPED_SPEAKING_TO_CLIENT = "SEND_STOPPED_SPEAKING_TO_CLIENT",
|
||||
}
|
||||
|
||||
export default SocketChannels;
|
||||
|
||||
@@ -139,18 +139,17 @@ export function useGetAllContactBasicDetails() {
|
||||
const [speakingRooms, setSpeakingRooms] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
socket.on(
|
||||
SocketChannels.SEND_STARTED_SPEAKING,
|
||||
(relationshipId: string) => {
|
||||
setSpeakingRooms((prevSpeakingRooms) => [
|
||||
...prevSpeakingRooms,
|
||||
relationshipId,
|
||||
]);
|
||||
}
|
||||
);
|
||||
socket.on(SocketChannels.SEND_STARTED_SPEAKING_TO_CLIENT, () => {
|
||||
console.log("yayaya someone started speaking!!!!");
|
||||
|
||||
// setSpeakingRooms((prevSpeakingRooms) => [
|
||||
// ...prevSpeakingRooms,
|
||||
// relationshipId,
|
||||
// ]);
|
||||
});
|
||||
|
||||
socket.on(
|
||||
SocketChannels.SEND_STOPPED_SPEAKING,
|
||||
SocketChannels.SEND_STOPPED_SPEAKING_TO_CLIENT,
|
||||
(relationshipId: string) => {
|
||||
setSpeakingRooms((prevSpeakingRooms) =>
|
||||
prevSpeakingRooms.filter(
|
||||
@@ -161,8 +160,8 @@ export function useGetAllContactBasicDetails() {
|
||||
);
|
||||
|
||||
return () => {
|
||||
socket.removeAllListeners(SocketChannels.SEND_STARTED_SPEAKING);
|
||||
socket.removeAllListeners(SocketChannels.SEND_STOPPED_SPEAKING);
|
||||
socket.removeAllListeners(SocketChannels.SEND_STARTED_SPEAKING_TO_CLIENT);
|
||||
socket.removeAllListeners(SocketChannels.SEND_STOPPED_SPEAKING_TO_CLIENT);
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -174,16 +173,22 @@ export function useGetAllContactBasicDetails() {
|
||||
}
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (reactQueryRes.data) {
|
||||
reactQueryRes.data.contactsDetails.map((contactDet) => {
|
||||
// join the right rooms based on the relevant contacts/conversations returned here
|
||||
socket.emit(
|
||||
SocketChannels.JOIN_ROOM,
|
||||
contactDet.relationship._id.toString()
|
||||
);
|
||||
});
|
||||
}
|
||||
}, [reactQueryRes.isFetched]);
|
||||
|
||||
// go through all conversations and mutate adding in data
|
||||
// on whether or not someone is speaking or not
|
||||
if (reactQueryRes.data) {
|
||||
reactQueryRes.data.contactsDetails.map((contactDet) => {
|
||||
// todo: join the right rooms based on the relevant contacts/conversations returned here
|
||||
socket.emit(
|
||||
SocketChannels.JOIN_ROOM,
|
||||
contactDet.relationship._id.toString()
|
||||
);
|
||||
|
||||
// if this contact/conversation is in the list of speaking ones, then change isSpeaking
|
||||
if (speakingRooms.includes(contactDet.relationship._id.toString())) {
|
||||
contactDet.isSpeaking = true;
|
||||
|
||||
@@ -132,7 +132,13 @@ export default function SelectedConversation() {
|
||||
const socketStartedSpeaking = () => {
|
||||
// send the room name and the update type
|
||||
|
||||
socket.emit(SocketChannels.SEND_STARTED_SPEAKING);
|
||||
socket.emit(SocketChannels.SEND_STARTED_SPEAKING_TO_SERVER, selectedConvo);
|
||||
};
|
||||
|
||||
const socketStopSpeaking = () => {
|
||||
// send the room name and the update type
|
||||
|
||||
socket.emit(SocketChannels.SEND_STOPPED_SPEAKING_TO_SERVER, selectedConvo);
|
||||
};
|
||||
|
||||
// hot keys for closing this window
|
||||
@@ -176,6 +182,9 @@ export default function SelectedConversation() {
|
||||
</span>
|
||||
|
||||
{renderMainContent()}
|
||||
|
||||
<button onClick={socketStartedSpeaking}>start speaking</button>
|
||||
<button onClick={socketStopSpeaking}>stop speaking</button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user