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.
π¨ refactor: Migrate video chat from P2P to SFU architecture using Medβ¦
β¦iaSoup - Replace P2P WebRTC implementation with MediaSoup-based SFU architecture - Restructure LiveClass component for scalable video streaming: - Add ConnectionStatus for improved connection state management - Extract ControlButtons for better media control handling - Create VideoBox for unified video stream rendering - Implement MediaSoup producer/consumer pattern - Enhance WebSocket signaling for SFU communication - Add robust error handling and reconnection logic - Improve stream management and cleanup Technical Details: - Switch from direct P2P connections to MediaSoup-based routing - Implement proper stream producer/consumer lifecycle - Add TypeScript interfaces for MediaSoup integration - Update WebSocket protocol for SFU requirements Dependencies: - Add mediasoup-client - Add @types/webrtc
- 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.