fffiloni commited on
Commit
61538ff
1 Parent(s): f1103cb

add rear cam on mobile

Browse files
Files changed (1) hide show
  1. public/sketch.js +75 -1
public/sketch.js CHANGED
@@ -14,10 +14,23 @@ let messages_list = []
14
  let timerWaiting;
15
  let waiting = false;
16
 
 
 
 
 
 
 
 
 
 
17
  //-----------------------------------------------------
18
  //-----------------------------------------------------
19
 
20
  function preload(){
 
 
 
 
21
  // Socket events handlers
22
  socket = io();
23
  // client-side
@@ -100,9 +113,69 @@ function setup() {
100
  // Buttons
101
  start_capture_button=createButton("turn on cam")
102
  start_capture_button.mousePressed(() => {
103
- capture = createCapture(VIDEO);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  capture.hide();
105
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
  start_button = createButton('start live vision');
108
  start_button.mousePressed(() => {
@@ -124,6 +197,7 @@ function setup() {
124
  if(capture){
125
  capture.remove();
126
  capture = undefined
 
127
  }
128
  console.log("live is OFF")
129
  //redraw()
 
14
  let timerWaiting;
15
  let waiting = false;
16
 
17
+ let active_rearcam = false;
18
+ let camConfig = "user";
19
+ let isOnMobile;
20
+ let camIsON = false;
21
+
22
+ function isMobileDevice() {
23
+ return (typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1);
24
+ }
25
+
26
  //-----------------------------------------------------
27
  //-----------------------------------------------------
28
 
29
  function preload(){
30
+
31
+ isOnMobile = isMobileDevice()
32
+ console.log("is on mobile ? " + isOnMobile)
33
+
34
  // Socket events handlers
35
  socket = io();
36
  // client-side
 
113
  // Buttons
114
  start_capture_button=createButton("turn on cam")
115
  start_capture_button.mousePressed(() => {
116
+ camIsON = true;
117
+ if(!active_rearcam){
118
+ camConfig = "user"
119
+ } else {
120
+ camConfig = {
121
+ exact: "environment"
122
+ }
123
+ }
124
+ let constraints = {
125
+ audio: false,
126
+ video: {
127
+ facingMode: camConfig
128
+ }
129
+ };
130
+ capture = createCapture(constraints);
131
  capture.hide();
132
  })
133
+
134
+ if(isOnMobile){
135
+ checkbox_rearcam = createCheckbox("switch to rear cam");
136
+ checkbox_rearcam.parent("checkbox-rear");
137
+
138
+ checkbox_rearcam.mousePressed( () => {
139
+ if(active_rearcam == false){
140
+ active_rearcam = true;
141
+ } else {
142
+ active_rearcam = false
143
+ }
144
+
145
+ if(camIsON){
146
+ if(capture){
147
+ capture.remove()
148
+ capture = undefined
149
+ }
150
+
151
+ if(active_rearcam == true){
152
+ let new_constraints = {
153
+ audio: false,
154
+ video: {
155
+ facingMode: {
156
+ exact: "environment"
157
+ }
158
+ }
159
+ };
160
+ capture = createCapture(new_constraints)
161
+ capture.hide()
162
+ } else {
163
+ let new_constraints = {
164
+ audio: false,
165
+ video: {
166
+ facingMode: "user"
167
+ }
168
+ //video: {
169
+ //facingMode: "user"
170
+ //}
171
+ };
172
+ capture = createCapture(new_constraints)
173
+ capture.hide()
174
+ }
175
+ }
176
+ })
177
+
178
+ }
179
 
180
  start_button = createButton('start live vision');
181
  start_button.mousePressed(() => {
 
197
  if(capture){
198
  capture.remove();
199
  capture = undefined
200
+ camIsON = false;
201
  }
202
  console.log("live is OFF")
203
  //redraw()