Commit ede36ec8594fc201627cc5d0c13e121fd9970a25

Authored by David Guilherme
1 parent 851003bb
Exists in master

Automatiza a compilação do player para os demais plugins

Showing 53 changed files with 949 additions and 625 deletions   Show diff stats
.gitignore
1   -chrome/app/Release
2   -chrome/app/vendors
  1 +chrome/app/player
  2 +firefox/data/player
3 3  
4   -firefox/data/app/Release
5   -firefox/data/app/vendors
  4 +node_modules
... ...
Gulpfile.js 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +var gulp = require('gulp');
  2 +
  3 +var playerFiles = [
  4 + 'connect.js',
  5 + 'load.js',
  6 + 'window.html',
  7 + 'TemplateData/*',
  8 + 'vendors/**/*'
  9 +];
  10 +
  11 +gulp.task('chrome', function() {
  12 + gulp.src(playerFiles, { base: '.', cwd: 'player/' })
  13 + .pipe(gulp.dest('chrome/app'));
  14 +});
  15 +
  16 +gulp.task('firefox', function() {
  17 + gulp.src(playerFiles, { base: '.', cwd: 'player/' })
  18 + .pipe(gulp.dest('firefox/data'));
  19 +});
... ...
chrome/.bowerrc
... ... @@ -1,3 +0,0 @@
1   -{
2   - "directory": "app/vendors"
3   -}
chrome/app/TemplateData/Thumbs.db
No preview for this file type
chrome/app/TemplateData/UnityProgress.js
... ... @@ -1,97 +0,0 @@
1   -function UnityProgress (dom) {
2   - this.progress = 0.0;
3   - this.message = "";
4   - this.dom = dom;
5   -
6   - var parent = dom.parentNode;
7   -
8   - var background = document.createElement("div");
9   - background.style.background = "#FFFFFF";
10   - background.style.position = "absolute";
11   - parent.appendChild(background);
12   - this.background = background;
13   -
14   - var logoImage = document.createElement("img");
15   - logoImage.src = "TemplateData/progresslogo.png";
16   - logoImage.style.position = "absolute";
17   - parent.appendChild(logoImage);
18   - this.logoImage = logoImage;
19   -
20   - var progressFrame = document.createElement("img");
21   - progressFrame.src = "TemplateData/loadingbar.png";
22   - progressFrame.style.position = "absolute";
23   - parent.appendChild(progressFrame);
24   - this.progressFrame = progressFrame;
25   -
26   - var progressBar = document.createElement("img");
27   - progressBar.src = "TemplateData/fullbar.png";
28   - progressBar.style.position = "absolute";
29   - parent.appendChild(progressBar);
30   - this.progressBar = progressBar;
31   -
32   - var messageArea = document.createElement("p");
33   - messageArea.style.position = "absolute";
34   - parent.appendChild(messageArea);
35   - this.messageArea = messageArea;
36   -
37   -
38   - this.SetProgress = function (progress) {
39   - if (this.progress < progress)
40   - this.progress = progress;
41   - this.messageArea.style.display = "none";
42   - this.progressFrame.style.display = "inline";
43   - this.progressBar.style.display = "inline";
44   - this.Update();
45   - }
46   -
47   - this.SetMessage = function (message) {
48   - this.message = message;
49   - this.background.style.display = "inline";
50   - this.logoImage.style.display = "inline";
51   - this.progressFrame.style.display = "none";
52   - this.progressBar.style.display = "none";
53   - this.Update();
54   - }
55   -
56   - this.Clear = function() {
57   - this.background.style.display = "none";
58   - this.logoImage.style.display = "none";
59   - this.progressFrame.style.display = "none";
60   - this.progressBar.style.display = "none";
61   - }
62   -
63   - this.Update = function() {
64   - this.background.style.top = this.dom.offsetTop + 'px';
65   - this.background.style.left = this.dom.offsetLeft + 'px';
66   - this.background.style.width = this.dom.offsetWidth + 'px';
67   - this.background.style.height = this.dom.offsetHeight + 'px';
68   -
69   - var logoImg = new Image();
70   - logoImg.src = this.logoImage.src;
71   - var progressFrameImg = new Image();
72   - progressFrameImg.src = this.progressFrame.src;
73   -
74   - this.logoImage.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 - logoImg.height * 0.5) + 'px';
75   - this.logoImage.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - logoImg.width * 0.5) + 'px';
76   - this.logoImage.style.width = logoImg.width+'px';
77   - this.logoImage.style.height = logoImg.height+'px';
78   -
79   - this.progressFrame.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 + logoImg.height * 0.5 + 10) + 'px';
80   - this.progressFrame.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - progressFrameImg.width * 0.5) + 'px';
81   - this.progressFrame.width = progressFrameImg.width;
82   - this.progressFrame.height = progressFrameImg.height;
83   -
84   - this.progressBar.style.top = this.progressFrame.style.top;
85   - this.progressBar.style.left = this.progressFrame.style.left;
86   - this.progressBar.width = progressFrameImg.width * Math.min(this.progress, 1);
87   - this.progressBar.height = progressFrameImg.height;
88   -
89   - this.messageArea.style.top = this.progressFrame.style.top;
90   - this.messageArea.style.left = 0;
91   - this.messageArea.style.width = '100%';
92   - this.messageArea.style.textAlign = 'center';
93   - this.messageArea.innerHTML = this.message;
94   - }
95   -
96   - this.Update ();
97   -}
98 0 \ No newline at end of file
chrome/app/TemplateData/default-cover.jpg

51.6 KB

chrome/app/TemplateData/favicon.png

18.4 KB

chrome/app/TemplateData/fullbar.png

2.71 KB

chrome/app/TemplateData/loadingbar.png

2.78 KB

chrome/app/TemplateData/progresslogo.png

20.7 KB

chrome/app/TemplateData/style.css
... ... @@ -1,28 +0,0 @@
1   -
2   -/****************************************
3   - ==== RESETS
4   -****************************************/
5   -
6   -html,body,div,canvas { margin: 0; padding: 0; }
7   -::-moz-selection { color: #333; text-shadow: none; }
8   -::selection { color: #333; text-shadow: none; }
9   -.clear:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
10   -.clear { display: inline-table; clear: both; }
11   -/* Hides from IE-mac \*/ * html .clear { height: 1%; } .clear { display: block; } /* End hide from IE-mac */
12   -
13   -/****************************************
14   - ==== LAYOUT
15   -****************************************/
16   -
17   -html, body { width: 100%; height: 100%; font-family: Helvetica, Verdana, Arial, sans-serif; }
18   -body { }
19   -p.header, p.footer { display: none; }
20   -div.logo { width: 196px; height: 38px; float: left; background: url(logo.png) 0 0 no-repeat; position: relative; z-index: 10; }
21   -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; }
22   -.template-wrap { position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); }
23   -.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); }
24   -.fullscreen { float: right; position: relative; z-index: 10; }
25   -
26   -body.template { }
27   -.template .template-wrap { }
28   -.template .template-wrap canvas { }
chrome/app/connect.js
... ... @@ -1,39 +0,0 @@
1   -// connect to canvas
2   - var Module = {
3   - filePackagePrefixURL: "Release/",
4   - memoryInitializerPrefixURL: "Release/",
5   - preRun: [],
6   - postRun: [],
7   - print: (function() {
8   - return function(text) {
9   - console.log (text);
10   - };
11   - })(),
12   - printErr: function(text) {
13   - console.error (text);
14   - },
15   - canvas: document.getElementById('canvas'),
16   - progress: null,
17   - setStatus: function(text) {
18   - if (this.progress == null)
19   - {
20   - if (typeof UnityProgress != 'function')
21   - return;
22   - this.progress = new UnityProgress (canvas);
23   - }
24   - if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
25   - if (text === Module.setStatus.text) return;
26   - this.progress.SetMessage (text);
27   - var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
28   - if (m)
29   - this.progress.SetProgress (parseInt(m[2])/parseInt(m[4]));
30   - if (text === "")
31   - this.progress.Clear()
32   - },
33   - totalDependencies: 0,
34   - monitorRunDependencies: function(left) {
35   - this.totalDependencies = Math.max(this.totalDependencies, left);
36   - Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
37   - }
38   - };
39   - Module.setStatus('Downloading (0.0/1)');
40 0 \ No newline at end of file
chrome/app/load.js
... ... @@ -1,26 +0,0 @@
1   -if (!(!Math.fround)) {
2   - var script = document.createElement('script');
3   - script.src = "Release/VLibrasWebPlayer.js";
4   - document.body.appendChild(script);
5   -} else {
6   - var codeXHR = new XMLHttpRequest();
7   - codeXHR.open('GET', 'Release/VLibrasWebPlayer.js', true);
8   - codeXHR.onload = function() {
9   - var code = codeXHR.responseText;
10   - if (!Math.fround) {
11   -console.log('optimizing out Math.fround calls');
12   -code = code.replace(/Math_fround\(/g, '(').replace("'use asm'", "'almost asm'")
13   - }
14   -
15   - var blob = new Blob([code], { type: 'text/javascript' });
16   - codeXHR = null;
17   - var src = URL.createObjectURL(blob);
18   - var script = document.createElement('script');
19   - script.src = URL.createObjectURL(blob);
20   - script.onload = function() {
21   - URL.revokeObjectURL(script.src);
22   - };
23   - document.body.appendChild(script);
24   - };
25   - codeXHR.send(null);
26   -}
27 0 \ No newline at end of file
chrome/app/main.js
... ... @@ -1,48 +0,0 @@
1   -var app = {
2   - chooser: null,
3   - glosa: undefined,
4   - loaded: false,
5   - lastReq: {
6   - url: null,
7   - millis: null,
8   - response: null
9   - }
10   -};
11   -
12   -function onLoadPlayer() {
13   - if ( app.glosa !== undefined ) {
14   - SendMessage('Avatar', 'catchGlosa', app.glosa);
15   - }
16   -
17   - app.loaded = true;
18   -}
19   -
20   -chrome.runtime.onMessage.addListener(
21   - function(request, sender, sendResponse) {
22   - app.chooser = app.chooser || new qdClient.Chooser();
23   -
24   - document.getElementById('loading-screen').style.display = 'block';
25   - app.chooser.choose(
26   - app.lastReq.url,
27   - app.lastReq.millis,
28   - app.lastReq.response,
29   - function (url) {
30   - var start = new Date().getTime();
31   -
32   - qdClient.request(url + '?texto=' + request.selectedText, "GET", {},
33   - function(status, response) {
34   - app.lastReq.response = status === 404 ? -1 : status;
35   - app.lastReq.millis = (new Date().getTime() - start);
36   - app.lastReq.url = url;
37   -
38   - app.glosa = response;
39   -
40   - document.getElementById('loading-screen').style.display = 'none';
41   - if (app.loaded == true) {
42   - SendMessage('Avatar', 'catchGlosa', app.glosa);
43   - }
44   - });
45   - });
46   - });
47   -
48   -chrome.runtime.sendMessage({ready: true});
chrome/app/window.html
... ... @@ -1,57 +0,0 @@
1   -<!doctype html>
2   -<html lang="en-us">
3   - <head>
4   - <meta charset="utf-8">
5   - <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6   - <title>VLibras Plugin</title>
7   - <link rel="stylesheet" href="TemplateData/style.css">
8   - <link rel="shortcut icon" href="TemplateData/favicon.ico?v=2" />
9   - <script src="TemplateData/UnityProgress.js"></script>
10   -
11   - <script src="vendors/qdclient/qdclient.js"></script>
12   - <script src="main.js"></script>
13   -
14   - <style type="text/css">
15   - html, #canvas, .template, .template-wrap {
16   - width: 100%;
17   - height: 100%;
18   - margin: 0;
19   - overflow: hidden;
20   - }
21   -
22   - #loading-screen span {
23   - position: absolute;
24   - top: 5px;
25   - right: 40px;
26   - padding: 15px 10px;
27   - background: #000;
28   - color: #FFF;
29   -
30   - font-size: 1.2em;
31   - -webkit-border-radius: 20px;
32   - -moz-border-radius: 20px;
33   - border-radius: 20px;
34   - }
35   -
36   - #loading-screen {
37   - position: absolute;
38   - top: 0;
39   - left: 0;
40   - display: none;
41   - width: 100%;
42   - height: 100%;
43   - z-index: 9999;
44   - }
45   - </style>
46   - </head>
47   - <body class="template">
48   - <div id="loading-screen"><span>Carregando...</span></div>
49   - <div class="template-wrap clear">
50   - <canvas class="emscripten" id="canvas"></canvas>
51   - </div>
52   - <script src="connect.js"></script>
53   -<script src="Release/UnityConfig.js"></script>
54   -<script src="Release/fileloader.js"></script>
55   -<script src="load.js"></script>
56   - </body>
57   -</html>
chrome/bower.json
... ... @@ -1,14 +0,0 @@
1   -{
2   - "name": "vlibras-chrome",
3   - "version": "0.0.1",
4   - "ignore": [
5   - "**/.*",
6   - "node_modules",
7   - "bower_components",
8   - "test",
9   - "tests"
10   - ],
11   - "devDependencies": {
12   - "qdclient": "git@git.lavid.ufpb.br:qdclient.git"
13   - }
14   -}
firefox/.bowerrc
... ... @@ -1,3 +0,0 @@
1   -{
2   - "directory": "data/app/vendors"
3   -}
firefox/bower.json
... ... @@ -1,14 +0,0 @@
1   -{
2   - "name": "vlibras-firefox",
3   - "version": "0.0.1",
4   - "ignore": [
5   - "**/.*",
6   - "node_modules",
7   - "bower_components",
8   - "test",
9   - "tests"
10   - ],
11   - "devDependencies": {
12   - "qdclient": "git@git.lavid.ufpb.br:qdclient.git"
13   - }
14   -}
firefox/data/app/TemplateData/Thumbs.db
No preview for this file type
firefox/data/app/TemplateData/UnityProgress.js
... ... @@ -1,97 +0,0 @@
1   -function UnityProgress (dom) {
2   - this.progress = 0.0;
3   - this.message = "";
4   - this.dom = dom;
5   -
6   - var parent = dom.parentNode;
7   -
8   - var background = document.createElement("div");
9   - background.style.background = "#FFFFFF";
10   - background.style.position = "absolute";
11   - parent.appendChild(background);
12   - this.background = background;
13   -
14   - var logoImage = document.createElement("img");
15   - logoImage.src = "TemplateData/progresslogo.png";
16   - logoImage.style.position = "absolute";
17   - parent.appendChild(logoImage);
18   - this.logoImage = logoImage;
19   -
20   - var progressFrame = document.createElement("img");
21   - progressFrame.src = "TemplateData/loadingbar.png";
22   - progressFrame.style.position = "absolute";
23   - parent.appendChild(progressFrame);
24   - this.progressFrame = progressFrame;
25   -
26   - var progressBar = document.createElement("img");
27   - progressBar.src = "TemplateData/fullbar.png";
28   - progressBar.style.position = "absolute";
29   - parent.appendChild(progressBar);
30   - this.progressBar = progressBar;
31   -
32   - var messageArea = document.createElement("p");
33   - messageArea.style.position = "absolute";
34   - parent.appendChild(messageArea);
35   - this.messageArea = messageArea;
36   -
37   -
38   - this.SetProgress = function (progress) {
39   - if (this.progress < progress)
40   - this.progress = progress;
41   - this.messageArea.style.display = "none";
42   - this.progressFrame.style.display = "inline";
43   - this.progressBar.style.display = "inline";
44   - this.Update();
45   - }
46   -
47   - this.SetMessage = function (message) {
48   - this.message = message;
49   - this.background.style.display = "inline";
50   - this.logoImage.style.display = "inline";
51   - this.progressFrame.style.display = "none";
52   - this.progressBar.style.display = "none";
53   - this.Update();
54   - }
55   -
56   - this.Clear = function() {
57   - this.background.style.display = "none";
58   - this.logoImage.style.display = "none";
59   - this.progressFrame.style.display = "none";
60   - this.progressBar.style.display = "none";
61   - }
62   -
63   - this.Update = function() {
64   - this.background.style.top = this.dom.offsetTop + 'px';
65   - this.background.style.left = this.dom.offsetLeft + 'px';
66   - this.background.style.width = this.dom.offsetWidth + 'px';
67   - this.background.style.height = this.dom.offsetHeight + 'px';
68   -
69   - var logoImg = new Image();
70   - logoImg.src = this.logoImage.src;
71   - var progressFrameImg = new Image();
72   - progressFrameImg.src = this.progressFrame.src;
73   -
74   - this.logoImage.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 - logoImg.height * 0.5) + 'px';
75   - this.logoImage.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - logoImg.width * 0.5) + 'px';
76   - this.logoImage.style.width = logoImg.width+'px';
77   - this.logoImage.style.height = logoImg.height+'px';
78   -
79   - this.progressFrame.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 + logoImg.height * 0.5 + 10) + 'px';
80   - this.progressFrame.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - progressFrameImg.width * 0.5) + 'px';
81   - this.progressFrame.width = progressFrameImg.width;
82   - this.progressFrame.height = progressFrameImg.height;
83   -
84   - this.progressBar.style.top = this.progressFrame.style.top;
85   - this.progressBar.style.left = this.progressFrame.style.left;
86   - this.progressBar.width = progressFrameImg.width * Math.min(this.progress, 1);
87   - this.progressBar.height = progressFrameImg.height;
88   -
89   - this.messageArea.style.top = this.progressFrame.style.top;
90   - this.messageArea.style.left = 0;
91   - this.messageArea.style.width = '100%';
92   - this.messageArea.style.textAlign = 'center';
93   - this.messageArea.innerHTML = this.message;
94   - }
95   -
96   - this.Update ();
97   -}
98 0 \ No newline at end of file
firefox/data/app/TemplateData/default-cover.jpg

51.6 KB

firefox/data/app/TemplateData/favicon.png

18.4 KB

firefox/data/app/TemplateData/fullbar.png

2.71 KB

firefox/data/app/TemplateData/loadingbar.png

2.78 KB

firefox/data/app/TemplateData/progresslogo.png

20.7 KB

firefox/data/app/TemplateData/style.css
... ... @@ -1,28 +0,0 @@
1   -
2   -/****************************************
3   - ==== RESETS
4   -****************************************/
5   -
6   -html,body,div,canvas { margin: 0; padding: 0; }
7   -::-moz-selection { color: #333; text-shadow: none; }
8   -::selection { color: #333; text-shadow: none; }
9   -.clear:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
10   -.clear { display: inline-table; clear: both; }
11   -/* Hides from IE-mac \*/ * html .clear { height: 1%; } .clear { display: block; } /* End hide from IE-mac */
12   -
13   -/****************************************
14   - ==== LAYOUT
15   -****************************************/
16   -
17   -html, body { width: 100%; height: 100%; font-family: Helvetica, Verdana, Arial, sans-serif; }
18   -body { }
19   -p.header, p.footer { display: none; }
20   -div.logo { width: 196px; height: 38px; float: left; background: url(logo.png) 0 0 no-repeat; position: relative; z-index: 10; }
21   -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; }
22   -.template-wrap { position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); }
23   -.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); }
24   -.fullscreen { float: right; position: relative; z-index: 10; }
25   -
26   -body.template { }
27   -.template .template-wrap { }
28   -.template .template-wrap canvas { }
firefox/data/app/connect.js
... ... @@ -1,39 +0,0 @@
1   -// connect to canvas
2   - var Module = {
3   - filePackagePrefixURL: "Release/",
4   - memoryInitializerPrefixURL: "Release/",
5   - preRun: [],
6   - postRun: [],
7   - print: (function() {
8   - return function(text) {
9   - console.log (text);
10   - };
11   - })(),
12   - printErr: function(text) {
13   - console.error (text);
14   - },
15   - canvas: document.getElementById('canvas'),
16   - progress: null,
17   - setStatus: function(text) {
18   - if (this.progress == null)
19   - {
20   - if (typeof UnityProgress != 'function')
21   - return;
22   - this.progress = new UnityProgress (canvas);
23   - }
24   - if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
25   - if (text === Module.setStatus.text) return;
26   - this.progress.SetMessage (text);
27   - var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
28   - if (m)
29   - this.progress.SetProgress (parseInt(m[2])/parseInt(m[4]));
30   - if (text === "")
31   - this.progress.Clear()
32   - },
33   - totalDependencies: 0,
34   - monitorRunDependencies: function(left) {
35   - this.totalDependencies = Math.max(this.totalDependencies, left);
36   - Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
37   - }
38   - };
39   - Module.setStatus('Downloading (0.0/1)');
40 0 \ No newline at end of file
firefox/data/app/load.js
... ... @@ -1,26 +0,0 @@
1   -if (!(!Math.fround)) {
2   - var script = document.createElement('script');
3   - script.src = "Release/VLibrasWebPlayer.js";
4   - document.body.appendChild(script);
5   -} else {
6   - var codeXHR = new XMLHttpRequest();
7   - codeXHR.open('GET', 'Release/VLibrasWebPlayer.js', true);
8   - codeXHR.onload = function() {
9   - var code = codeXHR.responseText;
10   - if (!Math.fround) {
11   -console.log('optimizing out Math.fround calls');
12   -code = code.replace(/Math_fround\(/g, '(').replace("'use asm'", "'almost asm'")
13   - }
14   -
15   - var blob = new Blob([code], { type: 'text/javascript' });
16   - codeXHR = null;
17   - var src = URL.createObjectURL(blob);
18   - var script = document.createElement('script');
19   - script.src = URL.createObjectURL(blob);
20   - script.onload = function() {
21   - URL.revokeObjectURL(script.src);
22   - };
23   - document.body.appendChild(script);
24   - };
25   - codeXHR.send(null);
26   -}
27 0 \ No newline at end of file
firefox/data/app/main.js
... ... @@ -1,45 +0,0 @@
1   -var app = {
2   - chooser: null,
3   - glosa: undefined,
4   - loaded: false,
5   - lastReq: {
6   - url: null,
7   - millis: null,
8   - response: null
9   - }
10   -};
11   -
12   -function onLoadPlayer() {
13   - if ( app.glosa !== undefined ) {
14   - SendMessage('Avatar', 'catchGlosa', app.glosa);
15   - }
16   -
17   - app.loaded = true;
18   -}
19   -
20   -document.addEventListener('plugin:selectedText', function(e) {
21   - app.chooser = app.chooser || new qdClient.Chooser();
22   -
23   - document.getElementById('loading-screen').style.display = 'block';
24   - app.chooser.choose(
25   - app.lastReq.url,
26   - app.lastReq.millis,
27   - app.lastReq.response,
28   - function (url) {
29   - var start = new Date().getTime();
30   -
31   - qdClient.request(url + '?texto=' + e.detail, "GET", {},
32   - function(status, response) {
33   - app.lastReq.response = status === 404 ? -1 : status;
34   - app.lastReq.millis = (new Date().getTime() - start);
35   - app.lastReq.url = url;
36   -
37   - app.glosa = response;
38   -
39   - document.getElementById('loading-screen').style.display = 'none';
40   - if (app.loaded == true) {
41   - SendMessage('Avatar', 'catchGlosa', app.glosa);
42   - }
43   - });
44   - });
45   -});
firefox/data/app/window.html
... ... @@ -1,57 +0,0 @@
1   -<!doctype html>
2   -<html lang="en-us">
3   - <head>
4   - <meta charset="utf-8">
5   - <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6   - <title>VLibras Plugin</title>
7   - <link rel="stylesheet" href="TemplateData/style.css">
8   - <link rel="shortcut icon" href="TemplateData/favicon.ico?v=2" />
9   - <script src="TemplateData/UnityProgress.js"></script>
10   -
11   - <script src="vendors/qdclient/qdclient.js"></script>
12   - <script src="main.js"></script>
13   -
14   - <style type="text/css">
15   - html, #canvas, .template, .template-wrap {
16   - width: 100%;
17   - height: 100%;
18   - margin: 0;
19   - overflow: hidden;
20   - }
21   -
22   - #loading-screen span {
23   - position: absolute;
24   - top: 5px;
25   - right: 40px;
26   - padding: 15px 10px;
27   - background: #000;
28   - color: #FFF;
29   -
30   - font-size: 1.2em;
31   - -webkit-border-radius: 20px;
32   - -moz-border-radius: 20px;
33   - border-radius: 20px;
34   - }
35   -
36   - #loading-screen {
37   - position: absolute;
38   - top: 0;
39   - left: 0;
40   - display: none;
41   - width: 100%;
42   - height: 100%;
43   - z-index: 9999;
44   - }
45   - </style>
46   - </head>
47   - <body class="template">
48   - <div id="loading-screen"><span>Carregando...</span></div>
49   - <div class="template-wrap clear">
50   - <canvas class="emscripten" id="canvas"></canvas>
51   - </div>
52   - <script src="connect.js"></script>
53   -<script src="Release/UnityConfig.js"></script>
54   -<script src="Release/fileloader.js"></script>
55   -<script src="load.js"></script>
56   - </body>
57   -</html>
firefox/data/main.js 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +var app = {
  2 + chooser: null,
  3 + glosa: undefined,
  4 + loaded: false,
  5 + lastReq: {
  6 + url: null,
  7 + millis: null,
  8 + response: null
  9 + }
  10 +};
  11 +
  12 +function onLoadPlayer() {
  13 + if ( app.glosa !== undefined ) {
  14 + SendMessage('Avatar', 'catchGlosa', app.glosa);
  15 + }
  16 +
  17 + app.loaded = true;
  18 +}
  19 +
  20 +document.addEventListener('plugin:selectedText', function(e) {
  21 + app.chooser = app.chooser || new qdClient.Chooser();
  22 +
  23 + document.getElementById('loading-screen').style.display = 'block';
  24 + app.chooser.choose(
  25 + app.lastReq.url,
  26 + app.lastReq.millis,
  27 + app.lastReq.response,
  28 + function (url) {
  29 + var start = new Date().getTime();
  30 +
  31 + qdClient.request(url + '?texto=' + e.detail, "GET", {},
  32 + function(status, response) {
  33 + app.lastReq.response = status === 404 ? -1 : status;
  34 + app.lastReq.millis = (new Date().getTime() - start);
  35 + app.lastReq.url = url;
  36 +
  37 + app.glosa = response;
  38 +
  39 + document.getElementById('loading-screen').style.display = 'none';
  40 + if (app.loaded == true) {
  41 + SendMessage('Avatar', 'catchGlosa', app.glosa);
  42 + }
  43 + });
  44 + });
  45 +});
... ...
package.json 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +{
  2 + "name": "vlibras-plugin",
  3 + "version": "1.0.0",
  4 + "description": "",
  5 + "devDependencies": {
  6 + "gulp": "^3.9.0"
  7 + }
  8 +}
... ...
player/.bowerrc 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +{
  2 + "directory": "vendors"
  3 +}
... ...
player/TemplateData/Thumbs.db 0 → 100644
No preview for this file type
player/TemplateData/UnityProgress.js 0 → 100644
... ... @@ -0,0 +1,97 @@
  1 +function UnityProgress (dom) {
  2 + this.progress = 0.0;
  3 + this.message = "";
  4 + this.dom = dom;
  5 +
  6 + var parent = dom.parentNode;
  7 +
  8 + var background = document.createElement("div");
  9 + background.style.background = "#FFFFFF";
  10 + background.style.position = "absolute";
  11 + parent.appendChild(background);
  12 + this.background = background;
  13 +
  14 + var logoImage = document.createElement("img");
  15 + logoImage.src = "TemplateData/progresslogo.png";
  16 + logoImage.style.position = "absolute";
  17 + parent.appendChild(logoImage);
  18 + this.logoImage = logoImage;
  19 +
  20 + var progressFrame = document.createElement("img");
  21 + progressFrame.src = "TemplateData/loadingbar.png";
  22 + progressFrame.style.position = "absolute";
  23 + parent.appendChild(progressFrame);
  24 + this.progressFrame = progressFrame;
  25 +
  26 + var progressBar = document.createElement("img");
  27 + progressBar.src = "TemplateData/fullbar.png";
  28 + progressBar.style.position = "absolute";
  29 + parent.appendChild(progressBar);
  30 + this.progressBar = progressBar;
  31 +
  32 + var messageArea = document.createElement("p");
  33 + messageArea.style.position = "absolute";
  34 + parent.appendChild(messageArea);
  35 + this.messageArea = messageArea;
  36 +
  37 +
  38 + this.SetProgress = function (progress) {
  39 + if (this.progress < progress)
  40 + this.progress = progress;
  41 + this.messageArea.style.display = "none";
  42 + this.progressFrame.style.display = "inline";
  43 + this.progressBar.style.display = "inline";
  44 + this.Update();
  45 + }
  46 +
  47 + this.SetMessage = function (message) {
  48 + this.message = message;
  49 + this.background.style.display = "inline";
  50 + this.logoImage.style.display = "inline";
  51 + this.progressFrame.style.display = "none";
  52 + this.progressBar.style.display = "none";
  53 + this.Update();
  54 + }
  55 +
  56 + this.Clear = function() {
  57 + this.background.style.display = "none";
  58 + this.logoImage.style.display = "none";
  59 + this.progressFrame.style.display = "none";
  60 + this.progressBar.style.display = "none";
  61 + }
  62 +
  63 + this.Update = function() {
  64 + this.background.style.top = this.dom.offsetTop + 'px';
  65 + this.background.style.left = this.dom.offsetLeft + 'px';
  66 + this.background.style.width = this.dom.offsetWidth + 'px';
  67 + this.background.style.height = this.dom.offsetHeight + 'px';
  68 +
  69 + var logoImg = new Image();
  70 + logoImg.src = this.logoImage.src;
  71 + var progressFrameImg = new Image();
  72 + progressFrameImg.src = this.progressFrame.src;
  73 +
  74 + this.logoImage.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 - logoImg.height * 0.5) + 'px';
  75 + this.logoImage.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - logoImg.width * 0.5) + 'px';
  76 + this.logoImage.style.width = logoImg.width+'px';
  77 + this.logoImage.style.height = logoImg.height+'px';
  78 +
  79 + this.progressFrame.style.top = this.dom.offsetTop + (this.dom.offsetHeight * 0.5 + logoImg.height * 0.5 + 10) + 'px';
  80 + this.progressFrame.style.left = this.dom.offsetLeft + (this.dom.offsetWidth * 0.5 - progressFrameImg.width * 0.5) + 'px';
  81 + this.progressFrame.width = progressFrameImg.width;
  82 + this.progressFrame.height = progressFrameImg.height;
  83 +
  84 + this.progressBar.style.top = this.progressFrame.style.top;
  85 + this.progressBar.style.left = this.progressFrame.style.left;
  86 + this.progressBar.width = progressFrameImg.width * Math.min(this.progress, 1);
  87 + this.progressBar.height = progressFrameImg.height;
  88 +
  89 + this.messageArea.style.top = this.progressFrame.style.top;
  90 + this.messageArea.style.left = 0;
  91 + this.messageArea.style.width = '100%';
  92 + this.messageArea.style.textAlign = 'center';
  93 + this.messageArea.innerHTML = this.message;
  94 + }
  95 +
  96 + this.Update ();
  97 +}
0 98 \ No newline at end of file
... ...
player/TemplateData/default-cover.jpg 0 → 100644

51.6 KB

player/TemplateData/favicon.png 0 → 100644

18.4 KB

player/TemplateData/fullbar.png 0 → 100644

2.71 KB

player/TemplateData/loadingbar.png 0 → 100644

2.78 KB

player/TemplateData/progresslogo.png 0 → 100644

20.7 KB

player/TemplateData/style.css 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +
  2 +/****************************************
  3 + ==== RESETS
  4 +****************************************/
  5 +
  6 +html,body,div,canvas { margin: 0; padding: 0; }
  7 +::-moz-selection { color: #333; text-shadow: none; }
  8 +::selection { color: #333; text-shadow: none; }
  9 +.clear:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
  10 +.clear { display: inline-table; clear: both; }
  11 +/* Hides from IE-mac \*/ * html .clear { height: 1%; } .clear { display: block; } /* End hide from IE-mac */
  12 +
  13 +/****************************************
  14 + ==== LAYOUT
  15 +****************************************/
  16 +
  17 +html, body { width: 100%; height: 100%; font-family: Helvetica, Verdana, Arial, sans-serif; }
  18 +body { }
  19 +p.header, p.footer { display: none; }
  20 +div.logo { width: 196px; height: 38px; float: left; background: url(logo.png) 0 0 no-repeat; position: relative; z-index: 10; }
  21 +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; }
  22 +.template-wrap { position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); }
  23 +.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); }
  24 +.fullscreen { float: right; position: relative; z-index: 10; }
  25 +
  26 +body.template { }
  27 +.template .template-wrap { }
  28 +.template .template-wrap canvas { }
... ...
player/bower.json 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +{
  2 + "name": "vlibras-player",
  3 + "version": "0.0.1",
  4 + "ignore": [
  5 + "**/.*",
  6 + "node_modules",
  7 + "bower_components",
  8 + "test",
  9 + "tests"
  10 + ],
  11 + "devDependencies": {
  12 + "qdclient": "git@git.lavid.ufpb.br:qdclient.git"
  13 + }
  14 +}
... ...
player/connect.js 0 → 100644
... ... @@ -0,0 +1,39 @@
  1 +// connect to canvas
  2 + var Module = {
  3 + filePackagePrefixURL: "Release/",
  4 + memoryInitializerPrefixURL: "Release/",
  5 + preRun: [],
  6 + postRun: [],
  7 + print: (function() {
  8 + return function(text) {
  9 + console.log (text);
  10 + };
  11 + })(),
  12 + printErr: function(text) {
  13 + console.error (text);
  14 + },
  15 + canvas: document.getElementById('canvas'),
  16 + progress: null,
  17 + setStatus: function(text) {
  18 + if (this.progress == null)
  19 + {
  20 + if (typeof UnityProgress != 'function')
  21 + return;
  22 + this.progress = new UnityProgress (canvas);
  23 + }
  24 + if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
  25 + if (text === Module.setStatus.text) return;
  26 + this.progress.SetMessage (text);
  27 + var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
  28 + if (m)
  29 + this.progress.SetProgress (parseInt(m[2])/parseInt(m[4]));
  30 + if (text === "")
  31 + this.progress.Clear()
  32 + },
  33 + totalDependencies: 0,
  34 + monitorRunDependencies: function(left) {
  35 + this.totalDependencies = Math.max(this.totalDependencies, left);
  36 + Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
  37 + }
  38 + };
  39 + Module.setStatus('Downloading (0.0/1)');
0 40 \ No newline at end of file
... ...
player/load.js 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +if (!(!Math.fround)) {
  2 + var script = document.createElement('script');
  3 + script.src = "Release/VLibrasWebPlayer.js";
  4 + document.body.appendChild(script);
  5 +} else {
  6 + var codeXHR = new XMLHttpRequest();
  7 + codeXHR.open('GET', 'Release/VLibrasWebPlayer.js', true);
  8 + codeXHR.onload = function() {
  9 + var code = codeXHR.responseText;
  10 + if (!Math.fround) {
  11 +console.log('optimizing out Math.fround calls');
  12 +code = code.replace(/Math_fround\(/g, '(').replace("'use asm'", "'almost asm'")
  13 + }
  14 +
  15 + var blob = new Blob([code], { type: 'text/javascript' });
  16 + codeXHR = null;
  17 + var src = URL.createObjectURL(blob);
  18 + var script = document.createElement('script');
  19 + script.src = URL.createObjectURL(blob);
  20 + script.onload = function() {
  21 + URL.revokeObjectURL(script.src);
  22 + };
  23 + document.body.appendChild(script);
  24 + };
  25 + codeXHR.send(null);
  26 +}
0 27 \ No newline at end of file
... ...
player/vendors/qdclient/.bower.json 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +{
  2 + "name": "qdclient",
  3 + "main": [
  4 + "qdclient.js"
  5 + ],
  6 + "ignore": [
  7 + "**/.*",
  8 + "Gulpfile.js",
  9 + "demo",
  10 + "node_modules",
  11 + "vendor",
  12 + "tests"
  13 + ],
  14 + "devDependencies": {
  15 + "mocha": "~2.2.5",
  16 + "chai": "~3.0.0"
  17 + },
  18 + "_release": "2b32d629d0",
  19 + "_resolution": {
  20 + "type": "branch",
  21 + "branch": "master",
  22 + "commit": "2b32d629d0a6c4818ad5dd53c22bd000d37a7893"
  23 + },
  24 + "_source": "git@git.lavid.ufpb.br:qdclient.git",
  25 + "_target": "*",
  26 + "_originalSource": "git@git.lavid.ufpb.br:qdclient.git"
  27 +}
0 28 \ No newline at end of file
... ...
player/vendors/qdclient/README 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +qdClient
  2 +=========
  3 +
  4 +1. Tools
  5 +----------------
  6 +
  7 +1. NodeJS
  8 +2. NPM - Node Package Manager
  9 +3. Bower - Frontend dependencies
  10 +4. Gulp - Build tools
  11 +
  12 +2. Installing dependencies
  13 +----------------
  14 +
  15 +```bash
  16 +$ npm install
  17 +$ bower install
  18 +```
  19 +
  20 +3. Demo
  21 +----------------
  22 +```bash
  23 +$ gulp demo
  24 +```
  25 +
  26 +4. Building
  27 +----------------
  28 +```bash
  29 +$ gulp build
  30 +```
  31 +
  32 +**Enjoy**
... ...
player/vendors/qdclient/bower.json 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +{
  2 + "name": "qdclient",
  3 + "version": "0.0.1",
  4 + "main": [
  5 + "qdclient.js"
  6 + ],
  7 + "ignore": [
  8 + "**/.*",
  9 + "Gulpfile.js",
  10 + "demo",
  11 + "node_modules",
  12 + "vendor",
  13 + "tests"
  14 + ],
  15 + "devDependencies": {
  16 + "mocha": "~2.2.5",
  17 + "chai": "~3.0.0"
  18 + }
  19 +}
... ...
player/vendors/qdclient/lib/chooser.js 0 → 100644
... ... @@ -0,0 +1,222 @@
  1 +(function(window, localStorage, undefined) {
  2 + 'use strict';
  3 +
  4 + function Chooser() {
  5 + this.server = 'http://150.165.204.39/vlibras-cloud/get_servers.php';
  6 +
  7 + this.options = {
  8 + THRESHOLDSLOW: 2000,
  9 + SLOWLIMITTRIES: 5,
  10 + NBESTHEURISTIC1: 2,
  11 + QUANTITYPREVIOUSTIMESSTORED: 10
  12 + };
  13 +
  14 + this.mirrors = [];
  15 +
  16 + this.heuristics = {
  17 + FIRSTHEURISTIC: {
  18 + FIRSTRANDOM : {value: 0, name: "Random"},
  19 + FIRSTRANDOMNBEST: {value: 1, name: "Random Among N Best"},
  20 + FIRSTBEST : {value: 2, name: "Best"}
  21 + },
  22 + SECONDHEURISTIC: {
  23 + SECONDRANDOM : {value: 0, name: "Random"},
  24 + SECONDCLOSEST: {value: 1, name: "Closest"}
  25 + },
  26 + THIRDHEURISTIC: {
  27 + THIRDSIMPLEAVERAGE : {value: 0, name: "Simple Average"},
  28 + THIRDWEIGHTEDAVERAGE: {value: 1, name: "Weighted Average"}
  29 + }
  30 + };
  31 + }
  32 +
  33 + // Exports
  34 + qdClient.Chooser = Chooser;
  35 +
  36 + Chooser.prototype.choose = function(urlLast, millisLast, response, callback) {
  37 + var $this = this;
  38 +
  39 + this.loadMirrors_(function() {
  40 + $this.chooseServer_(urlLast, millisLast, response, callback);
  41 + });
  42 + };
  43 +
  44 + Chooser.prototype.chooseServer_ = function(urlLast, millisLast, response, callback) {
  45 + var firstHeuristic = this.heuristics.FIRSTHEURISTIC.FIRSTBEST;
  46 + var secondHeuristic = this.heuristics.SECONDHEURISTIC.SECONDRANDOM;
  47 + var thirdHeuristic = this.heuristics.THIRDHEURISTIC.THIRDWEIGHTEDAVERAGE;
  48 +
  49 + var j = 0, i = 0; /* Fix JSHint */
  50 +
  51 + var sizeBest = this.options.NBESTHEURISTIC1;
  52 + if (firstHeuristic == this.heuristics.FIRSTHEURISTIC.FIRSTBEST) {
  53 + sizeBest = 1;
  54 + }
  55 +
  56 + if (urlLast && urlLast.length > 0) {
  57 + for (i = 0; i < this.mirrors.length; i++) {
  58 + if (this.mirrors[i].url.toLowerCase() == urlLast.toLowerCase()) {
  59 + if (this.mirrors[i].previousTimes.length < this.options.QUANTITYPREVIOUSTIMESSTORED) {
  60 + this.mirrors[i].previousTimes[this.mirrors[i].previousTimes.length] = millisLast;
  61 + } else {
  62 + for (j = this.options.QUANTITYPREVIOUSTIMESSTORED-1; j > 0; j--) {
  63 + this.mirrors[i].previousTimes[j-1] = this.mirrors[i].previousTimes[j];
  64 + }
  65 +
  66 + this.mirrors[i].previousTimes[this.options.QUANTITYPREVIOUSTIMESSTORED-1] = millisLast;
  67 + }
  68 +
  69 + if (thirdHeuristic == this.heuristics.THIRDHEURISTIC.THIRDSIMPLEAVERAGE) {
  70 + var totalMillis = 0;
  71 + for (j = 0; j < this.mirrors[i].previousTimes.length; j++) {
  72 + totalMillis += this.mirrors[i].previousTimes[j];
  73 + }
  74 +
  75 + this.mirrors[i].averageTime = totalMillis/this.mirrors[i].previousTimes.length;
  76 + } else if (thirdHeuristic == this.heuristics.THIRDHEURISTIC.THIRDWEIGHTEDAVERAGE) {
  77 + var totalMillisAndWeights = 0;
  78 + var totalWeights = 0;
  79 + for (j = 0; j < this.mirrors[i].previousTimes.length; j++) {
  80 + totalMillisAndWeights += this.mirrors[i].previousTimes[j]*(j+1);
  81 + totalWeights += (j+1);
  82 + }
  83 +
  84 + this.mirrors[i].averageTime = totalMillisAndWeights/totalWeights;
  85 + }
  86 +
  87 + if (millisLast > this.options.THRESHOLDSLOW || response == -1) {
  88 + this.mirrors[i].isSlow = true;
  89 + this.mirrors[i].remainingSlow = this.options.SLOWLIMITTRIES;
  90 + }
  91 +
  92 + localStorage.setItem("servers", JSON.stringify(this.mirrors));
  93 + break;
  94 + }
  95 +
  96 + }
  97 +
  98 + }
  99 +
  100 + var position = Math.floor((Math.random() * this.mirrors.length));
  101 + var closestPosition;
  102 +
  103 + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM) {
  104 + position = -1;
  105 + closestPosition = -1;
  106 + }
  107 +
  108 + var vectorBest = [];
  109 + var k = 0, z = 0; /* JSHint Fix */
  110 +
  111 + for (j = 0; j < this.mirrors.length; j++) {
  112 + if (this.mirrors[j].remainingSlow > 0) {
  113 + this.mirrors[j].remainingSlow = this.mirrors[j].remainingSlow - 1;
  114 + }
  115 +
  116 + if (this.mirrors[j].remainingSlow === 0) {
  117 + this.mirrors[j].isSlow = false;
  118 + }
  119 +
  120 + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM && this.mirrors[j].isSlow === false) {
  121 + if (closestPosition == -1) {
  122 + closestPosition = j;
  123 + }
  124 +
  125 + var added = false;
  126 +
  127 + for (k = 0; k < vectorBest.length; k++) {
  128 + if (this.mirrors[j].averageTime < vectorBest[k].averageTime || (this.mirrors[j].averageTime == vectorBest[k].averageTime && (Math.floor(Math.random()) < 0.5) )) {
  129 +
  130 + added = true;
  131 +
  132 + if (vectorBest.length < sizeBest) {
  133 + for (z = vectorBest.length-1; z >= k; z--) {
  134 + vectorBest[z+1] = vectorBest[z];
  135 + }
  136 + } else {
  137 + for (z = vectorBest.length-2; z >= k; z--) {
  138 + vectorBest[z+1] = vectorBest[z];
  139 + }
  140 + }
  141 +
  142 + vectorBest[k] = this.mirrors[j];
  143 +
  144 + break;
  145 + }
  146 + }
  147 +
  148 + if (added === false && vectorBest.length < sizeBest) {
  149 + vectorBest[vectorBest.length] = this.mirrors[j];
  150 + }
  151 +
  152 + }
  153 +
  154 + }
  155 +
  156 + // pega aleatorio entre as N posicoes dos melhores (se for guloso, tera apenas um elemento no vetor)
  157 + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM && vectorBest.length > 0) {
  158 + position = Math.floor((Math.random() * vectorBest.length));
  159 + }
  160 +
  161 + if (position == -1) {
  162 + if (secondHeuristic == this.heuristics.SECONDHEURISTIC.SECONDCLOSEST) {
  163 + // escolhendo o mais proximo, no caso, o vetor já está ordenado
  164 + if (closestPosition != -1) {
  165 + position = closestPosition;
  166 + } else {
  167 + // se nao marcou nenhum como closest, todos devem estar como slow, nesse caso seleciona o primeiro que é o mais próximo
  168 + position = 0;
  169 + }
  170 +
  171 + } else {
  172 + position = Math.floor((Math.random() * this.mirrors.length));
  173 + }
  174 + }
  175 +
  176 + callback(this.mirrors[position].url);
  177 + };
  178 +
  179 + Chooser.prototype.loadMirrors_ = function(callback) {
  180 + if (this.mirrors.length > 0) {
  181 + if (callback instanceof Function) callback();
  182 +
  183 + return;
  184 + }
  185 +
  186 + var $this = this;
  187 +
  188 + var localServers = JSON.parse(localStorage.getItem("servers")) || [];
  189 +
  190 + qdClient.getJSON(this.server, function (status, response) {
  191 + var servers = status === 200 ? response : [];
  192 +
  193 + for (var i = 0; i < servers.length; i++){
  194 + var mirror = {
  195 + name: servers[i].nome,
  196 + url: servers[i].url,
  197 + averageTime: 99999999,
  198 + isSlow: false,
  199 + previousTimes: [],
  200 + remainingSlow: 0,
  201 + type: servers[i].type
  202 + };
  203 +
  204 + for (var localServer in localServers) {
  205 + if (mirror.url == localServer.url) {
  206 + mirror.averageTime = localServer.averageTime;
  207 + mirror.isSlow = localServer.isSlow;
  208 + mirror.previousTimes = localServer.previousTimes;
  209 + mirror.remainingSlow = localServer.remainingSlow;
  210 +
  211 + break;
  212 + }
  213 + }
  214 +
  215 + $this.mirrors.push(mirror);
  216 + }
  217 +
  218 + if (callback instanceof Function) callback();
  219 + });
  220 + };
  221 +
  222 +}(window, localStorage));
... ...
player/vendors/qdclient/lib/qdclient.js 0 → 100644
... ... @@ -0,0 +1,34 @@
  1 +(function(window, undefined) {
  2 + 'use strict';
  3 +
  4 + window.qdClient = window.qdClient || {};
  5 +
  6 + qdClient.request = function request(url, method, params, callback) {
  7 + var xhr = new XMLHttpRequest();
  8 + var raw_params = "";
  9 +
  10 + xhr.open(method, url, true);
  11 +
  12 + xhr.onload = function() {
  13 + callback(xhr.status, xhr.responseText);
  14 + };
  15 +
  16 + if (method == "POST" && params instanceof Object) {
  17 +
  18 + for(var param in params) {
  19 + raw_params += param + '=' + params[param] + '&';
  20 + }
  21 +
  22 + if (params.length > 1) raw_params.slice(0, -1);
  23 + }
  24 +
  25 + xhr.send(raw_params);
  26 + };
  27 +
  28 + qdClient.getJSON = function getJSON(url, callback) {
  29 + qdClient.request(url, "GET", {}, function(status, response) {
  30 + callback(status, JSON.parse(response));
  31 + });
  32 + };
  33 +
  34 +}(window));
... ...
player/vendors/qdclient/package.json 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +{
  2 + "name": "qdclient",
  3 + "version": "0.0.1",
  4 + "description": "",
  5 + "scripts": {
  6 + "test": "echo \"Error: no test specified\" && exit 1"
  7 + },
  8 + "devDependencies": {
  9 + "browser-sync": "^2.7.13",
  10 + "gulp": "^3.9.0",
  11 + "gulp-concat": "^2.6.0",
  12 + "gulp-jshint": "^1.11.2",
  13 + "gulp-rename": "^1.2.2",
  14 + "gulp-rimraf": "^0.1.1",
  15 + "gulp-uglify": "^1.2.0",
  16 + "run-sequence": "^1.1.1"
  17 + }
  18 +}
... ...
player/vendors/qdclient/qdclient.js 0 → 100644
... ... @@ -0,0 +1,257 @@
  1 +(function(window, undefined) {
  2 + 'use strict';
  3 +
  4 + window.qdClient = window.qdClient || {};
  5 +
  6 + qdClient.request = function request(url, method, params, callback) {
  7 + var xhr = new XMLHttpRequest();
  8 + var raw_params = "";
  9 +
  10 + xhr.open(method, url, true);
  11 +
  12 + xhr.onload = function() {
  13 + callback(xhr.status, xhr.responseText);
  14 + };
  15 +
  16 + if (method == "POST" && params instanceof Object) {
  17 +
  18 + for(var param in params) {
  19 + raw_params += param + '=' + params[param] + '&';
  20 + }
  21 +
  22 + if (params.length > 1) raw_params.slice(0, -1);
  23 + }
  24 +
  25 + xhr.send(raw_params);
  26 + };
  27 +
  28 + qdClient.getJSON = function getJSON(url, callback) {
  29 + qdClient.request(url, "GET", {}, function(status, response) {
  30 + callback(status, JSON.parse(response));
  31 + });
  32 + };
  33 +
  34 +}(window));
  35 +
  36 +(function(window, localStorage, undefined) {
  37 + 'use strict';
  38 +
  39 + function Chooser() {
  40 + this.server = 'http://150.165.204.39/vlibras-cloud/get_servers.php';
  41 +
  42 + this.options = {
  43 + THRESHOLDSLOW: 2000,
  44 + SLOWLIMITTRIES: 5,
  45 + NBESTHEURISTIC1: 2,
  46 + QUANTITYPREVIOUSTIMESSTORED: 10
  47 + };
  48 +
  49 + this.mirrors = [];
  50 +
  51 + this.heuristics = {
  52 + FIRSTHEURISTIC: {
  53 + FIRSTRANDOM : {value: 0, name: "Random"},
  54 + FIRSTRANDOMNBEST: {value: 1, name: "Random Among N Best"},
  55 + FIRSTBEST : {value: 2, name: "Best"}
  56 + },
  57 + SECONDHEURISTIC: {
  58 + SECONDRANDOM : {value: 0, name: "Random"},
  59 + SECONDCLOSEST: {value: 1, name: "Closest"}
  60 + },
  61 + THIRDHEURISTIC: {
  62 + THIRDSIMPLEAVERAGE : {value: 0, name: "Simple Average"},
  63 + THIRDWEIGHTEDAVERAGE: {value: 1, name: "Weighted Average"}
  64 + }
  65 + };
  66 + }
  67 +
  68 + // Exports
  69 + qdClient.Chooser = Chooser;
  70 +
  71 + Chooser.prototype.choose = function(urlLast, millisLast, response, callback) {
  72 + var $this = this;
  73 +
  74 + this.loadMirrors_(function() {
  75 + $this.chooseServer_(urlLast, millisLast, response, callback);
  76 + });
  77 + };
  78 +
  79 + Chooser.prototype.chooseServer_ = function(urlLast, millisLast, response, callback) {
  80 + var firstHeuristic = this.heuristics.FIRSTHEURISTIC.FIRSTBEST;
  81 + var secondHeuristic = this.heuristics.SECONDHEURISTIC.SECONDRANDOM;
  82 + var thirdHeuristic = this.heuristics.THIRDHEURISTIC.THIRDWEIGHTEDAVERAGE;
  83 +
  84 + var j = 0, i = 0; /* Fix JSHint */
  85 +
  86 + var sizeBest = this.options.NBESTHEURISTIC1;
  87 + if (firstHeuristic == this.heuristics.FIRSTHEURISTIC.FIRSTBEST) {
  88 + sizeBest = 1;
  89 + }
  90 +
  91 + if (urlLast && urlLast.length > 0) {
  92 + for (i = 0; i < this.mirrors.length; i++) {
  93 + if (this.mirrors[i].url.toLowerCase() == urlLast.toLowerCase()) {
  94 + if (this.mirrors[i].previousTimes.length < this.options.QUANTITYPREVIOUSTIMESSTORED) {
  95 + this.mirrors[i].previousTimes[this.mirrors[i].previousTimes.length] = millisLast;
  96 + } else {
  97 + for (j = this.options.QUANTITYPREVIOUSTIMESSTORED-1; j > 0; j--) {
  98 + this.mirrors[i].previousTimes[j-1] = this.mirrors[i].previousTimes[j];
  99 + }
  100 +
  101 + this.mirrors[i].previousTimes[this.options.QUANTITYPREVIOUSTIMESSTORED-1] = millisLast;
  102 + }
  103 +
  104 + if (thirdHeuristic == this.heuristics.THIRDHEURISTIC.THIRDSIMPLEAVERAGE) {
  105 + var totalMillis = 0;
  106 + for (j = 0; j < this.mirrors[i].previousTimes.length; j++) {
  107 + totalMillis += this.mirrors[i].previousTimes[j];
  108 + }
  109 +
  110 + this.mirrors[i].averageTime = totalMillis/this.mirrors[i].previousTimes.length;
  111 + } else if (thirdHeuristic == this.heuristics.THIRDHEURISTIC.THIRDWEIGHTEDAVERAGE) {
  112 + var totalMillisAndWeights = 0;
  113 + var totalWeights = 0;
  114 + for (j = 0; j < this.mirrors[i].previousTimes.length; j++) {
  115 + totalMillisAndWeights += this.mirrors[i].previousTimes[j]*(j+1);
  116 + totalWeights += (j+1);
  117 + }
  118 +
  119 + this.mirrors[i].averageTime = totalMillisAndWeights/totalWeights;
  120 + }
  121 +
  122 + if (millisLast > this.options.THRESHOLDSLOW || response == -1) {
  123 + this.mirrors[i].isSlow = true;
  124 + this.mirrors[i].remainingSlow = this.options.SLOWLIMITTRIES;
  125 + }
  126 +
  127 + localStorage.setItem("servers", JSON.stringify(this.mirrors));
  128 + break;
  129 + }
  130 +
  131 + }
  132 +
  133 + }
  134 +
  135 + var position = Math.floor((Math.random() * this.mirrors.length));
  136 + var closestPosition;
  137 +
  138 + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM) {
  139 + position = -1;
  140 + closestPosition = -1;
  141 + }
  142 +
  143 + var vectorBest = [];
  144 + var k = 0, z = 0; /* JSHint Fix */
  145 +
  146 + for (j = 0; j < this.mirrors.length; j++) {
  147 + if (this.mirrors[j].remainingSlow > 0) {
  148 + this.mirrors[j].remainingSlow = this.mirrors[j].remainingSlow - 1;
  149 + }
  150 +
  151 + if (this.mirrors[j].remainingSlow === 0) {
  152 + this.mirrors[j].isSlow = false;
  153 + }
  154 +
  155 + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM && this.mirrors[j].isSlow === false) {
  156 + if (closestPosition == -1) {
  157 + closestPosition = j;
  158 + }
  159 +
  160 + var added = false;
  161 +
  162 + for (k = 0; k < vectorBest.length; k++) {
  163 + if (this.mirrors[j].averageTime < vectorBest[k].averageTime || (this.mirrors[j].averageTime == vectorBest[k].averageTime && (Math.floor(Math.random()) < 0.5) )) {
  164 +
  165 + added = true;
  166 +
  167 + if (vectorBest.length < sizeBest) {
  168 + for (z = vectorBest.length-1; z >= k; z--) {
  169 + vectorBest[z+1] = vectorBest[z];
  170 + }
  171 + } else {
  172 + for (z = vectorBest.length-2; z >= k; z--) {
  173 + vectorBest[z+1] = vectorBest[z];
  174 + }
  175 + }
  176 +
  177 + vectorBest[k] = this.mirrors[j];
  178 +
  179 + break;
  180 + }
  181 + }
  182 +
  183 + if (added === false && vectorBest.length < sizeBest) {
  184 + vectorBest[vectorBest.length] = this.mirrors[j];
  185 + }
  186 +
  187 + }
  188 +
  189 + }
  190 +
  191 + // pega aleatorio entre as N posicoes dos melhores (se for guloso, tera apenas um elemento no vetor)
  192 + if (firstHeuristic != this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM && vectorBest.length > 0) {
  193 + position = Math.floor((Math.random() * vectorBest.length));
  194 + }
  195 +
  196 + if (position == -1) {
  197 + if (secondHeuristic == this.heuristics.SECONDHEURISTIC.SECONDCLOSEST) {
  198 + // escolhendo o mais proximo, no caso, o vetor já está ordenado
  199 + if (closestPosition != -1) {
  200 + position = closestPosition;
  201 + } else {
  202 + // se nao marcou nenhum como closest, todos devem estar como slow, nesse caso seleciona o primeiro que é o mais próximo
  203 + position = 0;
  204 + }
  205 +
  206 + } else {
  207 + position = Math.floor((Math.random() * this.mirrors.length));
  208 + }
  209 + }
  210 +
  211 + callback(this.mirrors[position].url);
  212 + };
  213 +
  214 + Chooser.prototype.loadMirrors_ = function(callback) {
  215 + if (this.mirrors.length > 0) {
  216 + if (callback instanceof Function) callback();
  217 +
  218 + return;
  219 + }
  220 +
  221 + var $this = this;
  222 +
  223 + var localServers = JSON.parse(localStorage.getItem("servers")) || [];
  224 +
  225 + qdClient.getJSON(this.server, function (status, response) {
  226 + var servers = status === 200 ? response : [];
  227 +
  228 + for (var i = 0; i < servers.length; i++){
  229 + var mirror = {
  230 + name: servers[i].nome,
  231 + url: servers[i].url,
  232 + averageTime: 99999999,
  233 + isSlow: false,
  234 + previousTimes: [],
  235 + remainingSlow: 0,
  236 + type: servers[i].type
  237 + };
  238 +
  239 + for (var localServer in localServers) {
  240 + if (mirror.url == localServer.url) {
  241 + mirror.averageTime = localServer.averageTime;
  242 + mirror.isSlow = localServer.isSlow;
  243 + mirror.previousTimes = localServer.previousTimes;
  244 + mirror.remainingSlow = localServer.remainingSlow;
  245 +
  246 + break;
  247 + }
  248 + }
  249 +
  250 + $this.mirrors.push(mirror);
  251 + }
  252 +
  253 + if (callback instanceof Function) callback();
  254 + });
  255 + };
  256 +
  257 +}(window, localStorage));
... ...
player/vendors/qdclient/qdclient.min.js 0 → 100644
... ... @@ -0,0 +1 @@
  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;S<this.mirrors.length;S++)if(this.mirrors[S].url.toLowerCase()==i.toLowerCase()){if(this.mirrors[S].previousTimes.length<this.options.QUANTITYPREVIOUSTIMESSTORED)this.mirrors[S].previousTimes[this.mirrors[S].previousTimes.length]=s;else{for(T=this.options.QUANTITYPREVIOUSTIMESSTORED-1;T>0;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;T<this.mirrors[S].previousTimes.length;T++)m+=this.mirrors[S].previousTimes[T];this.mirrors[S].averageTime=m/this.mirrors[S].previousTimes.length}else if(h==this.heuristics.THIRDHEURISTIC.THIRDWEIGHTEDAVERAGE){var I=0,l=0;for(T=0;T<this.mirrors[S].previousTimes.length;T++)I+=this.mirrors[S].previousTimes[T]*(T+1),l+=T+1;this.mirrors[S].averageTime=I/l}(s>this.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;T<this.mirrors.length;T++)if(this.mirrors[T].remainingSlow>0&&(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<u.length;v++)if(this.mirrors[T].averageTime<u[v].averageTime||this.mirrors[T].averageTime==u[v].averageTime&&Math.floor(Math.random())<.5){if(f=!0,u.length<a)for(g=u.length-1;g>=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.length<a&&(u[u.length]=this.mirrors[T])}o!=this.heuristics.FIRSTHEURISTIC.FIRSTRANDOM&&u.length>0&&(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<o.length;n++){var h={name:o[n].nome,url:o[n].url,averageTime:99999999,isSlow:!1,previousTimes:[],remainingSlow:0,type:o[n].type};for(var T in e)if(h.url==T.url){h.averageTime=T.averageTime,h.isSlow=T.isSlow,h.previousTimes=T.previousTimes,h.remainingSlow=T.remainingSlow;break}s.mirrors.push(h)}i instanceof Function&&i()})}}(window,localStorage);
0 2 \ No newline at end of file
... ...
player/window.html 0 → 100644
... ... @@ -0,0 +1,57 @@
  1 +<!doctype html>
  2 +<html lang="en-us">
  3 + <head>
  4 + <meta charset="utf-8">
  5 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6 + <title>VLibras Plugin</title>
  7 + <link rel="stylesheet" href="TemplateData/style.css">
  8 + <link rel="shortcut icon" href="TemplateData/favicon.ico?v=2" />
  9 + <script src="TemplateData/UnityProgress.js"></script>
  10 +
  11 + <script src="vendors/qdclient/qdclient.js"></script>
  12 + <script src="../main.js"></script>
  13 +
  14 + <style type="text/css">
  15 + html, #canvas, .template, .template-wrap {
  16 + width: 100%;
  17 + height: 100%;
  18 + margin: 0;
  19 + overflow: hidden;
  20 + }
  21 +
  22 + #loading-screen span {
  23 + position: absolute;
  24 + top: 5px;
  25 + right: 40px;
  26 + padding: 15px 10px;
  27 + background: #000;
  28 + color: #FFF;
  29 +
  30 + font-size: 1.2em;
  31 + -webkit-border-radius: 20px;
  32 + -moz-border-radius: 20px;
  33 + border-radius: 20px;
  34 + }
  35 +
  36 + #loading-screen {
  37 + position: absolute;
  38 + top: 0;
  39 + left: 0;
  40 + display: none;
  41 + width: 100%;
  42 + height: 100%;
  43 + z-index: 9999;
  44 + }
  45 + </style>
  46 + </head>
  47 + <body class="template">
  48 + <div id="loading-screen"><span>Carregando...</span></div>
  49 + <div class="template-wrap clear">
  50 + <canvas class="emscripten" id="canvas"></canvas>
  51 + </div>
  52 + <script src="connect.js"></script>
  53 +<script src="Release/UnityConfig.js"></script>
  54 +<script src="Release/fileloader.js"></script>
  55 +<script src="load.js"></script>
  56 + </body>
  57 +</html>
... ...