一、环境

// Vue: 2.6.10
// kurento-utils: 6.15.0// 安装kurento-utils
npm install kurento-utils

二、代码

    1、JS封装

// Time:   2021/11/17 11:16
// Author: Dily
// Remark:
import kurentoUtils from 'kurento-utils'let websocket = null
let webRtcPeer = null
let video = null // DOM元素
let videourl = ''  // 视频流获取地址
let wssUrl = ''    // 连接后台websocket// 初始化
function initVideo(video_dom, wsUrl, videoUrl) {websocket = new WebSocket(wsUrl)wssUrl = wsUrlvideourl = videoUrlvideo = video_dom
}// 获取数据并播放
function playVideo(isAudio, isVideo) {websocket.onopen = () => getVideo(isAudio, isVideo)websocket.onerror = () => initVideo(video, wssUrl, videourl)websocket.onmessage = onMessage
}// 关闭websocket
function destroyVideo() {if (websocket) websocket.close()
}// 使用RTP获取视频流
function getVideo(isAudio, isVideo) {// Video and audio by defaultconst userMediaConstraints = {audio: isAudio,video: isVideo}const options = {remoteVideo: video,mediaConstraints: userMediaConstraints,onicecandidate: onIceCandidate}webRtcPeer = new kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly(options, error => {error ? console.error(error) : ''webRtcPeer.generateOffer(onOffer)})
}// candidate对象
function onIceCandidate(candidate) {const message = {id: 'onIceCandidate',candidate: candidate}sendMessage(message)
}// 开始请求数据
function onOffer(error, offerSdp) {error ? console.error('Error generating the offer :' + error) : ''const message = {id: 'start',sdpOffer: offerSdp,videoUrl: videourl}sendMessage(message)
}// 发送后台数据
function sendMessage(message) {const jsonMessage = JSON.stringify(message)websocket.send(jsonMessage)
}// 接收数据
function onMessage(message) {const parsedMessage = JSON.parse(message.data)switch (parsedMessage.id) {case 'startResponse':startResponse(parsedMessage)breakcase 'error':console.error('Error message from server: ' + parsedMessage.message)breakcase 'playEnd':console.log('playEnd')breakcase 'videoInfo':showVideoData(parsedMessage)breakcase 'iceCandidate':webRtcPeer.addIceCandidate(parsedMessage.candidate, error => error ? console.error(error) : '')breakcase 'position':document.getElementById('videoPosition').value = parsedMessage.positionbreakdefault:console.error('Unrecognized message: ' + parsedMessage.message)}
}// 接收视频流信息
function startResponse(message) {webRtcPeer.processAnswer(message.sdpAnswer, error => error ? console.error(error) : '')
}// 设置Seek
function showVideoData(parsedMessage) {document.getElementById('initSeek') ? document.getElementById('initSeek').value = parsedMessage.initSeekable : ''document.getElementById('endSeek') ? document.getElementById('endSeek').value = parsedMessage.endSeekable : ''document.getElementById('durations') ? document.getElementById('duration').value = parsedMessage.videoDuration : ''
}export {initVideo,playVideo,destroyVideo
}

 2、页面

<template><div class="dashboard-container"><video id="video" autoplay width="640px" height="480px" controls onseeking /></div>
</template>
<script type="module">
import { destroyVideo, initVideo, playVideo } from '@/utils/video-rtc'export default {name: 'Resource',data() {return {// HTTP环境wsUrl: 'ws://' + window.location.hostname + ':8082/kurento/player',// HTTPS环境// wsUrl: 'wss://' + window.location.hostname + ':8082/kurento/player',// 这里写自己的视频流地址,不同相机格式不同,这里是海康相机videoUrl: 'rtsp://用户名:密码@海康相机地址/:554/Streaming/Channels/101'}},mounted() {this.init()},beforeDestroy() {this.destroy()},methods: {init() {this.video = document.getElementById('video')initVideo(this.video, this.wsUrl, this.videoUrl)playVideo(true, true)},destroy() {destroyVideo()}}
}</script>
<style>
video {border-radius: 10px;width: 500px;height: 100%;border: 2px solid #124968;
}
</style>

三、后台代码
WebSocket RTP 视频实时监控https://blog.csdn.net/qq_42151956/article/details/121403771

Vue + RTP 视频实时监控相关推荐

  1. SpringBoot WebSocket RTP 视频实时监控

    一.环境        1.安装 // docker安装kurento docker pull kurento/kurento-media-server:latest// 配置端口, 占用50个端口, ...

  2. 在vue中使用海康插件实现视频实时监控(海康插件)

    在vue中使用海康插件实现视频实时监控(海康插件) 首先 下载并安装海康插件 webcontrol.exe 然后 直接就写代码把,所有方法都是海康他们直接封装好的demo 初始化之后,后台把密钥和一些 ...

  3. 海康摄像头视频实时监控

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 海康摄像 ...

  4. 【解决方案】基于EasyGBS搭建的移动终端视频实时监控国家安全局无线视频指挥系统技术方案

    一.方案背景 国家安全局是人民政府的一个组成部门,主管全市安全工作.在省委.省政府.市委.市政府和国家安全部的领导下,负责和管理地区防范.打击危害国家安全行为的工作,开展隐蔽战线的对敌斗争,保卫国家安 ...

  5. 树莓派搭建网络视频实时监控系统

    前言 在GitHub上发现一个好玩的项目,不用安装其它任何依赖包,只要运行一个Python脚本就可以在局域网构建一个视频监控系统.果断试了一下,确实挺好玩的,现在分享给大家. 搭建方法 1. 硬件准备 ...

  6. flv实现视频实时监控

    html代码: <div class="controls"><!--<button οnclick="flv_load()">加载 ...

  7. 基于android手机实时监控ipcam视频之一:RTSP

    我以前做过一个这样的项目,基于android实现手机实时监控ipcam,ipcam厂商提供控件,该控件安装以后,在IE上面输入ipcam的ip地址,就可以实时查看ipcam的图像,这实时视频是通过HT ...

  8. 前端实现播放实时监控视频笔记(hls http-flv)

    前言 最近被安排做一个数据可视化的项目,其中包括视频直播(实时监控)功能,于是只懂用 <video> 播放视频文件的我开始学习关于直播.实时播放等知识,在此做下笔记,并转发一些参考性文章. ...

  9. 实时监控后台数据 vue_实时数据监控,快速掌握B站爆款视频热度走向

    飞瓜数据B站版的数据监控功能提供对B站UP主监控功能,实时掌握UP主视频热度走向和投放效果. 通过监控输入B站视频链接,设定24/48时长开始对其监控.监控开始后在监控报告中查看对应视频的数据曲线变化 ...

最新文章

  1. SmartDispatcher 类
  2. 薪资被「倒挂」,别慌,咱们用实力说话
  3. 京东AI研究院计算机视觉实验室招聘研究型实习生
  4. Python核心编程(第二版)第六章部分习题代码
  5. draw.io二次开发(2)文件解读
  6. Mysql+innodb数据存储逻辑
  7. H.264(MPEG-4 AVC)级别(Level)、DPB 与 MaxDpbMbs 详解
  8. Maven的pom.xml文件详解------The Basics
  9. 【锁相环系列1】锁相环的基本原理
  10. mysql中最常用的存储引擎有_mysql常用的存储引擎有哪些
  11. cesium加载批量模型
  12. 看雪CTF.TSRC 2018 团队赛 第八题 『二向箔』 解题思路
  13. java实现视频格式转换
  14. ORACLE基础之oracle锁(oracle lock mode)详解
  15. 各种工作面板护眼模式颜色设置
  16. 什么是M1、M2以及与资本市场的关系
  17. hdu5285-wyh2000 and pupil-(染色法二分图判定)
  18. 宗地自动编号及属性赋值
  19. CISCO WLC的配置备份与导入
  20. 人生没有白走的路,走过的都算数

热门文章

  1. Java实现 LeetCode 502 IPO(LeetCode:我疯起来连自己都卖)
  2. 查看oracle操作日志
  3. APP开发流程注意事项有哪些
  4. 【报告分享】AIoT智能生活场景营销研究报告-小米中传(附下载)
  5. 安霸平台led芯片aw9523b调试
  6. MySQL 统计数量的方式 coutn(*) 和 count(1)
  7. 学习《新概念》的方法
  8. 考研公共部分科目分支分布以及计算机408分值分布
  9. wParam与 lParam
  10. 使用torch.autograd.function解决dist.all_gather不能反向传播问题