screensharing(data){console.log("screensharing start");// create local streamconststreamSpec={streamID:this._params.uid,audio:false,video:false,screen:true,microphoneId:data.microphoneId,cameraId:data.cameraId}// Your firefox need use support mediaSource at leastif(isFirefox()){streamSpec.mediaSource='window';}elseif(!isCompatibleChrome()){// before chrome 72 need install chrome extensions// You can download screen share plugin here https://chrome.google.com/webstore/detail/agora-web-screensharing/minllpmhdgpndnkomcoccfekfegnlikgstreamSpec.extensionId='minllpmhdgpndnkomcoccfekfegnlikg';}this._localStream=AgoraRTC.createStream(streamSpec);// set screen sharing video resolutionif(data.screenShareResolution!='default'){this._localStream.setScreenProfile(data.screenShareResolution);console.log("set screen profile",data.screenShareResolution);}// Occurs when sdk emit error this._localStream.on("error",(evt)=>{Toast.error("error",JSON.stringify([evt]))})// Occurs when a you stop screen sharingthis._localStream.on("stopScreenSharing",(evt)=>{this._localStream.stop();this._showProfile=false;Toast.notice("stop screen sharing")})// init local streamthis._localStream.init(()=>{console.log("init local stream success");// play stream with html element id "local_stream"this._localStream.play("local_stream",{fit:"cover"})// run callbackresolve();},(err)=>{Toast.error("stream init failed, please open console see more detail")console.error("init local stream failed ",err);if(isFirefox()){console.error('Failed to start screen sharing, maybe firefox not support mediaSource, please upgrade your firefox to latest version')return;}if(!isCompatibleChrome()){console.error('Failed to start screen sharing, maybe chrome extension was not installed properly, you can get it from https://chrome.google.com/webstore/detail/minllpmhdgpndnkomcoccfekfegnlikg');return;}})console.log("screensharing success");return;}
動作確認
それでは動作確認してみます。
1.画面起動
画面を起動します。(npm install、npm run devを実行しlocalhost:8080を表示)