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) => {}
|
(relationshipId: string, data: any) => {}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// tell everyone in a room when someone is starting to speak
|
||||||
socket.on(
|
socket.on(
|
||||||
SocketChannels.SEND_STARTED_SPEAKING,
|
SocketChannels.SEND_STARTED_SPEAKING_TO_SERVER,
|
||||||
(relationshipId: string, data: any) => {}
|
(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(
|
socket.on(
|
||||||
SocketChannels.SEND_STOPPED_SPEAKING,
|
SocketChannels.SEND_STOPPED_SPEAKING_TO_SERVER,
|
||||||
(relationshipId: string, data: any) => {}
|
(relationshipId: string) => {
|
||||||
|
console.log("stopped speaking");
|
||||||
|
socket.emit(
|
||||||
|
SocketChannels.SEND_STOPPED_SPEAKING_TO_CLIENT,
|
||||||
|
relationshipId
|
||||||
|
);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// ==== DISCONNECT ====
|
// ==== DISCONNECT ====
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ enum SocketChannels {
|
|||||||
JOIN_ROOM = "JOIN_ROOM",
|
JOIN_ROOM = "JOIN_ROOM",
|
||||||
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 = "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;
|
export default SocketChannels;
|
||||||
|
|||||||
@@ -139,18 +139,17 @@ export function useGetAllContactBasicDetails() {
|
|||||||
const [speakingRooms, setSpeakingRooms] = useState<string[]>([]);
|
const [speakingRooms, setSpeakingRooms] = useState<string[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
socket.on(
|
socket.on(SocketChannels.SEND_STARTED_SPEAKING_TO_CLIENT, () => {
|
||||||
SocketChannels.SEND_STARTED_SPEAKING,
|
console.log("yayaya someone started speaking!!!!");
|
||||||
(relationshipId: string) => {
|
|
||||||
setSpeakingRooms((prevSpeakingRooms) => [
|
// setSpeakingRooms((prevSpeakingRooms) => [
|
||||||
...prevSpeakingRooms,
|
// ...prevSpeakingRooms,
|
||||||
relationshipId,
|
// relationshipId,
|
||||||
]);
|
// ]);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
socket.on(
|
socket.on(
|
||||||
SocketChannels.SEND_STOPPED_SPEAKING,
|
SocketChannels.SEND_STOPPED_SPEAKING_TO_CLIENT,
|
||||||
(relationshipId: string) => {
|
(relationshipId: string) => {
|
||||||
setSpeakingRooms((prevSpeakingRooms) =>
|
setSpeakingRooms((prevSpeakingRooms) =>
|
||||||
prevSpeakingRooms.filter(
|
prevSpeakingRooms.filter(
|
||||||
@@ -161,8 +160,8 @@ export function useGetAllContactBasicDetails() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.removeAllListeners(SocketChannels.SEND_STARTED_SPEAKING);
|
socket.removeAllListeners(SocketChannels.SEND_STARTED_SPEAKING_TO_CLIENT);
|
||||||
socket.removeAllListeners(SocketChannels.SEND_STOPPED_SPEAKING);
|
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
|
// go through all conversations and mutate adding in data
|
||||||
// on whether or not someone is speaking or not
|
// on whether or not someone is speaking or not
|
||||||
if (reactQueryRes.data) {
|
if (reactQueryRes.data) {
|
||||||
reactQueryRes.data.contactsDetails.map((contactDet) => {
|
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 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;
|
||||||
|
|||||||
@@ -132,7 +132,13 @@ 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);
|
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
|
// hot keys for closing this window
|
||||||
@@ -176,6 +182,9 @@ export default function SelectedConversation() {
|
|||||||
</span>
|
</span>
|
||||||
|
|
||||||
{renderMainContent()}
|
{renderMainContent()}
|
||||||
|
|
||||||
|
<button onClick={socketStartedSpeaking}>start speaking</button>
|
||||||
|
<button onClick={socketStopSpeaking}>stop speaking</button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user