@@ -46,7 +46,6 @@ if (typeof MediaStreamTrackProcessor === 'undefined') {
4646 this . readable = new ReadableStream ( {
4747 async start ( controller ) {
4848 const ctx = new AudioContext ( ) ;
49- // Worklet to pass raw audio data to main thread
5049 const workletCode = `registerProcessor("mstp-shim",class extends AudioWorkletProcessor{process(i){if(i[0].length>0)this.port.postMessage(i[0]);return true}})`
5150 await ctx . audioWorklet . addModule ( `data:text/javascript,${ workletCode } ` ) . catch ( e => console . error ( e ) ) ;
5251
@@ -57,7 +56,6 @@ if (typeof MediaStreamTrackProcessor === 'undefined') {
5756 node . port . onmessage = ( { data : channels } ) => {
5857 if ( ! channels || channels . length === 0 ) return ;
5958
60- // Flatten planar data (array of Float32Arrays) to interleaved Float32Array
6159 const length = channels [ 0 ] . length ;
6260 const numChannels = channels . length ;
6361 const flattened = new Float32Array ( length * numChannels ) ;
@@ -1427,7 +1425,7 @@ document.addEventListener('DOMContentLoaded', () => {
14271425 }
14281426 } ;
14291427
1430- const handleUsernameSubmit = ( e ) => {
1428+ const handleUsernameSubmit = async ( e ) => {
14311429 e . preventDefault ( ) ;
14321430 const input = document . getElementById ( 'username-input' ) ;
14331431 const newUsername = input . value . trim ( ) ;
@@ -1438,6 +1436,27 @@ document.addEventListener('DOMContentLoaded', () => {
14381436 sessionStorage . setItem ( 'collab_hasJoined_' + COLLAB_DATA . sessionId , 'true' ) ;
14391437 ws . send ( JSON . stringify ( { action : 'set_username' , username : username } ) ) ;
14401438 renderSidebar ( ) ;
1439+
1440+ if ( ! mediaInitialized ) {
1441+ await startMedia ( ) ;
1442+ }
1443+
1444+ isMicOn = true ;
1445+ if ( localStream ) localStream . getAudioTracks ( ) . forEach ( t => t . enabled = true ) ;
1446+ sendControlMessage ( 'audio_state' , true ) ;
1447+ updateMediaButtonUI ( ) ;
1448+
1449+ await new Promise ( r => setTimeout ( r , 1000 ) ) ;
1450+
1451+ isWebcamOn = true ;
1452+ if ( localStream && localStream . getVideoTracks ( ) . length > 0 ) {
1453+ localStream . getVideoTracks ( ) . forEach ( t => t . enabled = true ) ;
1454+ localContainer . style . display = 'flex' ;
1455+ sendControlMessage ( 'video_state' , true ) ;
1456+ }
1457+ updateMediaButtonUI ( ) ;
1458+
1459+ toggleSidebar ( ) ;
14411460 }
14421461 } ;
14431462
0 commit comments