35 lines
996 B
TypeScript
35 lines
996 B
TypeScript
import type { VoiceState } from '../../../../shared-kernel';
|
|
|
|
export function isLocalVoiceOwner(
|
|
voiceState: Pick<VoiceState, 'isConnected' | 'clientInstanceId'> | null | undefined,
|
|
clientInstanceId: string
|
|
): boolean {
|
|
return !!voiceState?.isConnected
|
|
&& !!voiceState.clientInstanceId
|
|
&& voiceState.clientInstanceId === clientInstanceId;
|
|
}
|
|
|
|
export function isVoiceOnAnotherClient(
|
|
voiceState: Pick<VoiceState, 'isConnected' | 'clientInstanceId'> | null | undefined,
|
|
clientInstanceId: string
|
|
): boolean {
|
|
return !!voiceState?.isConnected
|
|
&& !!voiceState.clientInstanceId
|
|
&& voiceState.clientInstanceId !== clientInstanceId;
|
|
}
|
|
|
|
export function shouldTransmitVoice(
|
|
voiceState: Pick<VoiceState, 'isConnected' | 'clientInstanceId'> | null | undefined,
|
|
clientInstanceId: string
|
|
): boolean {
|
|
if (!voiceState?.isConnected) {
|
|
return true;
|
|
}
|
|
|
|
if (!voiceState.clientInstanceId) {
|
|
return true;
|
|
}
|
|
|
|
return voiceState.clientInstanceId === clientInstanceId;
|
|
}
|