我正在使用agora io进行视频通话和屏幕共享。屏幕共享工作正常。但是问题是当我取消屏幕共享时,流不显示。但是加入仍然很活跃。我需要捕捉屏幕共享的取消事件。我已经阅读了文档,但是没有关于取消事件的线索。 您能帮忙参加取消活动吗? 预先谢谢你。
答案 0 :(得分:1)
如果您使用的是Agora Web SDK NG,则可以这样使用-
screen_rtc.screenTrack.close();
在这里screen_rtc是我的客户端对象,您还可以如下所示禁用屏幕客户端-
screen_rtc.client.leave();
我用于屏幕共享的完整代码如下-
<!-- Import Agora -->
import AgoraRTC from "agora-rtc-sdk-ng";
<!-- Create client for screen -->
screen_rtc: {
client: null,
screenTrack: null,
},
<!-- Start Screen sharing -->
screen_rtc.client = AgoraRTC.createClient({
mode: "rtc",
codec: "vp8",
});
await screen_rtc.client.join(
<YOUR_APP_ID>,
<YOUR_CHANNEL_NAME>,
<YOUR_TOKEN>,
null
);
screen_rtc.screenTrack = await AgoraRTC.createScreenVideoTrack();
await screen_rtc.client.publish(screen_rtc.screenTrack);
<!-- Stop screen sharing -->
screen_rtc.screenTrack.close();
await screen_rtc.client.leave();
答案 1 :(得分:1)
If you are using agora web sdk ng library then you can detect this by using track-ended event.
We can create screen track using createScreenVideoTrack in this sdk.
step-1 call this method to create track
async shareScreen() {
const localScreenTrack = await AgoraRTC.createScreenVideoTrack();
return localScreenTrack;
}
step2- call event method after creating track.
To add event on this track create different method to handle event
shareScreenEvent(){
const track = this.shareScreen()
if (track) {
track.on('track-ended', () => {
console.log('track-ended');
console.log('you can run your code here to stop screen')
})
}
}
答案 2 :(得分:0)
Agora的Web SDK没有提供检测此问题的任何方法,但是由于Agora Web SDK基于Web RTC,因此您可以利用navigator
对象和catch
错误。
navigator.mediaDevices.getUserMedia(constraints).then(function success(stream) {
/* media access has been granted */
}).catch(function(err) {
//log to console first
console.log(err); /* handle the error */
if (err.name == "NotFoundError" || err.name == "DevicesNotFoundError") {
//required track is missing
} else if (err.name == "NotReadableError" || err.name == "TrackStartError") {
//webcam or mic are already in use
} else if (err.name == "OverconstrainedError" || err.name == "ConstraintNotSatisfiedError") {
//constraints can not be satisfied by avb. devices
} else if (err.name == "NotAllowedError" || err.name == "PermissionDeniedError") {
//permission denied in browser
} else if (err.name == "TypeError" || err.name == "TypeError") {
//empty constraints object
} else {
//other errors
console.log("Error: " + err.name);
}
});
参考链接:https://blog.addpipe.com/common-getusermedia-errors/
代码笔演示:https://codepen.io/naicuoctavian/pen/wPeZWO
答案 3 :(得分:0)
您可以尝试使用 stopScreenSharing 事件。
this.localStream.on("stopScreenSharing", () => {
this.localStream.stop();
this.localStream.close();
//this.client.leave();
});