Skip to content

Commit 397ff96

Browse files
committed
moving peripherals check to fielddb
1 parent 6e939d2 commit 397ff96

File tree

1 file changed

+5
-92
lines changed

1 file changed

+5
-92
lines changed

Diff for: ui/sound-check.reel/sound-check.js

+5-92
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
* @requires ui/Confirm
55
*/
66
var Confirm = require("ui/confirm.reel").Confirm,
7+
AudioVideoRecorder = require("fielddb/api/audio_video/AudioVideoRecorder").AudioVideoRecorder,
78
Popup = require("matte/ui/popup/popup.reel").Popup;
89

10+
var audioVideoRecorder = new AudioVideoRecorder();
911
/**
1012
* @class SoundCheck
1113
* @extends Confirm
@@ -24,104 +26,15 @@ var SoundCheck = Confirm.specialize( /** @lends SoundCheck# */ {
2426
}, {
2527
microphoneCheck: {
2628
value: function() {
27-
this.periphialsCheck(false);
29+
audioVideoRecorder.periphialsCheck(false);
2830
}
2931
},
3032
videoCheck: {
3133
value: function() {
32-
this.periphialsCheck(true);
33-
}
34-
},
35-
periphialsCheck: {
36-
value: function(withVideo) {
37-
var application = this.application;
38-
var waitUntilVideoElementIsRendered = function() {
39-
40-
/* access camera and microphone
41-
http://www.html5rocks.com/en/tutorials/getusermedia/intro/
42-
*/
43-
navigator.getUserMedia = navigator.getUserMedia ||
44-
navigator.webkitGetUserMedia ||
45-
navigator.mozGetUserMedia ||
46-
navigator.msGetUserMedia;
47-
48-
if (navigator.getUserMedia) {
49-
console.log("hasGetUserMedia");
50-
51-
var video = document.getElementById("video-preview");
52-
var canvas = document.getElementById("video-snapshot-canvas");
53-
var snapshotImage = document.getElementById("video-snapshot");
54-
if (!canvas) {
55-
console.warn("video-snapshot-canvas is not present, cant verify periphialsCheck");
56-
return;
57-
}
58-
canvas.width = 640;
59-
canvas.height = 360;
60-
var ctx = canvas.getContext("2d");
61-
62-
63-
var errorCallback = function(e) {
64-
console.log("User refused access to camera and microphone!", e);
65-
};
66-
67-
navigator.getUserMedia({
68-
video: {
69-
mandatory: {
70-
maxWidth: canvas.width,
71-
maxHeight: canvas.height
72-
}
73-
},
74-
audio: true,
75-
geolocation: true
76-
},
77-
function(localMediaStream) {
78-
if (withVideo) {
79-
video.removeAttribute("hidden");
80-
snapshotImage.removeAttribute("hidden");
81-
}
82-
video.src = window.URL.createObjectURL(localMediaStream);
83-
84-
var takeSnapshot = function takeSnapshot() {
85-
if (localMediaStream) {
86-
ctx.drawImage(video, 0, 0);
87-
// "image/webp" works in Chrome.
88-
// Other browsers will fall back to image/png.
89-
snapshotImage.src = canvas.toDataURL("image/webp");
90-
}
91-
};
92-
video.addEventListener("click", takeSnapshot, false);
93-
94-
95-
// Note: onloadedmetadata doesn't fire in Chrome when using it with getUserMedia.
96-
// See crbug.com/110938.
97-
video.onloadedmetadata = function(e) {
98-
// Ready to go. Do some stuff.
99-
console.log("Video preview is working, take note of this in application so user can continue to the game.");
100-
application.videoRecordingVerified = true;
101-
102-
navigator.geolocation.getCurrentPosition(function(position) {
103-
console.warn("recieved position information");
104-
if (FieldDB && FieldDB.FieldDBObject) {
105-
FieldDB.FieldDBObject.software = FieldDB.FieldDBObject.software || {};
106-
FieldDB.FieldDBObject.software.location = position.coords;
107-
}
108-
});
109-
};
110-
},
111-
errorCallback
112-
);
113-
114-
} else {
115-
alert("The Microphone is not supported in your browser");
116-
}
117-
};
118-
if (!document.getElementById("video-preview")) {
119-
window.setTimeout(waitUntilVideoElementIsRendered, 2000);
120-
} else {
121-
waitUntilVideoElementIsRendered();
122-
}
34+
audioVideoRecorder.periphialsCheck(true);
12335
}
12436
},
37+
12538
/**
12639
Description TODO
12740
@type {Function}

0 commit comments

Comments
 (0)