cleaning and starting process for listening to socket events
This commit is contained in:
@@ -1,34 +1,3 @@
|
||||
// ! NOTE: these are legacy and too much thinking in the developers head to understand the flow
|
||||
enum SocketChannels {
|
||||
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',
|
||||
|
||||
JOIN_LIVE_ROOM = 'JOIN_LIVE_ROOM',
|
||||
GET_ALL_ACTIVE_SOCKET_IDS = 'GET_ALL_ACTIVE_SOCKET_IDS',
|
||||
|
||||
SEND_SIGNAL = 'SEND_SIGNAL',
|
||||
|
||||
RECEIVE_SIGNAL = 'RECEIVE_SIGNAL',
|
||||
|
||||
// v3
|
||||
|
||||
/**
|
||||
* when someone connects to a line, whether tuned in or not
|
||||
*/
|
||||
CONNECT_TO_LINE = 'CONNECT_TO_LINE',
|
||||
SOMEONE_CONNECTED_TO_LINE = 'SOMEONE_CONNECTED_TO_LINE',
|
||||
|
||||
TUNE_TO_LINE = 'TUNE_TO_LINE',
|
||||
SOMEONE_TUNED_TO_LINE = 'SOMEONE_TUNED_TO_LINE',
|
||||
|
||||
SOMEONE_UNTUNED_FROM_LINE = 'SOMEONE_UNTUNED_FROM_LINE',
|
||||
|
||||
USER_BROADCAST_PUSH_PULL = 'USER_BROADCAST_PUSH_PULL',
|
||||
}
|
||||
|
||||
// ! MAKE SURE THAT THE ENUMS BETWEEN REQUEST AND RESPONSE DON'T OVERLAP???
|
||||
// ?maybe won't matter since it's different for server and client?
|
||||
export enum ServerRequestChannels {
|
||||
@@ -64,8 +33,6 @@ export enum ServerResponseChannels {
|
||||
SOMEONE_GOING_INTO_FLOW_STATE = 'SOMEONE_GOING_INTO_FLOW_STATE',
|
||||
}
|
||||
|
||||
export default SocketChannels;
|
||||
|
||||
export class ConnectToLineRequest {
|
||||
constructor(public lineId: string) {}
|
||||
}
|
||||
@@ -103,11 +70,6 @@ export class UserStoppedBroadcastingResponse {
|
||||
constructor(public lineId: string, public userId: string) {}
|
||||
}
|
||||
|
||||
// ?another approach to use switch statements, but it just requires same mess, just less methods with socket but who cares right now
|
||||
export class SocketEmitter<T> {
|
||||
constructor(public channel: SocketChannels, data: T) {}
|
||||
}
|
||||
|
||||
export class RtcCallRequest {
|
||||
constructor(public userToCall: string, public lineId: string, public simplePeerSignal: any) {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { ServerResponseChannels, SomeoneTunedResponse } from '@nirvana/core/sockets/channels';
|
||||
|
||||
import { SomeoneConnectedResponse } from '@nirvana/core/sockets/channels';
|
||||
import useSockets from './SocketProvider';
|
||||
|
||||
/**
|
||||
* Responsibility: provide real time feel of people presence
|
||||
*
|
||||
* Get to know when:
|
||||
* - me or someone else tunes or untunes from a conversation
|
||||
* - someone speaks in a chat for a conversation that I am tuned into
|
||||
* - there is new content in a channel that I am connected or tuned into
|
||||
* - someone in a chat that I am tuned into goes into flow state
|
||||
*
|
||||
*
|
||||
* Firing Events - this could be in the universe as a whole through a hook and doesn't need to be in here
|
||||
* - have helper async functions which take in a socket client and call the event
|
||||
* - on load, we need to join the particular rooms based on priority vs inbox
|
||||
* - move conversation to priority and back and mutate the conversation map
|
||||
*
|
||||
* Listening Events:
|
||||
* - have a useEffect that listens to all events and mutates conversation map accordingly
|
||||
* -
|
||||
*/
|
||||
|
||||
const RealtimeContext = React.createContext({});
|
||||
|
||||
export function RealtimeProvider({ children }: { children }) {
|
||||
const { $ws } = useSockets();
|
||||
|
||||
useEffect(() => {
|
||||
// $ws.on(ServerResponseChannels.SOMEONE_CONNECTED_TO_LINE, (res: SomeoneConnectedResponse) => {
|
||||
// })
|
||||
// $ws.on(ServerResponseChannels.SOMEONE_TUNED_INTO_LINE, (res: SomeoneTunedResponse) => {
|
||||
// })
|
||||
}, [$ws]);
|
||||
|
||||
return <RealtimeContext.Provider value={{}}>{children}</RealtimeContext.Provider>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user