fffiloni commited on
Commit
d01d0c9
1 Parent(s): f351f64

Update public/sketch.js

Browse files
Files changed (1) hide show
  1. public/sketch.js +95 -9
public/sketch.js CHANGED
@@ -18,6 +18,7 @@ let active_rearcam = false;
18
  let camConfig = "user";
19
  let isOnMobile;
20
  let camIsON = false;
 
21
 
22
  let graphicsToSend;
23
 
@@ -32,6 +33,12 @@ function preload(){
32
 
33
  isOnMobile = isMobileDevice()
34
  console.log("is on mobile ? " + isOnMobile)
 
 
 
 
 
 
35
 
36
  // Socket events handlers
37
  socket = io();
@@ -75,6 +82,42 @@ function windowResized() {
75
  }
76
 
77
  function setup() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  pixelDensity(1)
79
  if(windowWidth <= 500){
80
  myCanvas = createCanvas(380, 380*320/576);
@@ -156,10 +199,11 @@ function setup() {
156
  checkbox_rearcam.parent("checkbox-rear");
157
 
158
  checkbox_rearcam.mousePressed( () => {
 
159
  if(active_rearcam == false){
160
  active_rearcam = true;
161
  } else {
162
- active_rearcam = false
163
  }
164
 
165
  if(camIsON){
@@ -184,7 +228,7 @@ function setup() {
184
  audio: false,
185
  video: {
186
  facingMode: "user"
187
- }
188
  //video: {
189
  //facingMode: "user"
190
  //}
@@ -246,18 +290,62 @@ function draw() {
246
  text('turn on your webcam', width/2, height/2);
247
 
248
  if(capture != undefined){
249
- graphicsToSend.image(capture, 0, 0)
250
  if(!active_rearcam){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  push()
252
  //move image by the width of image to the left
253
- translate(capture.width, 0);
254
- //then scale it by -1 in the x-axis
 
255
  //to flip the image
256
  scale(-1, 1);
257
- image(capture,0, 0)
258
  pop()
 
 
259
  } else {
260
- image(capture,0, 0)
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  }
262
 
263
  }
@@ -355,5 +443,3 @@ function show_loading(){
355
 
356
 
357
  }
358
-
359
-
 
18
  let camConfig = "user";
19
  let isOnMobile;
20
  let camIsON = false;
21
+ let device_orientation;
22
 
23
  let graphicsToSend;
24
 
 
33
 
34
  isOnMobile = isMobileDevice()
35
  console.log("is on mobile ? " + isOnMobile)
36
+
37
+ if(isOnMobile){
38
+ device_orientation = screen.orientation.type;
39
+ }
40
+
41
+
42
 
43
  // Socket events handlers
44
  socket = io();
 
82
  }
83
 
84
  function setup() {
85
+
86
+ screen.orientation.addEventListener("change", function(e) {
87
+ device_orientation = screen.orientation.type
88
+ console.log(device_orientation)
89
+ if(camIsON){
90
+ if(capture){
91
+ capture.remove()
92
+ capture = undefined
93
+ }
94
+
95
+ if(active_rearcam == true){
96
+ let new_constraints = {
97
+ audio: false,
98
+ video: {
99
+ facingMode: {
100
+ exact: "environment"
101
+ }
102
+ }
103
+ };
104
+ capture = createCapture(new_constraints)
105
+ capture.hide()
106
+ } else {
107
+ let new_constraints = {
108
+ audio: false,
109
+ video: {
110
+ facingMode: "user"
111
+ }
112
+ //video: {
113
+ //facingMode: "user"
114
+ //}
115
+ };
116
+ capture = createCapture(new_constraints)
117
+ capture.hide()
118
+ }
119
+ }
120
+ });
121
  pixelDensity(1)
122
  if(windowWidth <= 500){
123
  myCanvas = createCanvas(380, 380*320/576);
 
199
  checkbox_rearcam.parent("checkbox-rear");
200
 
201
  checkbox_rearcam.mousePressed( () => {
202
+
203
  if(active_rearcam == false){
204
  active_rearcam = true;
205
  } else {
206
+ active_rearcam = false
207
  }
208
 
209
  if(camIsON){
 
228
  audio: false,
229
  video: {
230
  facingMode: "user"
231
+ }
232
  //video: {
233
  //facingMode: "user"
234
  //}
 
290
  text('turn on your webcam', width/2, height/2);
291
 
292
  if(capture != undefined){
293
+
294
  if(!active_rearcam){
295
+
296
+
297
+ if(isOnMobile){
298
+ if(device_orientation == "portrait" || device_orientation == "portrait-primary" || device_orientation == "portrait-secondary"){
299
+ graphicsToSend.image(capture,(myCanvas.width/2)-(capture.width/2), -(capture.height/4))
300
+ push()
301
+ //move image by the width of image to the left
302
+ translate(myCanvas.width, 0);
303
+ //then scale push()
304
+ //move image by the width of image to the left
305
+ //to flip the image
306
+ scale(-1, 1);
307
+ image(capture,(myCanvas.width/2)-(capture.width/2), -(capture.height/4))
308
+ pop()
309
+ } else {
310
+ graphicsToSend.image(capture, 0, 0)
311
+ push()
312
+ //move image by the width of image to the left
313
+ translate(myCanvas.width, 0);
314
+ //then scale push()
315
+ //move image by the width of image to the left
316
+ //to flip the image
317
+ scale(-1, 1);
318
+ image(capture, 0, 0)
319
+ pop()
320
+ }
321
+ } else {
322
+ graphicsToSend.image(capture, 0, 0)
323
  push()
324
  //move image by the width of image to the left
325
+ translate(myCanvas.width, 0);
326
+ //then scale push()
327
+ //move image by the width of image to the left
328
  //to flip the image
329
  scale(-1, 1);
330
+ image(capture, 0, 0)
331
  pop()
332
+ }
333
+
334
  } else {
335
+ if(isOnMobile){
336
+ if(device_orientation == "portrait" || device_orientation == "portrait-primary" || device_orientation == "portrait-secondary"){
337
+ graphicsToSend.image(capture,(myCanvas.width/2)-(capture.width/2), -(capture.height/4))
338
+ image(capture,(myCanvas.width/2)-(capture.width/2), -(capture.height/4))
339
+ } else {
340
+ graphicsToSend.image(capture, 0, 0)
341
+ image(capture, 0, 0)
342
+
343
+
344
+ }
345
+ } else {
346
+ graphicsToSend.image(capture, 0, 0)
347
+ image(capture, 0, 0)
348
+ }
349
  }
350
 
351
  }
 
443
 
444
 
445
  }