Skip to content

Commit 2647efa

Browse files
authored
Merge pull request #6 from dodortus/feature/refactor
Feature/refactor
2 parents e007ad7 + 8031981 commit 2647efa

File tree

9 files changed

+619
-587
lines changed

9 files changed

+619
-587
lines changed

frontend/views/examples/capture/index.ejs

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,78 +16,81 @@
1616
<hr />
1717

1818
<div id="output">
19-
<strong>Capture images</strong>
19+
<strong>Capture images (아래 캡쳐된 이미지를 클릭하면 다운로드 할 수 있습니다)</strong>
2020
<div id="images"></div>
2121
</div>
2222

2323
<pre>
24-
<code class="highlight">$(function() {
25-
const videoEl = document.getElementById('video');
26-
const canvasEl = document.getElementById('canvas');
27-
const width = 350;
28-
const height = 260;
24+
<code class="highlight">const $video = document.getElementById('video');
25+
const $canvas = document.getElementById('canvas');
26+
const width = 350;
27+
const height = 260;
2928

30-
/**
31-
* getUserMedia 성공
32-
* @param stream
33-
*/
34-
function success(stream) {
35-
videoEl.srcObject = stream;
36-
}
29+
/**
30+
* 비디오 이미지 캡쳐
31+
*/
32+
function capture() {
33+
const context = $canvas.getContext('2d');
34+
context.drawImage($video, 0, 0, width, height);
35+
insertImage($canvas.toDataURL('image/png'));
36+
}
3737

38-
/**
39-
* getUserMedia 실패
40-
* @param err
41-
*/
42-
function error(err) {
43-
console.log('error', arguments);
44-
}
38+
/**
39+
* 캡쳐한 이미지 노출 함수
40+
* @param imageData
41+
*/
42+
function insertImage(imageData) {
43+
const $images = document.querySelector('#images');
44+
const $img = document.createElement('img');
4545

46-
/**
47-
* 비디오 이미지 캡쳐
48-
*/
49-
function capture() {
50-
const context = canvasEl.getContext('2d');
51-
context.drawImage(videoEl, 0, 0, width, height);
52-
insertImage(canvasEl.toDataURL('image/png'));
53-
}
46+
$img.src = imageData;
47+
$images.insertBefore($img, $images.childNodes[0]);
48+
}
5449

55-
/**
56-
* 캡쳐한 이미지 노출 함수
57-
* @param imageData
58-
*/
59-
function insertImage(imageData) {
60-
$('#images').prepend("&lt;img src=" + imageData + " /&gt;");
61-
}
50+
/**
51+
* getUserMedia 성공
52+
* @param stream
53+
*/
54+
function success(stream) {
55+
$video.srcObject = stream;
56+
}
57+
58+
/**
59+
* getUserMedia 실패
60+
* @param err
61+
*/
62+
function error(err) {
63+
console.log('error', err);
64+
alert(err.message);
65+
}
6266

63-
/**
64-
* 미디어 호출
65-
*/
66-
async function startMedia() {
67-
try {
68-
const stream = await navigator.mediaDevices.getUserMedia({
69-
audio: false,
70-
video: true,
71-
});
72-
success(stream);
73-
} catch (err) {
74-
error(err);
75-
}
67+
/**
68+
* 미디어 호출
69+
*/
70+
async function startMedia() {
71+
try {
72+
const stream = await navigator.mediaDevices.getUserMedia({
73+
audio: false,
74+
video: true,
75+
});
76+
success(stream);
77+
} catch (err) {
78+
error(err);
7679
}
80+
}
7781

78-
/**
79-
* 초기 이벤트 바인딩
80-
*/
81-
function initialize() {
82-
canvasEl.width = width;
83-
canvasEl.height = height;
82+
/**
83+
* 초기 이벤트 바인딩
84+
*/
85+
function initialize() {
86+
$canvas.width = width;
87+
$canvas.height = height;
8488

85-
$('#btn-camera').click(startMedia);
86-
$('#btn-capture').click(capture);
87-
}
89+
document.querySelector('#btn-camera').addEventListener('click', startMedia);
90+
document.querySelector('#btn-capture').addEventListener('click', capture);
91+
}
8892

89-
initialize();
90-
});
93+
initialize();
9194
</code>
9295
</pre>
9396
</div>
Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,76 @@
1-
$(function () {
2-
const videoEl = document.getElementById('video');
3-
const canvasEl = document.getElementById('canvas');
4-
const width = 350;
5-
const height = 260;
1+
const $video = document.getElementById('video');
2+
const $canvas = document.getElementById('canvas');
3+
const width = 350;
4+
const height = 260;
65

7-
/**
8-
* getUserMedia 성공
9-
* @param stream
10-
*/
11-
function success(stream) {
12-
videoEl.srcObject = stream;
13-
}
6+
/**
7+
* 비디오 이미지 캡쳐
8+
*/
9+
function capture() {
10+
const context = $canvas.getContext('2d');
11+
context.drawImage($video, 0, 0, width, height);
12+
insertImage($canvas.toDataURL('image/png'));
13+
}
1414

15-
/**
16-
* getUserMedia 실패
17-
* @param err
18-
*/
19-
function error(err) {
20-
console.log('error', err);
21-
alert(err.message);
22-
}
15+
/**
16+
* 캡쳐한 이미지 노출 함수
17+
* @param imageData
18+
*/
19+
function insertImage(imageData) {
20+
const $images = document.querySelector('#images');
21+
const $img = document.createElement('img');
22+
const $a = document.createElement('a');
23+
const fileName = `[WebRTC 연구실] Capture - ${new Date().getTime()}`;
2324

24-
/**
25-
* 비디오 이미지 캡쳐
26-
*/
27-
function capture() {
28-
const context = canvasEl.getContext('2d');
29-
context.drawImage(videoEl, 0, 0, width, height);
30-
insertImage(canvasEl.toDataURL('image/png'));
31-
}
25+
$img.src = imageData;
26+
$a.href = imageData;
27+
$a.download = fileName;
28+
$a.appendChild($img);
3229

33-
/**
34-
* 캡쳐한 이미지 노출 함수
35-
* @param imageData
36-
*/
37-
function insertImage(imageData) {
38-
$('#images').prepend('<img src=' + imageData + ' />');
39-
}
30+
$images.insertBefore($a, $images.childNodes[0]);
31+
}
4032

41-
/**
42-
* 미디어 호출
43-
*/
44-
async function startMedia() {
45-
try {
46-
const stream = await navigator.mediaDevices.getUserMedia({
47-
audio: false,
48-
video: true,
49-
});
50-
success(stream);
51-
} catch (err) {
52-
error(err);
53-
}
54-
}
33+
/**
34+
* getUserMedia 성공
35+
* @param stream
36+
*/
37+
function success(stream) {
38+
$video.srcObject = stream;
39+
}
5540

56-
/**
57-
* 초기 이벤트 바인딩
58-
*/
59-
function initialize() {
60-
canvasEl.width = width;
61-
canvasEl.height = height;
41+
/**
42+
* getUserMedia 실패
43+
* @param err
44+
*/
45+
function error(err) {
46+
console.log('error', err);
47+
alert(err.message);
48+
}
6249

63-
$('#btn-camera').click(startMedia);
64-
$('#btn-capture').click(capture);
50+
/**
51+
* 미디어 호출
52+
*/
53+
async function startMedia() {
54+
try {
55+
const stream = await navigator.mediaDevices.getUserMedia({
56+
audio: false,
57+
video: true,
58+
});
59+
success(stream);
60+
} catch (err) {
61+
error(err);
6562
}
63+
}
64+
65+
/**
66+
* 초기 이벤트 바인딩
67+
*/
68+
function initialize() {
69+
$canvas.width = width;
70+
$canvas.height = height;
71+
72+
document.querySelector('#btn-camera').addEventListener('click', startMedia);
73+
document.querySelector('#btn-capture').addEventListener('click', capture);
74+
}
6675

67-
initialize();
68-
});
76+
initialize();

frontend/views/examples/conference/css/main.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ input[type='text'] {
3535
vertical-align: top;
3636
}
3737

38+
#create-wrap {
39+
overflow: hidden;
40+
max-height: 200px;
41+
transition: all 0.3s ease-out;
42+
}
43+
44+
#create-wrap.slideup {
45+
max-height: 0;
46+
}
47+
3848
/********************************************
3949
Below room style
4050
*********************************************/

0 commit comments

Comments
 (0)