-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19748 from Tainan404/refactor-voice-user
Refactor: move voice users to graphql
- Loading branch information
Showing
8 changed files
with
118 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...tml5/imports/ui/components/components-data/voiceUserGraphQlMiniMongoAdapter/component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useSubscription } from '@apollo/client'; | ||
import React, { useEffect, useState } from 'react'; | ||
import VoiceUsers from '/imports/api/voice-users/'; | ||
import logger from '/imports/startup/client/logger'; | ||
import { UserVoiceStreamResponse, voiceUserStream } from './queries'; | ||
|
||
const VoiceUserGrapQlMiniMongoAdapter: React.FC = () => { | ||
const { | ||
loading, | ||
error, | ||
data, | ||
} = useSubscription<UserVoiceStreamResponse>(voiceUserStream); | ||
const [voiceUserDataSetted, setVoiceUserDataSetted] = useState(false); | ||
|
||
useEffect(() => { | ||
if (error) { | ||
logger.error('Error in VoiceUserGrapQlMiniMongoAdapter', error); | ||
} | ||
}, [error]); | ||
|
||
useEffect(() => { | ||
if (data && data.user_voice_mongodb_adapter_stream) { | ||
const usersVoice = data.user_voice_mongodb_adapter_stream; | ||
|
||
usersVoice.forEach((userVoice) => { | ||
VoiceUsers.upsert({ userId: userVoice.userId }, userVoice); | ||
}); | ||
} | ||
}, [data]); | ||
|
||
useEffect(() => { | ||
if (loading) { | ||
if (!voiceUserDataSetted) { | ||
setVoiceUserDataSetted(true); | ||
} | ||
} | ||
}, [loading]); | ||
return null; | ||
}; | ||
|
||
export default VoiceUserGrapQlMiniMongoAdapter; |
67 changes: 67 additions & 0 deletions
67
...n-html5/imports/ui/components/components-data/voiceUserGraphQlMiniMongoAdapter/queries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
interface UserVoiceStream { | ||
callerName: string | null; | ||
callerNum: string | null; | ||
callingWith: string | null; | ||
endTime: string | null; | ||
endedAt: string | null; | ||
floor: string | null; | ||
hideTalkingIndicatorAt: string | null; | ||
joined: string | null; | ||
lastFloorTime: string | null; | ||
lastSpeakChangedAt: number; | ||
listenOnly: string | null; | ||
muted: string | null; | ||
showTalkingIndicator: boolean; | ||
spoke: string | null; | ||
startTime: string | null; | ||
startedAt: string | null; | ||
talking: string | null; | ||
userId: string; | ||
voiceConf: string | null; | ||
voiceConfCallSession: string | null; | ||
voiceConfCallState: string | null; | ||
voiceConfClientSession: string | null; | ||
voiceUpdatedAt: string | null; | ||
voiceUserId: string | null; | ||
} | ||
|
||
export interface UserVoiceStreamResponse { | ||
user_voice_mongodb_adapter_stream: UserVoiceStream[]; | ||
} | ||
|
||
export const voiceUserStream = gql` | ||
subscription voiceUserStream { | ||
user_voice_mongodb_adapter_stream(cursor: {initial_value: {voiceUpdatedAt: "2020-01-01"}}, batch_size: 100) { | ||
callerName | ||
callerNum | ||
callingWith | ||
endTime | ||
endedAt | ||
floor | ||
hideTalkingIndicatorAt | ||
joined | ||
lastFloorTime | ||
lastSpeakChangedAt | ||
listenOnly | ||
muted | ||
showTalkingIndicator | ||
spoke | ||
startTime | ||
startedAt | ||
talking | ||
userId | ||
voiceConf | ||
voiceConfCallSession | ||
voiceConfCallState | ||
voiceConfClientSession | ||
voiceUpdatedAt | ||
voiceUserId | ||
} | ||
} | ||
`; | ||
|
||
export default { | ||
voiceUserStream, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters