generated from yuminn-k/yuminnk-nextjs-template
-
Notifications
You must be signed in to change notification settings - Fork 4
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 #181 from yuminn-k/refactor/p2p-to-sfu-migration
🎨 ビデオチャット: P2P方式からSFU方式(MediaSoup)へのマイグレーション
- Loading branch information
Showing
6 changed files
with
872 additions
and
268 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
36 changes: 36 additions & 0 deletions
36
src/app/classes/[cId]/[mId]/components/manageSubComponents/ConnectionStatus.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,36 @@ | ||
import React, {memo} from 'react'; | ||
|
||
interface ConnectionStatusProps { | ||
state: 'connecting' | 'connected' | 'disconnected'; | ||
} | ||
|
||
const ConnectionStatus: React.FC<ConnectionStatusProps> = memo(({state}) => { | ||
const getStatusData = (): {color: string; text: string} => { | ||
const statusMap = { | ||
connected: {color: 'bg-green-500', text: '接続中'}, | ||
connecting: {color: 'bg-yellow-500', text: '接続試行中...'}, | ||
disconnected: {color: 'bg-red-500', text: '未接続'}, | ||
}; | ||
return statusMap[state]; | ||
}; | ||
|
||
const {color, text} = getStatusData(); | ||
|
||
return ( | ||
<div | ||
className="flex items-center mb-4" | ||
role="status" | ||
aria-live="polite" | ||
aria-atomic="true" | ||
> | ||
<div | ||
className={`w-3 h-3 rounded-full ${color} mr-2`} | ||
aria-hidden="true" | ||
/> | ||
<span className="text-sm text-gray-600">{text}</span> | ||
</div> | ||
); | ||
}); | ||
|
||
ConnectionStatus.displayName = 'ConnectionStatus'; | ||
export default ConnectionStatus; |
92 changes: 92 additions & 0 deletions
92
src/app/classes/[cId]/[mId]/components/manageSubComponents/ControlButtons.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,92 @@ | ||
import React, {memo} from 'react'; | ||
|
||
interface MediaState { | ||
video: boolean; | ||
audio: boolean; | ||
} | ||
|
||
interface ControlButtonsProps { | ||
isTeacher: boolean; | ||
isSharingScreen: boolean; | ||
mediaState: MediaState; | ||
isLoading?: boolean; | ||
disabled?: boolean; | ||
onEndClass: () => void; | ||
onToggleScreen: () => void; | ||
onToggleAudio: () => void; | ||
onToggleVideo: () => void; | ||
} | ||
|
||
const ControlButtons: React.FC<ControlButtonsProps> = memo( | ||
({ | ||
isTeacher, | ||
isSharingScreen, | ||
mediaState, | ||
isLoading = false, | ||
disabled = false, | ||
onEndClass, | ||
onToggleScreen, | ||
onToggleAudio, | ||
onToggleVideo, | ||
}) => { | ||
const buttonClass = (active: boolean, color: string) => | ||
`${active ? `bg-${color}-500 hover:bg-${color}-600` : 'bg-gray-500'} | ||
text-white font-bold py-2 px-4 rounded-md transition-colors | ||
disabled:opacity-50 disabled:cursor-not-allowed`; | ||
|
||
return ( | ||
<div className="flex flex-col items-center gap-4"> | ||
<button | ||
onClick={onEndClass} | ||
disabled={disabled || isLoading} | ||
className={buttonClass(true, 'red')} | ||
aria-label="授業を終了する" | ||
> | ||
{isLoading ? '処理中...' : '授業終了'} | ||
</button> | ||
|
||
{isTeacher && ( | ||
<button | ||
onClick={onToggleScreen} | ||
disabled={disabled} | ||
className={buttonClass( | ||
isSharingScreen, | ||
isSharingScreen ? 'yellow' : 'green' | ||
)} | ||
aria-label={ | ||
isSharingScreen ? '画面共有を停止する' : '画面共有を開始する' | ||
} | ||
> | ||
{isSharingScreen ? '画面共有停止' : '画面共有開始'} | ||
</button> | ||
)} | ||
|
||
<div className="flex justify-center gap-4"> | ||
<button | ||
onClick={onToggleAudio} | ||
disabled={disabled} | ||
className={buttonClass(mediaState.audio, 'blue')} | ||
aria-label={ | ||
mediaState.audio ? 'マイクをオフにする' : 'マイクをオンにする' | ||
} | ||
> | ||
{mediaState.audio ? 'マイクオン' : 'マイクオフ'} | ||
</button> | ||
<button | ||
onClick={onToggleVideo} | ||
disabled={disabled} | ||
className={buttonClass(mediaState.video, 'blue')} | ||
aria-label={ | ||
mediaState.video ? 'カメラをオフにする' : 'カメラをオンにする' | ||
} | ||
> | ||
{mediaState.video ? 'カメラオン' : 'カメラオフ'} | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
ControlButtons.displayName = 'ControlButtons'; | ||
export default ControlButtons; |
Oops, something went wrong.