1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
| <template>
| <div class="video-player">
| <video ref="videoPlayer" poster="../../assets/baseimg.png" preload="auto"></video>
| <div class="controls">
| <!-- 全屏 -->
| <i class="el-icon-full-screen" @click="fullScreen"></i>
| </div>
| </div>
| </template>
| <script>
| import Wfs from "./wfs";
| export default {
| name: "CameraPlayer",
| props: {
| wsAddr: {
| type: String,
| // default: "ws://192.168.1.182:10101/ws"
| default: `${location.protocol === "https" ? "wss" : "ws"}://${
| location.host
| }/ws`
| },
| cameraName: {
| type: String,
| default: ""
| },
| cameraID: {
| type: String,
| default: "C4668FD0-3CAE-C31F-C21E-28B7001243C4"
| },
| rtspUrl: {
| type: String,
| default: "rtsp://admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream"
| },
| isRunning: {
| type: Boolean,
| default: false
| },
| isGb: {
| type: Boolean,
| default: false
| }
| },
| watch: {
| rtspUrl: function(newVal, oldVal) {
| if (newVal !== oldVal) {
| if (this.wfs.config) {
| this.wfs.destroy();
| }
| this.$nextTick(() => {
| this.clickStart();
| });
| }
| }
| },
| data() {
| return {
| wfs: {}
| };
| },
| methods: {
| clickStart() {
| if (this.rtspUrl == "") {
| return;
| }
|
| let cameraId = this.cameraID;
| if (cameraId == "") {
| cameraId = this.getUuid();
| }
|
| if (Wfs.isSupported()) {
| let wsAddr = this.wsAddr;
| let cameraInfo = {
| cameraID: cameraId,
| rtspUrl: this.rtspUrl,
| isRunning: this.isRunning,
| isGb28181: this.isGb
| };
|
| // let camera = document.getElementById(this.cameraID);
| let camera = this.$refs.videoPlayer;
| this.wfs = new Wfs();
| this.wfs.attachMedia(camera, "chX", "H264Raw", wsAddr, cameraInfo);
| }
| },
| getUuid() {
| var s = [];
| var hexDigits = "0123456789abcdefghijkopqrst";
| for (var i = 0; i < 36; i++) {
| s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
| }
| s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
| s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
| s[8] = s[13] = s[18] = s[23] = "-";
| var uuid = s.join("");
| return uuid;
| },
| fullScreen() {
| this.$refs.videoPlayer.webkitRequestFullScreen();
| }
| },
| mounted() {
| this.clickStart();
| },
| beforeDestroy() {
| this.wfs.destroy();
| }
| };
| </script>
|
| <style lang="scss">
| video {
| object-fit: fill;
| width: 100%;
| height: 100%;
| }
| .video-player {
| width: 100%;
| height: 100%;
| .controls {
| position: absolute;
| bottom: 0%;
| color: #95b7ff;
| width: 100%;
| height: 22px;
| line-height: 22px;
| padding: 0px 20px;
| box-sizing: border-box;
| background: #27293190;
| display: none;
| text-align: right;
|
| i {
| cursor: pointer;
| }
| i:hover {
| -moz-box-shadow: 2px 2px 7px #000;
| -webkit-box-shadow: 2px 2px 7px #000;
| box-shadow: 2px 2px 7px #000;
| }
| }
| }
|
| .video-player:hover {
| .controls {
| display: block;
| }
| }
| </style>
|
|