|
1 | 1 | <template>
|
2 |
| - <div class="container"> |
3 |
| - <div class="row"> |
4 |
| - <div class="col-md-6"> |
5 |
| - <h2>Current Camera</h2> |
6 |
| - <code v-if="device">{{ device.label }}</code> |
7 |
| - <div class="border"> |
8 |
| - <vue-web-cam ref="webcam" |
9 |
| - :device-id="deviceId" |
10 |
| - width="100%" |
11 |
| - @started="onStarted" |
12 |
| - @stopped="onStopped" |
13 |
| - @error="onError" |
14 |
| - @cameras="onCameras" |
15 |
| - @camera-change="onCameraChange" /> |
16 |
| - </div> |
17 |
| - |
| 2 | + <div class="container"> |
18 | 3 | <div class="row">
|
19 |
| - <div class="col-md-12"> |
20 |
| - <select v-model="camera"> |
21 |
| - <option>-- Select Device --</option> |
22 |
| - <option v-for="device in devices" |
23 |
| - :key="device.deviceId" |
24 |
| - :value="device.deviceId">{{ device.label }}</option> |
25 |
| - </select> |
26 |
| - </div> |
27 |
| - <div class="col-md-12"> |
28 |
| - <button type="button" |
29 |
| - class="btn btn-primary" |
30 |
| - @click="onCapture">Capture Photo</button> |
31 |
| - <button type="button" |
32 |
| - class="btn btn-danger" |
33 |
| - @click="onStop">Stop Camera</button> |
34 |
| - <button type="button" |
35 |
| - class="btn btn-success" |
36 |
| - @click="onStart">Start Camera</button> |
37 |
| - </div> |
| 4 | + <div class="col-md-6"> |
| 5 | + <h2>Current Camera</h2> |
| 6 | + <code v-if="device">{{ device.label }}</code> |
| 7 | + <div class="border"> |
| 8 | + <vue-web-cam |
| 9 | + ref="webcam" |
| 10 | + :device-id="deviceId" |
| 11 | + width="100%" |
| 12 | + @started="onStarted" |
| 13 | + @stopped="onStopped" |
| 14 | + @error="onError" |
| 15 | + @cameras="onCameras" |
| 16 | + @camera-change="onCameraChange" |
| 17 | + /> |
| 18 | + </div> |
| 19 | + |
| 20 | + <div class="row"> |
| 21 | + <div class="col-md-12"> |
| 22 | + <select v-model="camera"> |
| 23 | + <option>-- Select Device --</option> |
| 24 | + <option |
| 25 | + v-for="device in devices" |
| 26 | + :key="device.deviceId" |
| 27 | + :value="device.deviceId" |
| 28 | + >{{ device.label }}</option> |
| 29 | + </select> |
| 30 | + </div> |
| 31 | + <div class="col-md-12"> |
| 32 | + <button type="button" class="btn btn-primary" @click="onCapture">Capture Photo</button> |
| 33 | + <button type="button" class="btn btn-danger" @click="onStop">Stop Camera</button> |
| 34 | + <button type="button" class="btn btn-success" @click="onStart">Start Camera</button> |
| 35 | + </div> |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + <div class="col-md-6"> |
| 39 | + <h2>Captured Image</h2> |
| 40 | + <figure class="figure"> |
| 41 | + <img :src="img" class="img-responsive" /> |
| 42 | + </figure> |
| 43 | + </div> |
38 | 44 | </div>
|
39 |
| - </div> |
40 |
| - <div class="col-md-6"> |
41 |
| - <h2>Captured Image</h2> |
42 |
| - <figure class="figure"> |
43 |
| - <img :src="img" class="img-responsive" > |
44 |
| - </figure> |
45 |
| - </div> |
46 | 45 | </div>
|
47 |
| - </div> |
48 | 46 | </template>
|
49 | 47 |
|
50 | 48 | <script>
|
51 |
| -import { WebCam } from "vue-web-cam"; |
| 49 | +import { WebCam } from "../../src"; |
52 | 50 |
|
53 | 51 | export default {
|
54 |
| - name: "App", |
55 |
| - components: { |
56 |
| - "vue-web-cam": WebCam |
57 |
| - }, |
58 |
| - data() { |
59 |
| - return { |
60 |
| - img: null, |
61 |
| - camera: null, |
62 |
| - deviceId: null, |
63 |
| - devices: [] |
64 |
| - }; |
65 |
| - }, |
66 |
| - computed: { |
67 |
| - device: function() { |
68 |
| - return this.devices.find(n => n.deviceId === this.deviceId); |
69 |
| - } |
70 |
| - }, |
71 |
| - watch: { |
72 |
| - camera: function(id) { |
73 |
| - this.deviceId = id; |
74 |
| - }, |
75 |
| - devices: function() { |
76 |
| - // Once we have a list select the first one |
77 |
| - const [first, ...tail] = this.devices; |
78 |
| - if (first) { |
79 |
| - this.camera = first.deviceId; |
80 |
| - this.deviceId = first.deviceId; |
81 |
| - } |
82 |
| - } |
83 |
| - }, |
84 |
| - methods: { |
85 |
| - onCapture() { |
86 |
| - this.img = this.$refs.webcam.capture(); |
87 |
| - }, |
88 |
| - onStarted(stream) { |
89 |
| - console.log("On Started Event", stream); |
90 |
| - }, |
91 |
| - onStopped(stream) { |
92 |
| - console.log("On Stopped Event", stream); |
93 |
| - }, |
94 |
| - onStop() { |
95 |
| - this.$refs.webcam.stop(); |
| 52 | + name: "App", |
| 53 | + components: { |
| 54 | + "vue-web-cam": WebCam |
96 | 55 | },
|
97 |
| - onStart() { |
98 |
| - this.$refs.webcam.start(); |
| 56 | + data() { |
| 57 | + return { |
| 58 | + img: null, |
| 59 | + camera: null, |
| 60 | + deviceId: null, |
| 61 | + devices: [] |
| 62 | + }; |
99 | 63 | },
|
100 |
| - onError(error) { |
101 |
| - console.log("On Error Event", error); |
| 64 | + computed: { |
| 65 | + device: function() { |
| 66 | + return this.devices.find(n => n.deviceId === this.deviceId); |
| 67 | + } |
102 | 68 | },
|
103 |
| - onCameras(cameras) { |
104 |
| - this.devices = cameras; |
105 |
| - console.log("On Cameras Event", cameras); |
| 69 | + watch: { |
| 70 | + camera: function(id) { |
| 71 | + this.deviceId = id; |
| 72 | + }, |
| 73 | + devices: function() { |
| 74 | + // Once we have a list select the first one |
| 75 | + const [first, ...tail] = this.devices; |
| 76 | + if (first) { |
| 77 | + this.camera = first.deviceId; |
| 78 | + this.deviceId = first.deviceId; |
| 79 | + } |
| 80 | + } |
106 | 81 | },
|
107 |
| - onCameraChange(deviceId) { |
108 |
| - this.deviceId = deviceId; |
109 |
| - this.camera = deviceId; |
110 |
| - console.log("On Camera Change Event", deviceId); |
| 82 | + methods: { |
| 83 | + onCapture() { |
| 84 | + this.img = this.$refs.webcam.capture(); |
| 85 | + }, |
| 86 | + onStarted(stream) { |
| 87 | + console.log("On Started Event", stream); |
| 88 | + }, |
| 89 | + onStopped(stream) { |
| 90 | + console.log("On Stopped Event", stream); |
| 91 | + }, |
| 92 | + onStop() { |
| 93 | + this.$refs.webcam.stop(); |
| 94 | + }, |
| 95 | + onStart() { |
| 96 | + this.$refs.webcam.start(); |
| 97 | + }, |
| 98 | + onError(error) { |
| 99 | + console.log("On Error Event", error); |
| 100 | + }, |
| 101 | + onCameras(cameras) { |
| 102 | + this.devices = cameras; |
| 103 | + console.log("On Cameras Event", cameras); |
| 104 | + }, |
| 105 | + onCameraChange(deviceId) { |
| 106 | + this.deviceId = deviceId; |
| 107 | + this.camera = deviceId; |
| 108 | + console.log("On Camera Change Event", deviceId); |
| 109 | + } |
111 | 110 | }
|
112 |
| - } |
113 | 111 | };
|
114 | 112 | </script>
|
0 commit comments