diff --git a/.gitignore b/.gitignore index c8d5928..7ba4fb4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -chrome/app/Release -chrome/app/vendors +chrome/app/player +firefox/data/player -firefox/data/app/Release -firefox/data/app/vendors +node_modules diff --git a/Gulpfile.js b/Gulpfile.js new file mode 100644 index 0000000..93943ad --- /dev/null +++ b/Gulpfile.js @@ -0,0 +1,19 @@ +var gulp = require('gulp'); + +var playerFiles = [ + 'connect.js', + 'load.js', + 'window.html', + 'TemplateData/*', + 'vendors/**/*' +]; + +gulp.task('chrome', function() { + gulp.src(playerFiles, { base: '.', cwd: 'player/' }) + .pipe(gulp.dest('chrome/app')); +}); + +gulp.task('firefox', function() { + gulp.src(playerFiles, { base: '.', cwd: 'player/' }) + .pipe(gulp.dest('firefox/data')); +}); diff --git a/chrome/.bowerrc b/chrome/.bowerrc deleted file mode 100644 index 5d0c33e..0000000 --- a/chrome/.bowerrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "directory": "app/vendors" -} diff --git a/chrome/app/TemplateData/Thumbs.db b/chrome/app/TemplateData/Thumbs.db deleted file mode 100644 index 0ac3614..0000000 Binary files a/chrome/app/TemplateData/Thumbs.db and /dev/null differ diff --git a/chrome/app/TemplateData/UnityProgress.js b/chrome/app/TemplateData/UnityProgress.js deleted file mode 100644 index 0ed2beb..0000000 --- a/chrome/app/TemplateData/UnityProgress.js +++ /dev/null @@ -1,97 +0,0 @@ -function UnityProgress (dom) { - this.progress = 0.0; - this.message = ""; - this.dom = dom; - - var parent = dom.parentNode; - - var background = document.createElement("div"); - background.style.background = "#FFFFFF"; - background.style.position = "absolute"; - parent.appendChild(background); - this.background = background; - - var logoImage = document.createElement("img"); - logoImage.src = "TemplateData/progresslogo.png"; - logoImage.style.position = "absolute"; - parent.appendChild(logoImage); - this.logoImage = logoImage; - - var progressFrame = document.createElement("img"); - progressFrame.src = "TemplateData/loadingbar.png"; - progressFrame.style.position = "absolute"; - parent.appendChild(progressFrame); - this.progressFrame = progressFrame; - - var progressBar = document.createElement("img"); - progressBar.src = "TemplateData/fullbar.png"; - progressBar.style.position = "absolute"; - parent.appendChild(progressBar); - this.progressBar = progressBar; - - var messageArea = document.createElement("p"); - messageArea.style.position = "absolute"; - parent.appendChild(messageArea); - this.messageArea = messageArea; - - - this.SetProgress = function (progress) { - if (this.progress < progress) - this.progress = progress; - this.messageArea.style.display = "none"; - this.progressFrame.style.display = "inline"; - this.progressBar.style.display = "inline"; - this.Update(); - } - - this.SetMessage = function (message) { - this.message = message; - this.background.style.display = "inline"; - this.logoImage.style.display = "inline"; - this.progressFrame.style.display = "none"; - this.progressBar.style.display = "none"; - this.Update(); - } - - this.Clear = function() { - this.background.style.display = "none"; - this.logoImage.style.display = "none"; - this.progressFrame.style.display = "none"; - this.progressBar.style.display = "none"; - } - - this.Update = function() { - this.background.style.top = this.dom.offsetTop + 'px'; - this.background.style.left = this.dom.offsetLeft + 'px'; - this.background.style.width = this.dom.offsetWidth + 'px'; - this.background.style.height = this.dom.offsetHeight + 'px'; - - var logoImg = new Image(); - logoImg.src = this.logoImage.src; - var progressFrameImg = new Image(); - progressFrameImg.src = this.progressFrame.src; - - this.logoImage.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 - logoImg.height * 0.5) + 'px'; - this.logoImage.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - logoImg.width * 0.5) + 'px'; - this.logoImage.style.width = logoImg.width+'px'; - this.logoImage.style.height = logoImg.height+'px'; - - this.progressFrame.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 + logoImg.height * 0.5 + 10) + 'px'; - this.progressFrame.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - progressFrameImg.width * 0.5) + 'px'; - this.progressFrame.width = progressFrameImg.width; - this.progressFrame.height = progressFrameImg.height; - - this.progressBar.style.top = this.progressFrame.style.top; - this.progressBar.style.left = this.progressFrame.style.left; - this.progressBar.width = progressFrameImg.width * Math.min(this.progress, 1); - this.progressBar.height = progressFrameImg.height; - - this.messageArea.style.top = this.progressFrame.style.top; - this.messageArea.style.left = 0; - this.messageArea.style.width = '100%'; - this.messageArea.style.textAlign = 'center'; - this.messageArea.innerHTML = this.message; - } - - this.Update (); -} \ No newline at end of file diff --git a/chrome/app/TemplateData/default-cover.jpg b/chrome/app/TemplateData/default-cover.jpg deleted file mode 100644 index 86f23ce..0000000 Binary files a/chrome/app/TemplateData/default-cover.jpg and /dev/null differ diff --git a/chrome/app/TemplateData/favicon.png b/chrome/app/TemplateData/favicon.png deleted file mode 100644 index f6c7194..0000000 Binary files a/chrome/app/TemplateData/favicon.png and /dev/null differ diff --git a/chrome/app/TemplateData/fullbar.png b/chrome/app/TemplateData/fullbar.png deleted file mode 100644 index 4ee0a14..0000000 Binary files a/chrome/app/TemplateData/fullbar.png and /dev/null differ diff --git a/chrome/app/TemplateData/loadingbar.png b/chrome/app/TemplateData/loadingbar.png deleted file mode 100644 index 98e0d96..0000000 Binary files a/chrome/app/TemplateData/loadingbar.png and /dev/null differ diff --git a/chrome/app/TemplateData/progresslogo.png b/chrome/app/TemplateData/progresslogo.png deleted file mode 100644 index a568710..0000000 Binary files a/chrome/app/TemplateData/progresslogo.png and /dev/null differ diff --git a/chrome/app/TemplateData/style.css b/chrome/app/TemplateData/style.css deleted file mode 100644 index 94c4232..0000000 --- a/chrome/app/TemplateData/style.css +++ /dev/null @@ -1,28 +0,0 @@ - -/**************************************** - ==== RESETS -****************************************/ - -html,body,div,canvas { margin: 0; padding: 0; } -::-moz-selection { color: #333; text-shadow: none; } -::selection { color: #333; text-shadow: none; } -.clear:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; } -.clear { display: inline-table; clear: both; } -/* Hides from IE-mac \*/ * html .clear { height: 1%; } .clear { display: block; } /* End hide from IE-mac */ - -/**************************************** - ==== LAYOUT -****************************************/ - -html, body { width: 100%; height: 100%; font-family: Helvetica, Verdana, Arial, sans-serif; } -body { } -p.header, p.footer { display: none; } -div.logo { width: 196px; height: 38px; float: left; background: url(logo.png) 0 0 no-repeat; position: relative; z-index: 10; } -div.title { height: 38px; line-height: 38px; padding: 0 10px; margin: 0 1px 0 0; float: right; color: #333; text-align: right; font-size: 18px; position: relative; z-index: 10; } -.template-wrap { position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); } -.template-wrap canvas { margin: 0 0 10px 0; position: relative; z-index: 9; box-shadow: 0 10px 30px rgba(0,0,0,0.2); -moz-box-shadow: 0 10px 30px rgba(0,0,0,0.2); } -.fullscreen { float: right; position: relative; z-index: 10; } - -body.template { } -.template .template-wrap { } -.template .template-wrap canvas { } diff --git a/chrome/app/connect.js b/chrome/app/connect.js deleted file mode 100644 index fb18869..0000000 --- a/chrome/app/connect.js +++ /dev/null @@ -1,39 +0,0 @@ -// connect to canvas - var Module = { - filePackagePrefixURL: "Release/", - memoryInitializerPrefixURL: "Release/", - preRun: [], - postRun: [], - print: (function() { - return function(text) { - console.log (text); - }; - })(), - printErr: function(text) { - console.error (text); - }, - canvas: document.getElementById('canvas'), - progress: null, - setStatus: function(text) { - if (this.progress == null) - { - if (typeof UnityProgress != 'function') - return; - this.progress = new UnityProgress (canvas); - } - if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' }; - if (text === Module.setStatus.text) return; - this.progress.SetMessage (text); - var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); - if (m) - this.progress.SetProgress (parseInt(m[2])/parseInt(m[4])); - if (text === "") - this.progress.Clear() - }, - totalDependencies: 0, - monitorRunDependencies: function(left) { - this.totalDependencies = Math.max(this.totalDependencies, left); - Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); - } - }; - Module.setStatus('Downloading (0.0/1)'); \ No newline at end of file diff --git a/chrome/app/load.js b/chrome/app/load.js deleted file mode 100644 index 70463b1..0000000 --- a/chrome/app/load.js +++ /dev/null @@ -1,26 +0,0 @@ -if (!(!Math.fround)) { - var script = document.createElement('script'); - script.src = "Release/VLibrasWebPlayer.js"; - document.body.appendChild(script); -} else { - var codeXHR = new XMLHttpRequest(); - codeXHR.open('GET', 'Release/VLibrasWebPlayer.js', true); - codeXHR.onload = function() { - var code = codeXHR.responseText; - if (!Math.fround) { -console.log('optimizing out Math.fround calls'); -code = code.replace(/Math_fround\(/g, '(').replace("'use asm'", "'almost asm'") - } - - var blob = new Blob([code], { type: 'text/javascript' }); - codeXHR = null; - var src = URL.createObjectURL(blob); - var script = document.createElement('script'); - script.src = URL.createObjectURL(blob); - script.onload = function() { - URL.revokeObjectURL(script.src); - }; - document.body.appendChild(script); - }; - codeXHR.send(null); -} \ No newline at end of file diff --git a/chrome/app/main.js b/chrome/app/main.js deleted file mode 100644 index 97c5bb4..0000000 --- a/chrome/app/main.js +++ /dev/null @@ -1,48 +0,0 @@ -var app = { - chooser: null, - glosa: undefined, - loaded: false, - lastReq: { - url: null, - millis: null, - response: null - } -}; - -function onLoadPlayer() { - if ( app.glosa !== undefined ) { - SendMessage('Avatar', 'catchGlosa', app.glosa); - } - - app.loaded = true; -} - -chrome.runtime.onMessage.addListener( - function(request, sender, sendResponse) { - app.chooser = app.chooser || new qdClient.Chooser(); - - document.getElementById('loading-screen').style.display = 'block'; - app.chooser.choose( - app.lastReq.url, - app.lastReq.millis, - app.lastReq.response, - function (url) { - var start = new Date().getTime(); - - qdClient.request(url + '?texto=' + request.selectedText, "GET", {}, - function(status, response) { - app.lastReq.response = status === 404 ? -1 : status; - app.lastReq.millis = (new Date().getTime() - start); - app.lastReq.url = url; - - app.glosa = response; - - document.getElementById('loading-screen').style.display = 'none'; - if (app.loaded == true) { - SendMessage('Avatar', 'catchGlosa', app.glosa); - } - }); - }); - }); - -chrome.runtime.sendMessage({ready: true}); diff --git a/chrome/app/window.html b/chrome/app/window.html deleted file mode 100644 index ea0a323..0000000 --- a/chrome/app/window.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - VLibras Plugin - - - - - - - - - - -
Carregando...
-
- -
- - - - - - diff --git a/chrome/bower.json b/chrome/bower.json deleted file mode 100644 index 31d6ac7..0000000 --- a/chrome/bower.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "vlibras-chrome", - "version": "0.0.1", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], - "devDependencies": { - "qdclient": "git@git.lavid.ufpb.br:qdclient.git" - } -} diff --git a/firefox/.bowerrc b/firefox/.bowerrc deleted file mode 100644 index 6ca24d8..0000000 --- a/firefox/.bowerrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "directory": "data/app/vendors" -} diff --git a/firefox/bower.json b/firefox/bower.json deleted file mode 100644 index 28a1f56..0000000 --- a/firefox/bower.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "vlibras-firefox", - "version": "0.0.1", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], - "devDependencies": { - "qdclient": "git@git.lavid.ufpb.br:qdclient.git" - } -} diff --git a/firefox/data/app/TemplateData/Thumbs.db b/firefox/data/app/TemplateData/Thumbs.db deleted file mode 100644 index 0ac3614..0000000 Binary files a/firefox/data/app/TemplateData/Thumbs.db and /dev/null differ diff --git a/firefox/data/app/TemplateData/UnityProgress.js b/firefox/data/app/TemplateData/UnityProgress.js deleted file mode 100644 index 0ed2beb..0000000 --- a/firefox/data/app/TemplateData/UnityProgress.js +++ /dev/null @@ -1,97 +0,0 @@ -function UnityProgress (dom) { - this.progress = 0.0; - this.message = ""; - this.dom = dom; - - var parent = dom.parentNode; - - var background = document.createElement("div"); - background.style.background = "#FFFFFF"; - background.style.position = "absolute"; - parent.appendChild(background); - this.background = background; - - var logoImage = document.createElement("img"); - logoImage.src = "TemplateData/progresslogo.png"; - logoImage.style.position = "absolute"; - parent.appendChild(logoImage); - this.logoImage = logoImage; - - var progressFrame = document.createElement("img"); - progressFrame.src = "TemplateData/loadingbar.png"; - progressFrame.style.position = "absolute"; - parent.appendChild(progressFrame); - this.progressFrame = progressFrame; - - var progressBar = document.createElement("img"); - progressBar.src = "TemplateData/fullbar.png"; - progressBar.style.position = "absolute"; - parent.appendChild(progressBar); - this.progressBar = progressBar; - - var messageArea = document.createElement("p"); - messageArea.style.position = "absolute"; - parent.appendChild(messageArea); - this.messageArea = messageArea; - - - this.SetProgress = function (progress) { - if (this.progress < progress) - this.progress = progress; - this.messageArea.style.display = "none"; - this.progressFrame.style.display = "inline"; - this.progressBar.style.display = "inline"; - this.Update(); - } - - this.SetMessage = function (message) { - this.message = message; - this.background.style.display = "inline"; - this.logoImage.style.display = "inline"; - this.progressFrame.style.display = "none"; - this.progressBar.style.display = "none"; - this.Update(); - } - - this.Clear = function() { - this.background.style.display = "none"; - this.logoImage.style.display = "none"; - this.progressFrame.style.display = "none"; - this.progressBar.style.display = "none"; - } - - this.Update = function() { - this.background.style.top = this.dom.offsetTop + 'px'; - this.background.style.left = this.dom.offsetLeft + 'px'; - this.background.style.width = this.dom.offsetWidth + 'px'; - this.background.style.height = this.dom.offsetHeight + 'px'; - - var logoImg = new Image(); - logoImg.src = this.logoImage.src; - var progressFrameImg = new Image(); - progressFrameImg.src = this.progressFrame.src; - - this.logoImage.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 - logoImg.height * 0.5) + 'px'; - this.logoImage.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - logoImg.width * 0.5) + 'px'; - this.logoImage.style.width = logoImg.width+'px'; - this.logoImage.style.height = logoImg.height+'px'; - - this.progressFrame.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 + logoImg.height * 0.5 + 10) + 'px'; - this.progressFrame.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - progressFrameImg.width * 0.5) + 'px'; - this.progressFrame.width = progressFrameImg.width; - this.progressFrame.height = progressFrameImg.height; - - this.progressBar.style.top = this.progressFrame.style.top; - this.progressBar.style.left = this.progressFrame.style.left; - this.progressBar.width = progressFrameImg.width * Math.min(this.progress, 1); - this.progressBar.height = progressFrameImg.height; - - this.messageArea.style.top = this.progressFrame.style.top; - this.messageArea.style.left = 0; - this.messageArea.style.width = '100%'; - this.messageArea.style.textAlign = 'center'; - this.messageArea.innerHTML = this.message; - } - - this.Update (); -} \ No newline at end of file diff --git a/firefox/data/app/TemplateData/default-cover.jpg b/firefox/data/app/TemplateData/default-cover.jpg deleted file mode 100644 index 86f23ce..0000000 Binary files a/firefox/data/app/TemplateData/default-cover.jpg and /dev/null differ diff --git a/firefox/data/app/TemplateData/favicon.png b/firefox/data/app/TemplateData/favicon.png deleted file mode 100644 index f6c7194..0000000 Binary files a/firefox/data/app/TemplateData/favicon.png and /dev/null differ diff --git a/firefox/data/app/TemplateData/fullbar.png b/firefox/data/app/TemplateData/fullbar.png deleted file mode 100644 index 4ee0a14..0000000 Binary files a/firefox/data/app/TemplateData/fullbar.png and /dev/null differ diff --git a/firefox/data/app/TemplateData/loadingbar.png b/firefox/data/app/TemplateData/loadingbar.png deleted file mode 100644 index 98e0d96..0000000 Binary files a/firefox/data/app/TemplateData/loadingbar.png and /dev/null differ diff --git a/firefox/data/app/TemplateData/progresslogo.png b/firefox/data/app/TemplateData/progresslogo.png deleted file mode 100644 index a568710..0000000 Binary files a/firefox/data/app/TemplateData/progresslogo.png and /dev/null differ diff --git a/firefox/data/app/TemplateData/style.css b/firefox/data/app/TemplateData/style.css deleted file mode 100644 index 94c4232..0000000 --- a/firefox/data/app/TemplateData/style.css +++ /dev/null @@ -1,28 +0,0 @@ - -/**************************************** - ==== RESETS -****************************************/ - -html,body,div,canvas { margin: 0; padding: 0; } -::-moz-selection { color: #333; text-shadow: none; } -::selection { color: #333; text-shadow: none; } -.clear:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; } -.clear { display: inline-table; clear: both; } -/* Hides from IE-mac \*/ * html .clear { height: 1%; } .clear { display: block; } /* End hide from IE-mac */ - -/**************************************** - ==== LAYOUT -****************************************/ - -html, body { width: 100%; height: 100%; font-family: Helvetica, Verdana, Arial, sans-serif; } -body { } -p.header, p.footer { display: none; } -div.logo { width: 196px; height: 38px; float: left; background: url(logo.png) 0 0 no-repeat; position: relative; z-index: 10; } -div.title { height: 38px; line-height: 38px; padding: 0 10px; margin: 0 1px 0 0; float: right; color: #333; text-align: right; font-size: 18px; position: relative; z-index: 10; } -.template-wrap { position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); } -.template-wrap canvas { margin: 0 0 10px 0; position: relative; z-index: 9; box-shadow: 0 10px 30px rgba(0,0,0,0.2); -moz-box-shadow: 0 10px 30px rgba(0,0,0,0.2); } -.fullscreen { float: right; position: relative; z-index: 10; } - -body.template { } -.template .template-wrap { } -.template .template-wrap canvas { } diff --git a/firefox/data/app/connect.js b/firefox/data/app/connect.js deleted file mode 100644 index fb18869..0000000 --- a/firefox/data/app/connect.js +++ /dev/null @@ -1,39 +0,0 @@ -// connect to canvas - var Module = { - filePackagePrefixURL: "Release/", - memoryInitializerPrefixURL: "Release/", - preRun: [], - postRun: [], - print: (function() { - return function(text) { - console.log (text); - }; - })(), - printErr: function(text) { - console.error (text); - }, - canvas: document.getElementById('canvas'), - progress: null, - setStatus: function(text) { - if (this.progress == null) - { - if (typeof UnityProgress != 'function') - return; - this.progress = new UnityProgress (canvas); - } - if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' }; - if (text === Module.setStatus.text) return; - this.progress.SetMessage (text); - var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); - if (m) - this.progress.SetProgress (parseInt(m[2])/parseInt(m[4])); - if (text === "") - this.progress.Clear() - }, - totalDependencies: 0, - monitorRunDependencies: function(left) { - this.totalDependencies = Math.max(this.totalDependencies, left); - Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); - } - }; - Module.setStatus('Downloading (0.0/1)'); \ No newline at end of file diff --git a/firefox/data/app/load.js b/firefox/data/app/load.js deleted file mode 100644 index 70463b1..0000000 --- a/firefox/data/app/load.js +++ /dev/null @@ -1,26 +0,0 @@ -if (!(!Math.fround)) { - var script = document.createElement('script'); - script.src = "Release/VLibrasWebPlayer.js"; - document.body.appendChild(script); -} else { - var codeXHR = new XMLHttpRequest(); - codeXHR.open('GET', 'Release/VLibrasWebPlayer.js', true); - codeXHR.onload = function() { - var code = codeXHR.responseText; - if (!Math.fround) { -console.log('optimizing out Math.fround calls'); -code = code.replace(/Math_fround\(/g, '(').replace("'use asm'", "'almost asm'") - } - - var blob = new Blob([code], { type: 'text/javascript' }); - codeXHR = null; - var src = URL.createObjectURL(blob); - var script = document.createElement('script'); - script.src = URL.createObjectURL(blob); - script.onload = function() { - URL.revokeObjectURL(script.src); - }; - document.body.appendChild(script); - }; - codeXHR.send(null); -} \ No newline at end of file diff --git a/firefox/data/app/main.js b/firefox/data/app/main.js deleted file mode 100644 index 7d93f81..0000000 --- a/firefox/data/app/main.js +++ /dev/null @@ -1,45 +0,0 @@ -var app = { - chooser: null, - glosa: undefined, - loaded: false, - lastReq: { - url: null, - millis: null, - response: null - } -}; - -function onLoadPlayer() { - if ( app.glosa !== undefined ) { - SendMessage('Avatar', 'catchGlosa', app.glosa); - } - - app.loaded = true; -} - -document.addEventListener('plugin:selectedText', function(e) { - app.chooser = app.chooser || new qdClient.Chooser(); - - document.getElementById('loading-screen').style.display = 'block'; - app.chooser.choose( - app.lastReq.url, - app.lastReq.millis, - app.lastReq.response, - function (url) { - var start = new Date().getTime(); - - qdClient.request(url + '?texto=' + e.detail, "GET", {}, - function(status, response) { - app.lastReq.response = status === 404 ? -1 : status; - app.lastReq.millis = (new Date().getTime() - start); - app.lastReq.url = url; - - app.glosa = response; - - document.getElementById('loading-screen').style.display = 'none'; - if (app.loaded == true) { - SendMessage('Avatar', 'catchGlosa', app.glosa); - } - }); - }); -}); diff --git a/firefox/data/app/window.html b/firefox/data/app/window.html deleted file mode 100644 index ea0a323..0000000 --- a/firefox/data/app/window.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - VLibras Plugin - - - - - - - - - - -
Carregando...
-
- -
- - - - - - diff --git a/firefox/data/main.js b/firefox/data/main.js new file mode 100644 index 0000000..7d93f81 --- /dev/null +++ b/firefox/data/main.js @@ -0,0 +1,45 @@ +var app = { + chooser: null, + glosa: undefined, + loaded: false, + lastReq: { + url: null, + millis: null, + response: null + } +}; + +function onLoadPlayer() { + if ( app.glosa !== undefined ) { + SendMessage('Avatar', 'catchGlosa', app.glosa); + } + + app.loaded = true; +} + +document.addEventListener('plugin:selectedText', function(e) { + app.chooser = app.chooser || new qdClient.Chooser(); + + document.getElementById('loading-screen').style.display = 'block'; + app.chooser.choose( + app.lastReq.url, + app.lastReq.millis, + app.lastReq.response, + function (url) { + var start = new Date().getTime(); + + qdClient.request(url + '?texto=' + e.detail, "GET", {}, + function(status, response) { + app.lastReq.response = status === 404 ? -1 : status; + app.lastReq.millis = (new Date().getTime() - start); + app.lastReq.url = url; + + app.glosa = response; + + document.getElementById('loading-screen').style.display = 'none'; + if (app.loaded == true) { + SendMessage('Avatar', 'catchGlosa', app.glosa); + } + }); + }); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..d30bc03 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "vlibras-plugin", + "version": "1.0.0", + "description": "", + "devDependencies": { + "gulp": "^3.9.0" + } +} diff --git a/player/.bowerrc b/player/.bowerrc new file mode 100644 index 0000000..b4eb29f --- /dev/null +++ b/player/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "vendors" +} diff --git a/player/TemplateData/Thumbs.db b/player/TemplateData/Thumbs.db new file mode 100644 index 0000000..0ac3614 Binary files /dev/null and b/player/TemplateData/Thumbs.db differ diff --git a/player/TemplateData/UnityProgress.js b/player/TemplateData/UnityProgress.js new file mode 100644 index 0000000..0ed2beb --- /dev/null +++ b/player/TemplateData/UnityProgress.js @@ -0,0 +1,97 @@ +function UnityProgress (dom) { + this.progress = 0.0; + this.message = ""; + this.dom = dom; + + var parent = dom.parentNode; + + var background = document.createElement("div"); + background.style.background = "#FFFFFF"; + background.style.position = "absolute"; + parent.appendChild(background); + this.background = background; + + var logoImage = document.createElement("img"); + logoImage.src = "TemplateData/progresslogo.png"; + logoImage.style.position = "absolute"; + parent.appendChild(logoImage); + this.logoImage = logoImage; + + var progressFrame = document.createElement("img"); + progressFrame.src = "TemplateData/loadingbar.png"; + progressFrame.style.position = "absolute"; + parent.appendChild(progressFrame); + this.progressFrame = progressFrame; + + var progressBar = document.createElement("img"); + progressBar.src = "TemplateData/fullbar.png"; + progressBar.style.position = "absolute"; + parent.appendChild(progressBar); + this.progressBar = progressBar; + + var messageArea = document.createElement("p"); + messageArea.style.position = "absolute"; + parent.appendChild(messageArea); + this.messageArea = messageArea; + + + this.SetProgress = function (progress) { + if (this.progress < progress) + this.progress = progress; + this.messageArea.style.display = "none"; + this.progressFrame.style.display = "inline"; + this.progressBar.style.display = "inline"; + this.Update(); + } + + this.SetMessage = function (message) { + this.message = message; + this.background.style.display = "inline"; + this.logoImage.style.display = "inline"; + this.progressFrame.style.display = "none"; + this.progressBar.style.display = "none"; + this.Update(); + } + + this.Clear = function() { + this.background.style.display = "none"; + this.logoImage.style.display = "none"; + this.progressFrame.style.display = "none"; + this.progressBar.style.display = "none"; + } + + this.Update = function() { + this.background.style.top = this.dom.offsetTop + 'px'; + this.background.style.left = this.dom.offsetLeft + 'px'; + this.background.style.width = this.dom.offsetWidth + 'px'; + this.background.style.height = this.dom.offsetHeight + 'px'; + + var logoImg = new Image(); + logoImg.src = this.logoImage.src; + var progressFrameImg = new Image(); + progressFrameImg.src = this.progressFrame.src; + + this.logoImage.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 - logoImg.height * 0.5) + 'px'; + this.logoImage.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - logoImg.width * 0.5) + 'px'; + this.logoImage.style.width = logoImg.width+'px'; + this.logoImage.style.height = logoImg.height+'px'; + + this.progressFrame.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 + logoImg.height * 0.5 + 10) + 'px'; + this.progressFrame.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - progressFrameImg.width * 0.5) + 'px'; + this.progressFrame.width = progressFrameImg.width; + this.progressFrame.height = progressFrameImg.height; + + this.progressBar.style.top = this.progressFrame.style.top; + this.progressBar.style.left = this.progressFrame.style.left; + this.progressBar.width = progressFrameImg.width * Math.min(this.progress, 1); + this.progressBar.height = progressFrameImg.height; + + this.messageArea.style.top = this.progressFrame.style.top; + this.messageArea.style.left = 0; + this.messageArea.style.width = '100%'; + this.messageArea.style.textAlign = 'center'; + this.messageArea.innerHTML = this.message; + } + + this.Update (); +} \ No newline at end of file diff --git a/player/TemplateData/default-cover.jpg b/player/TemplateData/default-cover.jpg new file mode 100644 index 0000000..86f23ce Binary files /dev/null and b/player/TemplateData/default-cover.jpg differ diff --git a/player/TemplateData/favicon.png b/player/TemplateData/favicon.png new file mode 100644 index 0000000..f6c7194 Binary files /dev/null and b/player/TemplateData/favicon.png differ diff --git a/player/TemplateData/fullbar.png b/player/TemplateData/fullbar.png new file mode 100644 index 0000000..4ee0a14 Binary files /dev/null and b/player/TemplateData/fullbar.png differ diff --git a/player/TemplateData/loadingbar.png b/player/TemplateData/loadingbar.png new file mode 100644 index 0000000..98e0d96 Binary files /dev/null and b/player/TemplateData/loadingbar.png differ diff --git a/player/TemplateData/progresslogo.png b/player/TemplateData/progresslogo.png new file mode 100644 index 0000000..a568710 Binary files /dev/null and b/player/TemplateData/progresslogo.png differ diff --git a/player/TemplateData/style.css b/player/TemplateData/style.css new file mode 100644 index 0000000..94c4232 --- /dev/null +++ b/player/TemplateData/style.css @@ -0,0 +1,28 @@ + +/**************************************** + ==== RESETS +****************************************/ + +html,body,div,canvas { margin: 0; padding: 0; } +::-moz-selection { color: #333; text-shadow: none; } +::selection { color: #333; text-shadow: none; } +.clear:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; } +.clear { display: inline-table; clear: both; } +/* Hides from IE-mac \*/ * html .clear { height: 1%; } .clear { display: block; } /* End hide from IE-mac */ + +/**************************************** + ==== LAYOUT +****************************************/ + +html, body { width: 100%; height: 100%; font-family: Helvetica, Verdana, Arial, sans-serif; } +body { } +p.header, p.footer { display: none; } +div.logo { width: 196px; height: 38px; float: left; background: url(logo.png) 0 0 no-repeat; position: relative; z-index: 10; } +div.title { height: 38px; line-height: 38px; padding: 0 10px; margin: 0 1px 0 0; float: right; color: #333; text-align: right; font-size: 18px; position: relative; z-index: 10; } +.template-wrap { position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); } +.template-wrap canvas { margin: 0 0 10px 0; position: relative; z-index: 9; box-shadow: 0 10px 30px rgba(0,0,0,0.2); -moz-box-shadow: 0 10px 30px rgba(0,0,0,0.2); } +.fullscreen { float: right; position: relative; z-index: 10; } + +body.template { } +.template .template-wrap { } +.template .template-wrap canvas { } diff --git a/player/bower.json b/player/bower.json new file mode 100644 index 0000000..0b34d2b --- /dev/null +++ b/player/bower.json @@ -0,0 +1,14 @@ +{ + "name": "vlibras-player", + "version": "0.0.1", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "devDependencies": { + "qdclient": "git@git.lavid.ufpb.br:qdclient.git" + } +} diff --git a/player/connect.js b/player/connect.js new file mode 100644 index 0000000..fb18869 --- /dev/null +++ b/player/connect.js @@ -0,0 +1,39 @@ +// connect to canvas + var Module = { + filePackagePrefixURL: "Release/", + memoryInitializerPrefixURL: "Release/", + preRun: [], + postRun: [], + print: (function() { + return function(text) { + console.log (text); + }; + })(), + printErr: function(text) { + console.error (text); + }, + canvas: document.getElementById('canvas'), + progress: null, + setStatus: function(text) { + if (this.progress == null) + { + if (typeof UnityProgress != 'function') + return; + this.progress = new UnityProgress (canvas); + } + if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' }; + if (text === Module.setStatus.text) return; + this.progress.SetMessage (text); + var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); + if (m) + this.progress.SetProgress (parseInt(m[2])/parseInt(m[4])); + if (text === "") + this.progress.Clear() + }, + totalDependencies: 0, + monitorRunDependencies: function(left) { + this.totalDependencies = Math.max(this.totalDependencies, left); + Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); + } + }; + Module.setStatus('Downloading (0.0/1)'); \ No newline at end of file diff --git a/player/load.js b/player/load.js new file mode 100644 index 0000000..70463b1 --- /dev/null +++ b/player/load.js @@ -0,0 +1,26 @@ +if (!(!Math.fround)) { + var script = document.createElement('script'); + script.src = "Release/VLibrasWebPlayer.js"; + document.body.appendChild(script); +} else { + var codeXHR = new XMLHttpRequest(); + codeXHR.open('GET', 'Release/VLibrasWebPlayer.js', true); + codeXHR.onload = function() { + var code = codeXHR.responseText; + if (!Math.fround) { +console.log('optimizing out Math.fround calls'); +code = code.replace(/Math_fround\(/g, '(').replace("'use asm'", "'almost asm'") + } + + var blob = new Blob([code], { type: 'text/javascript' }); + codeXHR = null; + var src = URL.createObjectURL(blob); + var script = document.createElement('script'); + script.src = URL.createObjectURL(blob); + script.onload = function() { + URL.revokeObjectURL(script.src); + }; + document.body.appendChild(script); + }; + codeXHR.send(null); +} \ No newline at end of file diff --git a/player/vendors/qdclient/.bower.json b/player/vendors/qdclient/.bower.json new file mode 100644 index 0000000..6dd3e23 --- /dev/null +++ b/player/vendors/qdclient/.bower.json @@ -0,0 +1,27 @@ +{ + "name": "qdclient", + "main": [ + "qdclient.js" + ], + "ignore": [ + "**/.*", + "Gulpfile.js", + "demo", + "node_modules", + "vendor", + "tests" + ], + "devDependencies": { + "mocha": "~2.2.5", + "chai": "~3.0.0" + }, + "_release": "2b32d629d0", + "_resolution": { + "type": "branch", + "branch": "master", + "commit": "2b32d629d0a6c4818ad5dd53c22bd000d37a7893" + }, + "_source": "git@git.lavid.ufpb.br:qdclient.git", + "_target": "*", + "_originalSource": "git@git.lavid.ufpb.br:qdclient.git" +} \ No newline at end of file diff --git a/player/vendors/qdclient/README b/player/vendors/qdclient/README new file mode 100644 index 0000000..15eab8e --- /dev/null +++ b/player/vendors/qdclient/README @@ -0,0 +1,32 @@ +qdClient +========= + +1. Tools +---------------- + +1. NodeJS +2. NPM - Node Package Manager +3. Bower - Frontend dependencies +4. Gulp - Build tools + +2. Installing dependencies +---------------- + +```bash +$ npm install +$ bower install +``` + +3. Demo +---------------- +```bash +$ gulp demo +``` + +4. Building +---------------- +```bash +$ gulp build +``` + +**Enjoy** diff --git a/player/vendors/qdclient/bower.json b/player/vendors/qdclient/bower.json new file mode 100644 index 0000000..98c58ce --- /dev/null +++ b/player/vendors/qdclient/bower.json @@ -0,0 +1,19 @@ +{ + "name": "qdclient", + "version": "0.0.1", + "main": [ + "qdclient.js" + ], + "ignore": [ + "**/.*", + "Gulpfile.js", + "demo", + "node_modules", + "vendor", + "tests" + ], + "devDependencies": { + "mocha": "~2.2.5", + "chai": "~3.0.0" + } +} diff --git a/player/vendors/qdclient/lib/chooser.js b/player/vendors/qdclient/lib/chooser.js new file mode 100644 index 0000000..2e36aa1 --- /dev/null +++ b/player/vendors/qdclient/lib/chooser.js @@ -0,0 +1,222 @@ +(function(window, localStorage, undefined) { + 'use strict'; + + function Chooser() { + this.server = 'http://150.165.204.39/vlibras-cloud/get_servers.php'; + + this.options = { + THRESHOLDSLOW: 2000, + SLOWLIMITTRIES: 5, + NBESTHEURISTIC1: 2, + QUANTITYPREVIOUSTIMESSTORED: 10 + }; + + this.mirrors = []; + + this.heuristics = { + FIRSTHEURISTIC: { + FIRSTRANDOM : {value: 0, name: "Random"}, + FIRSTRANDOMNBEST: {value: 1, name: "Random Among N Best"}, + FIRSTBEST : {value: 2, name: "Best"} + }, + SECONDHEURISTIC: { + SECONDRANDOM : {value: 0, name: "Random"}, + SECONDCLOSEST: {value: 1, name: "Closest"} + }, + THIRDHEURISTIC: { + THIRDSIMPLEAVERAGE : {value: 0, name: "Simple Average"}, + THIRDWEIGHTEDAVERAGE: {value: 1, name: "Weighted Average"} + } + }; + } + + // Exports + qdClient.Chooser = Chooser; + + Chooser.prototype.choose = function(urlLast, millisLast, response, callback) { + var $this = this; + + this.loadMirrors_(function() { + $this.chooseServer_(urlLast, millisLast, response, callback); + }); + }; + + Chooser.prototype.chooseServer_ = function(urlLast, millisLast, response, callback) { + var firstHeuristic = this.heuristics.FIRSTHEURISTIC.FIRSTBEST; + var secondHeuristic = this.heuristics.SECONDHEURISTIC.SECONDRANDOM; + var thirdHeuristic = this.heuristics.THIRDHEURISTIC.THIRDWEIGHTEDAVERAGE; + + var j = 0, i = 0; /* Fix JSHint */ + + var sizeBest = this.options.NBESTHEURISTIC1; + if (firstHeuristic == this.heuristics.FIRSTHEURISTIC.FIRSTBEST) { + sizeBest = 1; + } + + if (urlLast && urlLast.length > 0) { + for (i = 0; i < this.mirrors.length; i++) { + if (this.mirrors[i].url.toLowerCase() == urlLast.toLowerCase()) { + if (this.mirrors[i].previousTimes.length < this.options.QUANTITYPREVIOUSTIMESSTORED) { + this.mirrors[i].previousTimes[this.mirrors[i].previousTimes.length] = millisLast; + } else { + for (j = this.options.QUANTITYPREVIOUSTIMESSTORED-1; j > 0; j--) { + this.mirrors[i].previousTimes[j-1] = this.mirrors[i].previousTimes[j]; + } + + this.mirrors[i].previousTimes[this.options.QUANTITYPREVIOUSTIMESSTORED-1] = millisLast; + } + + if (thirdHeuristic == this.heuristics.THIRDHEURISTIC.THIRDSIMPLEAVERAGE) { + var totalMillis = 0; + for (j = 0; j < this.mirrors[i].previousTimes.length; j++) { + totalMillis += this.mirrors[i].previousTimes[j]; + } + + this.mirrors[i].averageTime = totalMillis/this.mirrors[i].previousTimes.length; + } else if (thirdHeuristic == this.heuristics.THIRDHEURISTIC.THIRDWEIGHTEDAVERAGE) { + var totalMillisAndWeights = 0; + var totalWeights = 0; + for (j = 0; j < this.mirrors[i].previousTimes.length; j++) { + totalMillisAndWeights += this.mirrors[i].previousTimes[j]*(j+1); + totalWeights += (j+1); + } + + this.mirrors[i].averageTime = totalMillisAndWeights/totalWeights; + } + + if (millisLast > this.options.THRESHOLDSLOW || response == -1) { + this.mirrors[i].isSlow = true; + this.mirrors[i].remainingSlow = this.options.SLOWLIMITTRIES; + } + + localStorage.setItem("servers", JSON.stringify(this.mirrors)); + break; + } + + } + + } + + var position = Math.floor((Math.random() * this.mirrors.length)); + var closestPosition; + + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM) { + position = -1; + closestPosition = -1; + } + + var vectorBest = []; + var k = 0, z = 0; /* JSHint Fix */ + + for (j = 0; j < this.mirrors.length; j++) { + if (this.mirrors[j].remainingSlow > 0) { + this.mirrors[j].remainingSlow = this.mirrors[j].remainingSlow - 1; + } + + if (this.mirrors[j].remainingSlow === 0) { + this.mirrors[j].isSlow = false; + } + + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM && this.mirrors[j].isSlow === false) { + if (closestPosition == -1) { + closestPosition = j; + } + + var added = false; + + for (k = 0; k < vectorBest.length; k++) { + if (this.mirrors[j].averageTime < vectorBest[k].averageTime || (this.mirrors[j].averageTime == vectorBest[k].averageTime && (Math.floor(Math.random()) < 0.5) )) { + + added = true; + + if (vectorBest.length < sizeBest) { + for (z = vectorBest.length-1; z >= k; z--) { + vectorBest[z+1] = vectorBest[z]; + } + } else { + for (z = vectorBest.length-2; z >= k; z--) { + vectorBest[z+1] = vectorBest[z]; + } + } + + vectorBest[k] = this.mirrors[j]; + + break; + } + } + + if (added === false && vectorBest.length < sizeBest) { + vectorBest[vectorBest.length] = this.mirrors[j]; + } + + } + + } + + // pega aleatorio entre as N posicoes dos melhores (se for guloso, tera apenas um elemento no vetor) + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM && vectorBest.length > 0) { + position = Math.floor((Math.random() * vectorBest.length)); + } + + if (position == -1) { + if (secondHeuristic == this.heuristics.SECONDHEURISTIC.SECONDCLOSEST) { + // escolhendo o mais proximo, no caso, o vetor já está ordenado + if (closestPosition != -1) { + position = closestPosition; + } else { + // se nao marcou nenhum como closest, todos devem estar como slow, nesse caso seleciona o primeiro que é o mais próximo + position = 0; + } + + } else { + position = Math.floor((Math.random() * this.mirrors.length)); + } + } + + callback(this.mirrors[position].url); + }; + + Chooser.prototype.loadMirrors_ = function(callback) { + if (this.mirrors.length > 0) { + if (callback instanceof Function) callback(); + + return; + } + + var $this = this; + + var localServers = JSON.parse(localStorage.getItem("servers")) || []; + + qdClient.getJSON(this.server, function (status, response) { + var servers = status === 200 ? response : []; + + for (var i = 0; i < servers.length; i++){ + var mirror = { + name: servers[i].nome, + url: servers[i].url, + averageTime: 99999999, + isSlow: false, + previousTimes: [], + remainingSlow: 0, + type: servers[i].type + }; + + for (var localServer in localServers) { + if (mirror.url == localServer.url) { + mirror.averageTime = localServer.averageTime; + mirror.isSlow = localServer.isSlow; + mirror.previousTimes = localServer.previousTimes; + mirror.remainingSlow = localServer.remainingSlow; + + break; + } + } + + $this.mirrors.push(mirror); + } + + if (callback instanceof Function) callback(); + }); + }; + +}(window, localStorage)); diff --git a/player/vendors/qdclient/lib/qdclient.js b/player/vendors/qdclient/lib/qdclient.js new file mode 100644 index 0000000..086d549 --- /dev/null +++ b/player/vendors/qdclient/lib/qdclient.js @@ -0,0 +1,34 @@ +(function(window, undefined) { + 'use strict'; + + window.qdClient = window.qdClient || {}; + + qdClient.request = function request(url, method, params, callback) { + var xhr = new XMLHttpRequest(); + var raw_params = ""; + + xhr.open(method, url, true); + + xhr.onload = function() { + callback(xhr.status, xhr.responseText); + }; + + if (method == "POST" && params instanceof Object) { + + for(var param in params) { + raw_params += param + '=' + params[param] + '&'; + } + + if (params.length > 1) raw_params.slice(0, -1); + } + + xhr.send(raw_params); + }; + + qdClient.getJSON = function getJSON(url, callback) { + qdClient.request(url, "GET", {}, function(status, response) { + callback(status, JSON.parse(response)); + }); + }; + +}(window)); diff --git a/player/vendors/qdclient/package.json b/player/vendors/qdclient/package.json new file mode 100644 index 0000000..b1fdf95 --- /dev/null +++ b/player/vendors/qdclient/package.json @@ -0,0 +1,18 @@ +{ + "name": "qdclient", + "version": "0.0.1", + "description": "", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "devDependencies": { + "browser-sync": "^2.7.13", + "gulp": "^3.9.0", + "gulp-concat": "^2.6.0", + "gulp-jshint": "^1.11.2", + "gulp-rename": "^1.2.2", + "gulp-rimraf": "^0.1.1", + "gulp-uglify": "^1.2.0", + "run-sequence": "^1.1.1" + } +} diff --git a/player/vendors/qdclient/qdclient.js b/player/vendors/qdclient/qdclient.js new file mode 100644 index 0000000..e054abe --- /dev/null +++ b/player/vendors/qdclient/qdclient.js @@ -0,0 +1,257 @@ +(function(window, undefined) { + 'use strict'; + + window.qdClient = window.qdClient || {}; + + qdClient.request = function request(url, method, params, callback) { + var xhr = new XMLHttpRequest(); + var raw_params = ""; + + xhr.open(method, url, true); + + xhr.onload = function() { + callback(xhr.status, xhr.responseText); + }; + + if (method == "POST" && params instanceof Object) { + + for(var param in params) { + raw_params += param + '=' + params[param] + '&'; + } + + if (params.length > 1) raw_params.slice(0, -1); + } + + xhr.send(raw_params); + }; + + qdClient.getJSON = function getJSON(url, callback) { + qdClient.request(url, "GET", {}, function(status, response) { + callback(status, JSON.parse(response)); + }); + }; + +}(window)); + +(function(window, localStorage, undefined) { + 'use strict'; + + function Chooser() { + this.server = 'http://150.165.204.39/vlibras-cloud/get_servers.php'; + + this.options = { + THRESHOLDSLOW: 2000, + SLOWLIMITTRIES: 5, + NBESTHEURISTIC1: 2, + QUANTITYPREVIOUSTIMESSTORED: 10 + }; + + this.mirrors = []; + + this.heuristics = { + FIRSTHEURISTIC: { + FIRSTRANDOM : {value: 0, name: "Random"}, + FIRSTRANDOMNBEST: {value: 1, name: "Random Among N Best"}, + FIRSTBEST : {value: 2, name: "Best"} + }, + SECONDHEURISTIC: { + SECONDRANDOM : {value: 0, name: "Random"}, + SECONDCLOSEST: {value: 1, name: "Closest"} + }, + THIRDHEURISTIC: { + THIRDSIMPLEAVERAGE : {value: 0, name: "Simple Average"}, + THIRDWEIGHTEDAVERAGE: {value: 1, name: "Weighted Average"} + } + }; + } + + // Exports + qdClient.Chooser = Chooser; + + Chooser.prototype.choose = function(urlLast, millisLast, response, callback) { + var $this = this; + + this.loadMirrors_(function() { + $this.chooseServer_(urlLast, millisLast, response, callback); + }); + }; + + Chooser.prototype.chooseServer_ = function(urlLast, millisLast, response, callback) { + var firstHeuristic = this.heuristics.FIRSTHEURISTIC.FIRSTBEST; + var secondHeuristic = this.heuristics.SECONDHEURISTIC.SECONDRANDOM; + var thirdHeuristic = this.heuristics.THIRDHEURISTIC.THIRDWEIGHTEDAVERAGE; + + var j = 0, i = 0; /* Fix JSHint */ + + var sizeBest = this.options.NBESTHEURISTIC1; + if (firstHeuristic == this.heuristics.FIRSTHEURISTIC.FIRSTBEST) { + sizeBest = 1; + } + + if (urlLast && urlLast.length > 0) { + for (i = 0; i < this.mirrors.length; i++) { + if (this.mirrors[i].url.toLowerCase() == urlLast.toLowerCase()) { + if (this.mirrors[i].previousTimes.length < this.options.QUANTITYPREVIOUSTIMESSTORED) { + this.mirrors[i].previousTimes[this.mirrors[i].previousTimes.length] = millisLast; + } else { + for (j = this.options.QUANTITYPREVIOUSTIMESSTORED-1; j > 0; j--) { + this.mirrors[i].previousTimes[j-1] = this.mirrors[i].previousTimes[j]; + } + + this.mirrors[i].previousTimes[this.options.QUANTITYPREVIOUSTIMESSTORED-1] = millisLast; + } + + if (thirdHeuristic == this.heuristics.THIRDHEURISTIC.THIRDSIMPLEAVERAGE) { + var totalMillis = 0; + for (j = 0; j < this.mirrors[i].previousTimes.length; j++) { + totalMillis += this.mirrors[i].previousTimes[j]; + } + + this.mirrors[i].averageTime = totalMillis/this.mirrors[i].previousTimes.length; + } else if (thirdHeuristic == this.heuristics.THIRDHEURISTIC.THIRDWEIGHTEDAVERAGE) { + var totalMillisAndWeights = 0; + var totalWeights = 0; + for (j = 0; j < this.mirrors[i].previousTimes.length; j++) { + totalMillisAndWeights += this.mirrors[i].previousTimes[j]*(j+1); + totalWeights += (j+1); + } + + this.mirrors[i].averageTime = totalMillisAndWeights/totalWeights; + } + + if (millisLast > this.options.THRESHOLDSLOW || response == -1) { + this.mirrors[i].isSlow = true; + this.mirrors[i].remainingSlow = this.options.SLOWLIMITTRIES; + } + + localStorage.setItem("servers", JSON.stringify(this.mirrors)); + break; + } + + } + + } + + var position = Math.floor((Math.random() * this.mirrors.length)); + var closestPosition; + + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM) { + position = -1; + closestPosition = -1; + } + + var vectorBest = []; + var k = 0, z = 0; /* JSHint Fix */ + + for (j = 0; j < this.mirrors.length; j++) { + if (this.mirrors[j].remainingSlow > 0) { + this.mirrors[j].remainingSlow = this.mirrors[j].remainingSlow - 1; + } + + if (this.mirrors[j].remainingSlow === 0) { + this.mirrors[j].isSlow = false; + } + + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM && this.mirrors[j].isSlow === false) { + if (closestPosition == -1) { + closestPosition = j; + } + + var added = false; + + for (k = 0; k < vectorBest.length; k++) { + if (this.mirrors[j].averageTime < vectorBest[k].averageTime || (this.mirrors[j].averageTime == vectorBest[k].averageTime && (Math.floor(Math.random()) < 0.5) )) { + + added = true; + + if (vectorBest.length < sizeBest) { + for (z = vectorBest.length-1; z >= k; z--) { + vectorBest[z+1] = vectorBest[z]; + } + } else { + for (z = vectorBest.length-2; z >= k; z--) { + vectorBest[z+1] = vectorBest[z]; + } + } + + vectorBest[k] = this.mirrors[j]; + + break; + } + } + + if (added === false && vectorBest.length < sizeBest) { + vectorBest[vectorBest.length] = this.mirrors[j]; + } + + } + + } + + // pega aleatorio entre as N posicoes dos melhores (se for guloso, tera apenas um elemento no vetor) + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM && vectorBest.length > 0) { + position = Math.floor((Math.random() * vectorBest.length)); + } + + if (position == -1) { + if (secondHeuristic == this.heuristics.SECONDHEURISTIC.SECONDCLOSEST) { + // escolhendo o mais proximo, no caso, o vetor já está ordenado + if (closestPosition != -1) { + position = closestPosition; + } else { + // se nao marcou nenhum como closest, todos devem estar como slow, nesse caso seleciona o primeiro que é o mais próximo + position = 0; + } + + } else { + position = Math.floor((Math.random() * this.mirrors.length)); + } + } + + callback(this.mirrors[position].url); + }; + + Chooser.prototype.loadMirrors_ = function(callback) { + if (this.mirrors.length > 0) { + if (callback instanceof Function) callback(); + + return; + } + + var $this = this; + + var localServers = JSON.parse(localStorage.getItem("servers")) || []; + + qdClient.getJSON(this.server, function (status, response) { + var servers = status === 200 ? response : []; + + for (var i = 0; i < servers.length; i++){ + var mirror = { + name: servers[i].nome, + url: servers[i].url, + averageTime: 99999999, + isSlow: false, + previousTimes: [], + remainingSlow: 0, + type: servers[i].type + }; + + for (var localServer in localServers) { + if (mirror.url == localServer.url) { + mirror.averageTime = localServer.averageTime; + mirror.isSlow = localServer.isSlow; + mirror.previousTimes = localServer.previousTimes; + mirror.remainingSlow = localServer.remainingSlow; + + break; + } + } + + $this.mirrors.push(mirror); + } + + if (callback instanceof Function) callback(); + }); + }; + +}(window, localStorage)); diff --git a/player/vendors/qdclient/qdclient.min.js b/player/vendors/qdclient/qdclient.min.js new file mode 100644 index 0000000..d5273b7 --- /dev/null +++ b/player/vendors/qdclient/qdclient.min.js @@ -0,0 +1 @@ +!function(i,r){"use strict";i.qdClient=i.qdClient||{},qdClient.request=function(i,r,s,e){var t=new XMLHttpRequest,o="";if(t.open(r,i,!0),t.onload=function(){e(t.status,t.responseText)},"POST"==r&&s instanceof Object){for(var n in s)o+=n+"="+s[n]+"&";s.length>1&&o.slice(0,-1)}t.send(o)},qdClient.getJSON=function(i,r){qdClient.request(i,"GET",{},function(i,s){r(i,JSON.parse(s))})}}(window),function(i,r,s){"use strict";function e(){this.server="http://150.165.204.39/vlibras-cloud/get_servers.php",this.options={THRESHOLDSLOW:2e3,SLOWLIMITTRIES:5,NBESTHEURISTIC1:2,QUANTITYPREVIOUSTIMESSTORED:10},this.mirrors=[],this.heuristics={FIRSTHEURISTIC:{FIRSTRANDOM:{value:0,name:"Random"},FIRSTRANDOMNBEST:{value:1,name:"Random Among N Best"},FIRSTBEST:{value:2,name:"Best"}},SECONDHEURISTIC:{SECONDRANDOM:{value:0,name:"Random"},SECONDCLOSEST:{value:1,name:"Closest"}},THIRDHEURISTIC:{THIRDSIMPLEAVERAGE:{value:0,name:"Simple Average"},THIRDWEIGHTEDAVERAGE:{value:1,name:"Weighted Average"}}}}qdClient.Chooser=e,e.prototype.choose=function(i,r,s,e){var t=this;this.loadMirrors_(function(){t.chooseServer_(i,r,s,e)})},e.prototype.chooseServer_=function(i,s,e,t){var o=this.heuristics.FIRSTHEURISTIC.FIRSTBEST,n=this.heuristics.SECONDHEURISTIC.SECONDRANDOM,h=this.heuristics.THIRDHEURISTIC.THIRDWEIGHTEDAVERAGE,T=0,S=0,a=this.options.NBESTHEURISTIC1;if(o==this.heuristics.FIRSTHEURISTIC.FIRSTBEST&&(a=1),i&&i.length>0)for(S=0;S0;T--)this.mirrors[S].previousTimes[T-1]=this.mirrors[S].previousTimes[T];this.mirrors[S].previousTimes[this.options.QUANTITYPREVIOUSTIMESSTORED-1]=s}if(h==this.heuristics.THIRDHEURISTIC.THIRDSIMPLEAVERAGE){var m=0;for(T=0;Tthis.options.THRESHOLDSLOW||-1==e)&&(this.mirrors[S].isSlow=!0,this.mirrors[S].remainingSlow=this.options.SLOWLIMITTRIES),r.setItem("servers",JSON.stringify(this.mirrors));break}var R,E=Math.floor(Math.random()*this.mirrors.length);o!=this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM&&(E=-1,R=-1);var u=[],v=0,g=0;for(T=0;T0&&(this.mirrors[T].remainingSlow=this.mirrors[T].remainingSlow-1),0===this.mirrors[T].remainingSlow&&(this.mirrors[T].isSlow=!1),o!=this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM&&this.mirrors[T].isSlow===!1){-1==R&&(R=T);var f=!1;for(v=0;v=v;g--)u[g+1]=u[g];else for(g=u.length-2;g>=v;g--)u[g+1]=u[g];u[v]=this.mirrors[T];break}f===!1&&u.length0&&(E=Math.floor(Math.random()*u.length)),-1==E&&(E=n==this.heuristics.SECONDHEURISTIC.SECONDCLOSEST?-1!=R?R:0:Math.floor(Math.random()*this.mirrors.length)),t(this.mirrors[E].url)},e.prototype.loadMirrors_=function(i){if(this.mirrors.length>0)return void(i instanceof Function&&i());var s=this,e=JSON.parse(r.getItem("servers"))||[];qdClient.getJSON(this.server,function(r,t){for(var o=200===r?t:[],n=0;n + + + + + VLibras Plugin + + + + + + + + + + +
Carregando...
+
+ +
+ + + + + + -- libgit2 0.21.2