-
Notifications
You must be signed in to change notification settings - Fork 19
/
scriptcamlite.js
155 lines (145 loc) · 4.96 KB
/
scriptcamlite.js
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
// _____ _ _ _____
// / ___| (_) | | / __ \ L.I.T.E
// \ `--. ___ _ __ _ _ __ | |_| / \/
// `--. \/ __| '__| | '_ \| __| | / _` | '_ ` _ \
// /\__/ / (__| | | | |_) | |_| \__/\ (_| | | | | | |
// \____/ \___|_| |_| .__/ \__|\____/\__,_|_| |_| |_|
// | |
// Version 1.6.0 |_| (c) Tele-Line Videotex Services
// Use jscompress.com to compress this file
;(function($) {
$.fn.scriptcamlite=function(options) {
// merge passed options with default values
var opts=$.extend({}, $.fn.scriptcamlite.defaults, options);
// off we go
return this.each(function() {
data=opts; // pass options to jquery internal data field to make them available to the outside world
data.path=decodeURIComponent(data.path); // convert URI back to normal string
if (window.File && window.FileReader && window.FileList && window.Blob) {
if (data.fileName!='') {
// check filename
if (data.fileName != filterCharacters(data.fileName)) {
data.onError(5,"Illegal filename specified");
return;
}
data.fileName=randomNumber() + "_" + data.fileName;
data.country=data.country.toLowerCase();
if (data.country !="europe" && data.country !="usa") {
data.country="europe";
}
if (data.maximumSize < 10) {
data.maximumSize = 10;
}
if (data.maximumSize > 500) {
data.maximumSize = 500;
}
$('body').append('<div style="width: 0; height: 0; overflow: hidden;"><form><input type="file" id="videoupload" accept="video/*" capture></form></div><div id="progressNumber"></div>');
$('#videoupload').on('change', function(e) {
e.preventDefault();
var file = document.getElementById('videoupload').files[0];
if (file.size > 1000000 * data.maximumSize) {
data.onError(2,"File too large");
return;
}
var fd = new FormData();
fd.append("video", file);
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("POST", "http://"+data.country+".www.scriptcam.com/mobile/upload.cfm?filename=" + data.fileName);
xhr.send(fd);
});
function uploadProgress(evt) {
if (evt.lengthComputable) {
var percentComplete = Math.round(evt.loaded * 100 / evt.total);
data.uploadProgress(percentComplete);
}
else {
data.uploadProgress(0);
}
}
function uploadComplete(evt) {
data.fileConversionStarted(evt.target.response);
checkServerForFile(data.country,evt.target.response);
}
function uploadFailed(evt) {
data.onError(3,"Upload failed");
}
function uploadCanceled(evt) {
data.onError(4,"Upload cancelled");
}
function randomNumber() {
var low=1000000;
var high=9999999;
return Math.floor(Math.random()* (high-low)) +low;
}
function filterCharacters(str) {
var filter="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_";
var char_array = new Array ();
for (var i = 0; i < str.length; i ++) {
var cc = str.charAt (i);
if (filter.indexOf (cc) != - 1) {
char_array.push (cc);
}
}
return char_array.join ('');
};
function checkServerForFile(country,fileName) {
$.ajax({
type:"HEAD",
cache: false,
url: "http://" + country + ".www.scriptcam.com/dwnld/" + fileName + ".mp4",
success: function (result) {
data.fileReady("http://"+country+".www.scriptcam.com/dwnld/"+fileName+".mp4");
},
error:function (xhr, ajaxOptions, thrownError){
setTimeout(function() {
checkServerForFile(country,fileName);
}, 2000)
}
});
}
}
else {
$('body').append('<div style="width: 0; height: 0; overflow: hidden;"><form><input type="file" id="pictureupload" accept="image/*" capture></form></div>');
$('#pictureupload').on('change', function(e) {
e.preventDefault();
if ( this.files && this.files[0] ) {
var FR= new FileReader();
FR.onload = function(e) {
s=e.target.result;
data.onPictureAsBase64(s);
};
FR.readAsDataURL(this.files[0]);
}
});
}
}
else {
data.onError(1,"HTML5 not fully supported");
}
});
};
$.scriptcamlite={};
// outgoing functions
$.scriptcamlite.getFrameAsBase64=function() {
$('#pictureupload').trigger('click');
}
$.scriptcamlite.version=function() {
return "1.6.0";
}
$.scriptcamlite.startRecording=function() {
$('#videoupload').trigger('click');
}
$.scriptcamlite.playMP3=function(value) {
alert("playMP3 called");
}
// set javascript default values
$.fn.scriptcamlite.defaults={
maximumSize:500,
fileName:'',
country:'europe'
};
})(jQuery);