Skip to content

Commit

Permalink
Added modified console polyfills to Workers
Browse files Browse the repository at this point in the history
  • Loading branch information
zhukov committed Jan 24, 2014
1 parent 70cdf39 commit 877b445
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
ga('send', 'pageview');
</script>

<script type="text/javascript" src="vendor/console-polyfill/console-polyfill.js"></script>
<script type="text/javascript" src="vendor/console-polyfill/console-polyfill.js?1"></script>
<script type="text/javascript" src="vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="vendor/jquery.nanoscroller/nanoscroller.js"></script>
<script type="text/javascript" src="vendor/jquery.emojiarea/jquery.emojiarea.js"></script>
Expand All @@ -48,7 +48,7 @@


<script type="text/javascript" src="js/lib/config.js"></script>
<script type="text/javascript" src="js/lib/mtproto.js?12"></script>
<script type="text/javascript" src="js/lib/mtproto.js?13"></script>

<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="js/app.js?5"></script>
Expand Down
7 changes: 6 additions & 1 deletion app/js/lib/aes_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* https://github.com/zhukov/webogram/blob/master/LICENSE
*/

importScripts('mtproto.js', '../../vendor/jsbn/jsbn_combined.js', '../../vendor/cryptoJS/crypto.js');
importScripts(
'../../vendor/console-polyfill/console-polyfill.js?1',
'mtproto.js',
'../../vendor/jsbn/jsbn_combined.js',
'../../vendor/cryptoJS/crypto.js'
);

onmessage = function (e) {
// console.log('AES worker in', e.data);
Expand Down
26 changes: 15 additions & 11 deletions app/js/lib/mtproto.js
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ factory('MtpAuthorizer', function (MtpDcConfigurator, MtpRsaKeysManager, MtpSecu

console.log('PQ factorization start');
if (!!window.Worker) {
var worker = new Worker('js/lib/pq_worker.js');
var worker = new Worker('js/lib/pq_worker.js?1');

worker.onmessage = function (e) {
auth.p = e.data[0];
Expand Down Expand Up @@ -1407,7 +1407,7 @@ factory('MtpAesService', function ($q) {
};
}

var worker = new Worker('js/lib/aes_worker.js'),
var worker = new Worker('js/lib/aes_worker.js?1'),
taskID = 0,
awaiting = {};

Expand Down Expand Up @@ -1459,7 +1459,7 @@ factory('MtpSha1Service', function ($q) {
};
}

var worker = new Worker('js/lib/sha1_worker.js'),
var worker = new Worker('js/lib/sha1_worker.js?1'),
taskID = 0,
awaiting = {};

Expand Down Expand Up @@ -1511,13 +1511,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
// })();
// }

this.sessionID = new Array(8);
MtpSecureRandom.nextBytes(this.sessionID);

if (false) {
this.sessionID[0] = 0xAB;
this.sessionID[1] = 0xCD;
}
this.updateSession();

this.seqNo = 0;
this.currentRequests = 0;
Expand All @@ -1537,6 +1531,15 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
this.checkLongPoll();
};

MtpNetworker.prototype.updateSession = function () {
this.sessionID = new Array(8);
MtpSecureRandom.nextBytes(this.sessionID);

if (false) {
this.sessionID[0] = 0xAB;
this.sessionID[1] = 0xCD;
}
}

MtpNetworker.prototype.generateSeqNo = function (notContentRelated) {
var seqNo = this.seqNo * 2;
Expand Down Expand Up @@ -2046,6 +2049,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato

if (message.error_code == 16 || message.error_code == 17) {
MtpMessageIdGenerator.applyServerTime((new BigInteger(messageID, 10)).shiftRight(32).toString(10));
this.updateSession();
this.pushResend(message.bad_msg_id);
this.ackMessage(messageID);
}
Expand Down Expand Up @@ -2229,7 +2233,7 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
},
function (error) {
console.log('error', error.code, error.type, baseDcID, dcID);
if (error.code == 401 && error.type == 'AUTH_KEY_UNREGISTERED' && baseDcID && dcID != baseDcID) {
if (error.code == 401 && baseDcID && dcID != baseDcID) {
if (cachedExportPromise[dcID] === undefined) {
var exportDeferred = $q.defer();

Expand Down
6 changes: 5 additions & 1 deletion app/js/lib/pq_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* https://github.com/zhukov/webogram/blob/master/LICENSE
*/

importScripts('mtproto.js', '../../vendor/jsbn/jsbn_combined.js');
importScripts(
'../../vendor/console-polyfill/console-polyfill.js?1',
'mtproto.js',
'../../vendor/jsbn/jsbn_combined.js'
);

onmessage = function (e) {
postMessage(pqPrimeFactorization(e.data));
Expand Down
6 changes: 5 additions & 1 deletion app/js/lib/sha1_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* https://github.com/zhukov/webogram/blob/master/LICENSE
*/

importScripts('mtproto.js', '../../vendor/cryptoJS/crypto.js');
importScripts(
'../../vendor/console-polyfill/console-polyfill.js?1',
'mtproto.js',
'../../vendor/cryptoJS/crypto.js'
);

onmessage = function (e) {
var taskID = e.data.taskID;
Expand Down
4 changes: 3 additions & 1 deletion app/vendor/console-polyfill/console-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
'time,timeEnd,trace,warn').split(',');
while (prop = properties.pop()) con[prop] = con[prop] || empty;
while (method = methods.pop()) con[method] = con[method] || dummy;
})(window.console = window.console || {});
})(this.console = this.console || {});

// For Workers compatibility `window` object is replaced with `this` keyword

0 comments on commit 877b445

Please sign in to comment.