mpromonet / webrtc-streamer

WebRTC streamer for V4L2 capture devices, RTSP sources and Screen Capture
https://webrtcstreamer.agreeabletree-365b9a90.canadacentral.azurecontainerapps.io/?layout=2x2
The Unlicense
2.94k stars 598 forks source link

How to add a tip? #676

Open nianhuayixiao opened 6 months ago

nianhuayixiao commented 6 months ago

hi,

If a certain Hikvision camera does not start or is not connected to the internet, which code will prompt on the front-end page?

v0.8.5

CHN-STUDENT commented 3 months ago

我用 vue2 + element-ui 写的两个遮罩层 loading 和 loading Error

 setPlay(url) {
            // 检查 WebRtcStreamer 是否已加载并创建实例
            if (typeof WebRtcStreamer !== 'undefined') {
                const videoElement = document.getElementById('videoWrapper');
                if (!this.videoPlayerPlugin) {
                    this.videoPlayerPlugin = new WebRtcStreamer(videoElement, location.protocol + "//172.16.172.24:8000");
                }

                // 连接视频流
                this.videoPlayerPlugin.connect(url);

                // 设置计时器,如果10秒后未播放则认为播放失败
                const timer = setTimeout(() => {
                    this.loading = false;
                    this.loadingError = true;
                    videoElement.removeEventListener('playing', onPlaying);
                    // videoElement.setAttribute("controls", true); // 显示控制菜单
                }, 10000);

                // 播放成功的回调
                const onPlaying = () => {
                    clearTimeout(timer);
                    this.loading = false;
                    this.loadingError = false;
                    videoElement.removeAttribute("controls"); // 隐藏控制菜单
                };

                videoElement.addEventListener('playing', onPlaying);

                // 播放失败的回调
                this.videoPlayerPlugin.onError = (error) => {
                    console.error("WebRTC error: ", error);
                    clearTimeout(timer);
                    this.loading = false;
                    this.loadingError = true;
                    videoElement.setAttribute("controls", true); // 显示控制菜单
                };

            } else {
                this.loading = false;
                this.loadingError = true;
            }
        }
CHN-STUDENT commented 3 months ago

@mpromonet hi,mpromonet could you give me some advice to use in my vue project? our old project only use vue2, i try to use your project instead of RTMP(flash), I want to know how can i optimize and learn more.

mpromonet commented 3 months ago

Hi @CHN-STUDENT

Your post seems without any link with the initial issue. Please try to avoid to mix different subjects. To answer to your question using vuejs2 or vuejs3 or vanilla or another framework should be the same. Best Regards Michel