4
4
* @requires ui/Confirm
5
5
*/
6
6
var Confirm = require ( "ui/confirm.reel" ) . Confirm ,
7
+ AudioVideoRecorder = require ( "fielddb/api/audio_video/AudioVideoRecorder" ) . AudioVideoRecorder ,
7
8
Popup = require ( "matte/ui/popup/popup.reel" ) . Popup ;
8
9
10
+ var audioVideoRecorder = new AudioVideoRecorder ( ) ;
9
11
/**
10
12
* @class SoundCheck
11
13
* @extends Confirm
@@ -24,104 +26,15 @@ var SoundCheck = Confirm.specialize( /** @lends SoundCheck# */ {
24
26
} , {
25
27
microphoneCheck : {
26
28
value : function ( ) {
27
- this . periphialsCheck ( false ) ;
29
+ audioVideoRecorder . periphialsCheck ( false ) ;
28
30
}
29
31
} ,
30
32
videoCheck : {
31
33
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 ) ;
123
35
}
124
36
} ,
37
+
125
38
/**
126
39
Description TODO
127
40
@type {Function }
0 commit comments