forked from PhotoboothProject/photobooth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-preview.js
More file actions
163 lines (146 loc) · 5.19 KB
/
test-preview.js
File metadata and controls
163 lines (146 loc) · 5.19 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* globals photoboothTools photoboothPreview */
const photoboothPreviewTest = (function () {
const CameraDisplayMode = {
INIT: 1,
BACKGROUND: 2,
COUNTDOWN: 3,
TEST: 4
},
PreviewMode = {
NONE: 'none',
DEVICE: 'device_cam',
URL: 'url'
},
PreviewStyle = {
FILL: 'fill',
CONTAIN: 'contain',
COVER: 'cover',
NONE: 'none',
SCALE_DOWN: 'scale-down'
};
const api = {},
previewNone = $('#preview--none'),
previewIpcam = $('#preview--ipcam'),
previewVideo = $('#preview--video'),
previewFramePicture = $('#previewframe--picture'),
previewFrameCollage = $('#previewframe--collage'),
buttonStartPreview = $('[data-command="startPreview"]'),
buttonStopPreview = $('[data-command="stopPreview"]'),
buttonShowFramePicture = $('[data-command="showPictureFrame"]'),
buttonShowFrameCollage = $('[data-command="showCollageFrame"]'),
buttonHideFrame = $('[data-command="hideFrame"]');
let pid;
api.init = function () {
previewNone.show();
previewVideo.hide();
previewIpcam.hide();
previewFramePicture.hide();
previewFrameCollage.hide();
buttonStopPreview.hide();
buttonHideFrame.hide();
};
api.runCmd = function (mode) {
const dataVideo = {
play: mode,
pid: pid
};
jQuery
.post('../api/previewCamera.php', dataVideo)
.done(function (result) {
photoboothTools.console.log(dataVideo.play + ' webcam successfully.');
pid = result.pid;
})
// eslint-disable-next-line no-unused-vars
.fail(function (xhr, status, result) {
photoboothTools.console.log('Failed to ' + dataVideo.play + ' webcam!');
});
};
buttonStartPreview.on('click', (event) => {
event.preventDefault();
photoboothTools.console.log('Starting preview...');
buttonStartPreview.hide();
previewNone.hide();
if (config.commands.preview) {
photoboothTools.console.logDev('Running preview cmd (TEST).');
api.runCmd('start');
}
photoboothPreview.startVideo(CameraDisplayMode.TEST);
setTimeout(() => {
if (photoboothPreview.stream || config.preview.mode === PreviewMode.URL.valueOf()) {
buttonStopPreview.show();
} else {
buttonStartPreview.show();
}
}, 4000);
});
buttonStopPreview.on('click', (event) => {
event.preventDefault();
photoboothTools.console.log('Stopping preview...');
buttonStopPreview.hide();
previewFrameCollage.hide();
previewFramePicture.hide();
previewNone.show();
if (config.commands.preview_kill) {
api.runCmd('stop');
}
if (config.preview.mode === PreviewMode.DEVICE.valueOf()) {
photoboothPreview.stopVideo();
} else if (config.preview.mode === PreviewMode.URL.valueOf()) {
previewIpcam.removeClass('streaming');
previewIpcam.hide();
}
setTimeout(() => {
if (photoboothPreview.stream) {
buttonStopPreview.show();
} else {
buttonStartPreview.show();
}
}, 4000);
});
buttonShowFramePicture.on('click', (event) => {
event.preventDefault();
photoboothTools.console.log('Showing picture frame over the preview...');
previewFramePicture.show();
previewFrameCollage.hide();
buttonShowFramePicture.hide();
buttonShowFrameCollage.hide();
buttonHideFrame.show();
});
buttonShowFrameCollage.on('click', (event) => {
event.preventDefault();
photoboothTools.console.log('Showing collage frame over the preview...');
previewFrameCollage.show();
previewFramePicture.hide();
buttonShowFramePicture.hide();
buttonShowFrameCollage.hide();
buttonHideFrame.show();
});
buttonHideFrame.on('click', (event) => {
event.preventDefault();
photoboothTools.console.log('Hiding frames...');
previewFrameCollage.hide();
previewFramePicture.hide();
buttonShowFramePicture.show();
buttonShowFrameCollage.show();
buttonHideFrame.hide();
});
previewVideo.on('loadedmetadata', (event) => {
const videoEl = event.target;
let newWidth = videoEl.offsetWidth;
let newHeight = videoEl.offsetHeight;
if (config.preview.style === PreviewStyle.SCALE_DOWN.valueOf()) {
newWidth = videoEl.videoWidth;
newHeight = videoEl.videoHeight;
}
if (newWidth !== 0 && newHeight !== 0) {
previewFramePicture.css('width', newWidth);
previewFramePicture.css('height', newHeight);
previewFrameCollage.css('width', newWidth);
previewFrameCollage.css('height', newHeight);
}
});
return api;
})();
$(function () {
photoboothPreviewTest.init();
});