diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-11-23 05:43:00 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-11-23 05:43:00 +0900 |
| commit | 3f8ebac466ece8e9598432f3f574ec44e420c03b (patch) | |
| tree | 05114fce9728d6ce1deecc1f2eb8a903a22b0100 /src/web/app/common/mios.ts | |
| parent | :v: (diff) | |
| download | misskey-3f8ebac466ece8e9598432f3f574ec44e420c03b.tar.gz misskey-3f8ebac466ece8e9598432f3f574ec44e420c03b.tar.bz2 misskey-3f8ebac466ece8e9598432f3f574ec44e420c03b.zip | |
なんかもうめっちゃ変えた
Closes #940
Diffstat (limited to 'src/web/app/common/mios.ts')
| -rw-r--r-- | src/web/app/common/mios.ts | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/web/app/common/mios.ts b/src/web/app/common/mios.ts index 96dac70f61..7f9aacc46c 100644 --- a/src/web/app/common/mios.ts +++ b/src/web/app/common/mios.ts @@ -3,11 +3,12 @@ import * as riot from 'riot'; import signout from './scripts/signout'; import Progress from './scripts/loading'; import HomeStreamManager from './scripts/streaming/home-stream-manager'; -import CONFIG from './scripts/config'; import api from './scripts/api'; -declare var VERSION: string; -declare var LANG: string; +declare const _VERSION_: string; +declare const _LANG_: string; +declare const _API_URL_: string; +declare const _SW_PUBLICKEY_: string; /** * Misskey Operating System @@ -113,7 +114,7 @@ export default class MiOS extends EventEmitter { } // Fetch user - fetch(`${CONFIG.apiUrl}/i`, { + fetch(`${_API_URL_}/i`, { method: 'POST', body: JSON.stringify({ i: token @@ -229,10 +230,15 @@ export default class MiOS extends EventEmitter { this.swRegistration = registration; // Options of pushManager.subscribe + // SEE: https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe#Parameters const opts = { // A boolean indicating that the returned push subscription // will only be used for messages whose effect is made visible to the user. - userVisibleOnly: true + userVisibleOnly: true, + + // A public key your push server will use to send + // messages to client apps via a push server. + applicationServerKey: urlBase64ToUint8Array(_SW_PUBLICKEY_) }; // Subscribe push notification @@ -257,7 +263,7 @@ export default class MiOS extends EventEmitter { }); // The path of service worker script - const sw = `/sw.${VERSION}.${LANG}.js`; + const sw = `/sw.${_VERSION_}.${_LANG_}.js`; // Register service worker navigator.serviceWorker.register(sw).then(registration => { @@ -310,3 +316,22 @@ export default class MiOS extends EventEmitter { }); } } + +/** + * Convert the URL safe base64 string to a Uint8Array + * @param base64String base64 string + */ +function urlBase64ToUint8Array(base64String: string): Uint8Array { + const padding = '='.repeat((4 - base64String.length % 4) % 4); + const base64 = (base64String + padding) + .replace(/\-/g, '+') + .replace(/_/g, '/'); + + const rawData = window.atob(base64); + const outputArray = new Uint8Array(rawData.length); + + for (let i = 0; i < rawData.length; ++i) { + outputArray[i] = rawData.charCodeAt(i); + } + return outputArray; +} |