🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

webrtclib

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webrtclib

a webrtc lib for vue

0.1.10
latest
npm
Version published
Weekly downloads
2
-84.62%
Maintainers
1
Weekly downloads
 
Created
Source

webrtclib

一个webrtc的vue前端实现,支持截图和录像,后端代码暂未发布

npm导入

npm install webrtclib

引入组件

import videoWebrtc from "webrtclib";
import "webrtclib/lib/videoWebrtc.css"

Vue.use(videoWebrtc);

使用

<video-webrtc
        :server="server"
        :stun="stun"
        :sid="sid"
        :orgId="orgId"
        @saveVideo="saveVideo"
        @capture="capture"
      ></video-webrtc>

参数说明

参数类型类型解释
server必传String服务地址
stun必传Stringice协议服务地址
sid必传[Number, String]直播时候传入的设备id
orgId必传[Number, String]直播时候传入的组织ID
custTime非必传[Number, String]录像时间(秒),默认5分钟,最大1小时
saveVideo非必传回调方法返回录像地址url
capture非必传回调方法返回截图文件base64

tips

录像需要配置proxy

 proxy: {
      "/webrtcApi": {
        target: "http://ip:port", // 目标接口域名
        pathRewrite: {
          "^/webrtcApi": ""
        },
        changeOrigin: true // 是否跨域
      }
    }

demo参考

<template>
  <div class="home">
    <div class="video" v-for="item in arr" :key="item">
      <video-webrtc
        :server="server"
        :stun="stun"
        :sid="sid"
        :orgId="orgId"
        @saveVideo="saveVideo"
        @capture="capture"
      ></video-webrtc>
    </div>
    <div class="dialog-mask" v-if="imgCapture" @click="imgCapture = null"></div>
    <div class="dilog" v-if="imgCapture">
      <img v-if="imgCapture" :src="imgCapture" alt="" />
    </div>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      arr: [1, 2, 3, 4, 5, 6, 7, 8, 9],
      stun: "stun://ip:port",
      server: "ws://ip:port/wsrtc",
      sid: "摄像头ID",
      orgId: "组织ID"
      imgCapture: ""
    };
  },
  methods: {
    // 截图
    capture(val) {
      console.log(val);
      this.imgCapture = val;
    },
    // 录像
    saveVideo(val) {
      console.log(val);
    }
  }
};
</script>
<style>
.home {
  display: flex;
  flex-wrap: wrap;
}
.video {
  width: 320px;
  height: 180px;
  position: relative;
  margin: 10px;
}
.dialog-mask {
  position: absolute;
  z-index: 1001;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: #00000090;
}
.dilog {
  position: absolute;
  z-index: 1001;
  width: 80%;
  left: 10%;
  top: 10%;
  padding: 20px;
  background-color: #fff;
}
</style>


Keywords

webrtc

FAQs

Package last updated on 02 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts