Browse Source

temp

master
morethanwords 4 years ago
parent
commit
86bb1e112c
  1. 4
      src/lib/mtproto/dcConfigurator.ts
  2. 15
      src/lib/mtproto/mtproto.service.ts
  3. 23
      src/lib/mtproto/mtprotoworker.ts

4
src/lib/mtproto/dcConfigurator.ts

@ -26,6 +26,7 @@ type Servers = { @@ -26,6 +26,7 @@ type Servers = {
let socketId = 0;
const TEST_SUFFIX = Modes.test ? '_test' : '';
/// #if !MTPROTO_SW
class SocketProxied extends EventListenerBase<{
open: () => void,
message: (buffer: ArrayBuffer) => any,
@ -77,6 +78,7 @@ class SocketProxied extends EventListenerBase<{ @@ -77,6 +78,7 @@ class SocketProxied extends EventListenerBase<{
notifyAll(task);
}
}
/// #endif
export const socketsProxied: Map<number, SocketProxied> = new Map();
@ -108,7 +110,7 @@ export class DcConfigurator { @@ -108,7 +110,7 @@ export class DcConfigurator {
const retryTimeout = connectionType === 'client' ? 10000 : 10000;
const oooohLetMeLive: MTConnectionConstructable = (isSafari && isWebWorker) /* || true */ ? SocketProxied : Socket;
const oooohLetMeLive: MTConnectionConstructable = (isSafari && isWebWorker && typeof(SocketProxied) !== 'undefined') /* || true */ ? SocketProxied : Socket;
return new TcpObfuscated(oooohLetMeLive, dcId, chosenServer, logSuffix, retryTimeout);
};

15
src/lib/mtproto/mtproto.service.ts

@ -222,6 +222,21 @@ function alignLimit(limit: number) { @@ -222,6 +222,21 @@ function alignLimit(limit: number) {
return 2 ** Math.ceil(Math.log(limit) / Math.log(2));
}
/* ctx.addEventListener('push', (event) => {
console.log('[Service Worker] Push Received.');
console.log(`[Service Worker] Push had this data: "${event.data.text()}"`, event, event.data);
const title = 'Push Push Push';
const options = {};
// const options = {
// body: 'Yay it works.',
// icon: 'images/icon.png',
// badge: 'images/badge.png'
// };
event.waitUntil(ctx.registration.showNotification(title, options));
}); */
//export default () => {};
//MOUNT_CLASS_TO && (MOUNT_CLASS_TO.onFetch = onFetch);

23
src/lib/mtproto/mtprotoworker.ts

@ -77,7 +77,8 @@ export class ApiManagerProxy extends CryptoWorkerMethods { @@ -77,7 +77,8 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
private registerServiceWorker() {
if(!('serviceWorker' in navigator)) return;
navigator.serviceWorker.register('./sw.js', {scope: './'}).then(registration => {
const worker = navigator.serviceWorker;
worker.register('./sw.js', {scope: './'}).then(registration => {
this.log('SW registered', registration);
this.isSWRegistered = true;
@ -86,33 +87,29 @@ export class ApiManagerProxy extends CryptoWorkerMethods { @@ -86,33 +87,29 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
this.log('SW statechange', e);
});
const controller = navigator.serviceWorker.controller || registration.installing || registration.waiting || registration.active;
/// #if MTPROTO_SW
const controller = worker.controller || registration.installing || registration.waiting || registration.active;
this.onWorkerFirstMessage(controller);
/// #endif
}, (err) => {
this.isSWRegistered = false;
this.log.error('SW registration failed!', err);
appDocsManager.onServiceWorkerFail();
});
/* navigator.serviceWorker.ready.then((registration) => {
this.log('set SW', navigator.serviceWorker);
//registration.update();
}); */
navigator.serviceWorker.addEventListener('controllerchange', () => {
worker.addEventListener('controllerchange', () => {
this.log.warn('controllerchange');
this.releasePending();
navigator.serviceWorker.controller.addEventListener('error', (e) => {
worker.controller.addEventListener('error', (e) => {
this.log.error('controller error:', e);
});
});
/// #if MTPROTO_SW
navigator.serviceWorker.addEventListener('message', this.onWorkerMessage);
worker.addEventListener('message', this.onWorkerMessage);
/// #else
navigator.serviceWorker.addEventListener('message', (e) => {
worker.addEventListener('message', (e) => {
const task: ServiceWorkerTask = e.data;
if(!isObject(task)) {
return;
@ -122,7 +119,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods { @@ -122,7 +119,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
});
/// #endif
navigator.serviceWorker.addEventListener('messageerror', (e) => {
worker.addEventListener('messageerror', (e) => {
this.log.error('SW messageerror:', e);
});
}

Loading…
Cancel
Save