temp
This commit is contained in:
parent
2874032b3a
commit
86bb1e112c
@ -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<{
|
||||
notifyAll(task);
|
||||
}
|
||||
}
|
||||
/// #endif
|
||||
|
||||
export const socketsProxied: Map<number, SocketProxied> = new Map();
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
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 {
|
||||
});
|
||||
/// #endif
|
||||
|
||||
navigator.serviceWorker.addEventListener('messageerror', (e) => {
|
||||
worker.addEventListener('messageerror', (e) => {
|
||||
this.log.error('SW messageerror:', e);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user