Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*! @license Firebase v3.9.0
- Build: rev-cc77c9e
- Terms: https://firebase.google.com/terms/ */
- (function() {
- var f = function(a, b) {
- function c() {}
- c.prototype = b.prototype;
- a.u = b.prototype;
- a.prototype = new c;
- for (var d in b)
- if (Object.defineProperties) {
- var e = Object.getOwnPropertyDescriptor(b, d);
- e && Object.defineProperty(a, d, e)
- } else a[d] = b[d]
- },
- g = this,
- h = function(a) {
- var b = typeof a;
- if ("object" == b)
- if (a) {
- if (a instanceof Array) return "array";
- if (a instanceof Object) return b;
- var c = Object.prototype.toString.call(a);
- if ("[object Window]" == c) return "object";
- if ("[object Array]" == c || "number" == typeof a.length && "undefined" != typeof a.splice &&
- "undefined" != typeof a.propertyIsEnumerable && !a.propertyIsEnumerable("splice")) return "array";
- if ("[object Function]" == c || "undefined" != typeof a.call && "undefined" != typeof a.propertyIsEnumerable && !a.propertyIsEnumerable("call")) return "function"
- } else return "null";
- else if ("function" == b && "undefined" == typeof a.call) return "object";
- return b
- },
- k = function(a, b) {
- function c() {}
- c.prototype = b.prototype;
- a.u = b.prototype;
- a.prototype = new c;
- a.v = function(a, c, n) {
- for (var d = Array(arguments.length - 2), e = 2; e < arguments.length; e++) d[e -
- 2] = arguments[e];
- return b.prototype[c].apply(a, d)
- }
- };
- var m = function(a) {
- if (Error.captureStackTrace) Error.captureStackTrace(this, m);
- else {
- var b = Error().stack;
- b && (this.stack = b)
- }
- a && (this.message = String(a))
- };
- k(m, Error);
- var p = function(a, b) {
- for (var c = a.split("%s"), d = "", e = Array.prototype.slice.call(arguments, 1); e.length && 1 < c.length;) d += c.shift() + e.shift();
- return d + c.join("%s")
- };
- var q = function(a, b) {
- b.unshift(a);
- m.call(this, p.apply(null, b));
- b.shift()
- };
- k(q, m);
- var r = function(a, b, c) {
- if (!a) {
- var d = "Assertion failed";
- if (b) var d = d + (": " + b),
- e = Array.prototype.slice.call(arguments, 2);
- throw new q("" + d, e || []);
- }
- };
- var t = null;
- var v = function(a) {
- a = new Uint8Array(a);
- var b = h(a);
- r("array" == b || "object" == b && "number" == typeof a.length, "encodeByteArray takes an array as a parameter");
- if (!t)
- for (t = {}, b = 0; 65 > b; b++) t[b] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(b);
- for (var b = t, c = [], d = 0; d < a.length; d += 3) {
- var e = a[d],
- n = d + 1 < a.length,
- l = n ? a[d + 1] : 0,
- z = d + 2 < a.length,
- u = z ? a[d + 2] : 0,
- M = e >> 2,
- e = (e & 3) << 4 | l >> 4,
- l = (l & 15) << 2 | u >> 6,
- u = u & 63;
- z || (u = 64, n || (l = 64));
- c.push(b[M], b[e], b[l], b[u])
- }
- return c.join("").replace(/\+/g, "-").replace(/\//g,
- "_").replace(/=+$/, "")
- };
- var w = {},
- x = (w["only-available-in-window"] = "This method is available in a Window context.", w["only-available-in-sw"] = "This method is available in a service worker context.", w["should-be-overriden"] = "This method should be overriden by extended classes.", w["bad-sender-id"] = "Please ensure that 'messagingSenderId' is set correctly in the options passed into firebase.initializeApp().", w["permission-default"] = "The required permissions were not granted and dismissed instead.", w["permission-blocked"] = "The required permissions were not granted and blocked instead.",
- w["unsupported-browser"] = "This browser doesn't support the API's required to use the firebase SDK.", w["notifications-blocked"] = "Notifications have been blocked.", w["failed-serviceworker-registration"] = "We are unable to register the default service worker. {$browserErrorMessage}", w["sw-registration-expected"] = "A service worker registration was the expected input.", w["get-subscription-failed"] = "There was an error when trying to get any existing Push Subscriptions.", w["invalid-saved-token"] = "Unable to access details of the saved token.",
- w["sw-reg-redundant"] = "The service worker being used for push was made redundant.", w["token-subscribe-failed"] = "A problem occured while subscribing the user to FCM: {$message}", w["token-subscribe-no-token"] = "FCM returned no token when subscribing the user to push.", w["token-subscribe-no-push-set"] = "FCM returned an invalid response when getting an FCM token.", w["use-sw-before-get-token"] = "You must call useServiceWorker() before calling getToken() to ensure your service worker is used.", w["invalid-delete-token"] =
- "You must pass a valid token into deleteToken(), i.e. the token from getToken().", w["delete-token-not-found"] = "The deletion attempt for token could not be performed as the token was not found.", w["delete-scope-not-found"] = "The deletion attempt for service worker scope could not be performed as the scope was not found.", w["bg-handler-function-expected"] = "The input to setBackgroundMessageHandler() must be a function.", w["no-window-client-to-msg"] = "An attempt was made to message a non-existant window client.",
- w["unable-to-resubscribe"] = "There was an error while re-subscribing the FCM token for push messaging. Will have to resubscribe the user on next visit. {$message}", w["no-fcm-token-for-resubscribe"] = "Could not find an FCM token and as a result, unable to resubscribe. Will have to resubscribe the user on next visit.", w["failed-to-delete-token"] = "Unable to delete the currently saved token.", w["no-sw-in-reg"] = "Even though the service worker registration was successful, there was a problem accessing the service worker itself.",
- w["incorrect-gcm-sender-id"] = "Please change your web app manifest's 'gcm_sender_id' value to '103953800507' to use Firebase messaging.", w["bad-scope"] = "The service worker scope must be a string with at least one character.", w["bad-vapid-key"] = "The public VAPID key must be a string with at least one character.", w["bad-subscription"] = "The subscription must be a valid PushSubscription.", w["bad-token"] = "The FCM Token used for storage / lookup was not a valid token string.", w["bad-push-set"] = "The FCM push set used for storage / lookup was not not a valid push set string.",
- w["failed-delete-vapid-key"] = "The VAPID key could not be deleted.", w);
- var y = {
- userVisibleOnly: !0,
- applicationServerKey: new Uint8Array([4, 51, 148, 247, 223, 161, 235, 177, 220, 3, 162, 94, 21, 113, 219, 72, 211, 46, 237, 237, 178, 52, 219, 183, 71, 58, 12, 143, 196, 204, 225, 111, 60, 140, 132, 223, 171, 182, 102, 62, 242, 12, 212, 139, 254, 227, 249, 118, 47, 20, 28, 99, 8, 106, 111, 45, 177, 26, 149, 176, 206, 55, 192, 156, 110])
- };
- var A = new firebase.INTERNAL.ErrorFactory("messaging", "Messaging", x),
- B = function() {
- this.a = null
- },
- C = function(a) {
- if (a.a) return a.a;
- a.a = new Promise(function(a, c) {
- var b = g.indexedDB.open("fcm_token_details_db", 1);
- b.onerror = function(a) {
- c(a.target.error)
- };
- b.onsuccess = function(b) {
- a(b.target.result)
- };
- b.onupgradeneeded = function(a) {
- a = a.target.result.createObjectStore("fcm_token_object_Store", {
- keyPath: "swScope"
- });
- a.createIndex("fcmSenderId", "fcmSenderId", {
- unique: !1
- });
- a.createIndex("fcmToken", "fcmToken", {
- unique: !0
- })
- }
- });
- return a.a
- },
- D = function(a) {
- a.a ? a.a.then(function(b) {
- b.close();
- a.a = null
- }) : Promise.resolve()
- },
- E = function(a, b) {
- return C(a).then(function(a) {
- return new Promise(function(c, e) {
- var d = a.transaction(["fcm_token_object_Store"]).objectStore("fcm_token_object_Store").index("fcmToken").get(b);
- d.onerror = function(a) {
- e(a.target.error)
- };
- d.onsuccess = function(a) {
- c(a.target.result)
- }
- })
- })
- },
- F = function(a, b) {
- return C(a).then(function(a) {
- return new Promise(function(c, e) {
- var d = [],
- l = a.transaction(["fcm_token_object_Store"]).objectStore("fcm_token_object_Store").openCursor();
- l.onerror = function(a) {
- e(a.target.error)
- };
- l.onsuccess = function(a) {
- (a = a.target.result) ? (a.value.fcmSenderId === b && d.push(a.value), a.continue()) : c(d)
- }
- })
- })
- },
- G = function(a, b, c) {
- var d = v(b.getKey("p256dh")),
- e = v(b.getKey("auth"));
- a = "authorized_entity=" + a + "&" + ("endpoint=" + b.endpoint + "&") + ("encryption_key=" + d + "&") + ("encryption_auth=" + e);
- c && (a += "&pushSet=" + c);
- c = new Headers;
- c.append("Content-Type", "application/x-www-form-urlencoded");
- return fetch("https://fcm.googleapis.com/fcm/connect/subscribe", {
- method: "POST",
- headers: c,
- body: a
- }).then(function(a) {
- return a.json()
- }).then(function(a) {
- if (a.error) throw A.create("token-subscribe-failed", {
- message: a.error.message
- });
- if (!a.token) throw A.create("token-subscribe-no-token");
- if (!a.pushSet) throw A.create("token-subscribe-no-push-set");
- return {
- token: a.token,
- pushSet: a.pushSet
- }
- })
- },
- H = function(a, b, c, d, e, n) {
- var l = {
- swScope: c.scope,
- endpoint: d.endpoint,
- auth: v(d.getKey("auth")),
- p256dh: v(d.getKey("p256dh")),
- fcmToken: e,
- fcmPushSet: n,
- fcmSenderId: b
- };
- return C(a).then(function(a) {
- return new Promise(function(b,
- c) {
- var d = a.transaction(["fcm_token_object_Store"], "readwrite").objectStore("fcm_token_object_Store").put(l);
- d.onerror = function(a) {
- c(a.target.error)
- };
- d.onsuccess = function() {
- b()
- }
- })
- })
- };
- B.prototype.i = function(a, b) {
- return b instanceof ServiceWorkerRegistration ? "string" !== typeof a || 0 === a.length ? Promise.reject(A.create("bad-sender-id")) : F(this, a).then(function(c) {
- if (0 !== c.length) {
- var d = c.findIndex(function(c) {
- return b.scope === c.swScope && a === c.fcmSenderId
- });
- if (-1 !== d) return c[d]
- }
- }).then(function(a) {
- if (a) return b.pushManager.getSubscription().catch(function() {
- throw A.create("get-subscription-failed");
- }).then(function(b) {
- var c;
- if (c = b) c = b.endpoint === a.endpoint && v(b.getKey("auth")) === a.auth &&
- v(b.getKey("p256dh")) === a.p256dh;
- if (c) return a.fcmToken
- })
- }) : Promise.reject(A.create("sw-registration-expected"))
- };
- B.prototype.getSavedToken = B.prototype.i;
- B.prototype.h = function(a, b) {
- var c = this;
- return "string" !== typeof a || 0 === a.length ? Promise.reject(A.create("bad-sender-id")) : b instanceof ServiceWorkerRegistration ? b.pushManager.getSubscription().then(function(a) {
- return a ? a : b.pushManager.subscribe(y)
- }).then(function(d) {
- return G(a, d).then(function(e) {
- return H(c, a, b, d, e.token, e.pushSet).then(function() {
- return e.token
- })
- })
- }) : Promise.reject(A.create("sw-registration-expected"))
- };
- B.prototype.createToken = B.prototype.h;
- B.prototype.deleteToken = function(a) {
- var b = this;
- return "string" !== typeof a || 0 === a.length ? Promise.reject(A.create("invalid-delete-token")) : E(this, a).then(function(a) {
- if (!a) throw A.create("delete-token-not-found");
- return C(b).then(function(b) {
- return new Promise(function(c, d) {
- var e = b.transaction(["fcm_token_object_Store"], "readwrite").objectStore("fcm_token_object_Store").delete(a.swScope);
- e.onerror = function(a) {
- d(a.target.error)
- };
- e.onsuccess = function(b) {
- 0 === b.target.result ? d(A.create("failed-to-delete-token")) :
- c(a)
- }
- })
- })
- })
- };
- var I = function(a) {
- var b = this;
- this.a = new firebase.INTERNAL.ErrorFactory("messaging", "Messaging", x);
- if (!a.options.messagingSenderId || "string" !== typeof a.options.messagingSenderId) throw this.a.create("bad-sender-id");
- this.l = a.options.messagingSenderId;
- this.c = new B;
- this.app = a;
- this.INTERNAL = {};
- this.INTERNAL.delete = function() {
- return b.delete
- }
- };
- I.prototype.getToken = function() {
- var a = this,
- b = Notification.permission;
- return "granted" !== b ? "denied" === b ? Promise.reject(this.a.create("notifications-blocked")) : Promise.resolve(null) : this.f().then(function(b) {
- return a.c.i(a.l, b).then(function(c) {
- return c ? c : a.c.h(a.l, b)
- })
- })
- };
- I.prototype.getToken = I.prototype.getToken;
- I.prototype.deleteToken = function(a) {
- var b = this;
- return this.c.deleteToken(a).then(function() {
- return b.f()
- }).then(function(a) {
- return a ? a.pushManager.getSubscription() : null
- }).then(function(a) {
- if (a) return a.unsubscribe()
- })
- };
- I.prototype.deleteToken = I.prototype.deleteToken;
- I.prototype.f = function() {
- throw this.a.create("should-be-overriden");
- };
- I.prototype.requestPermission = function() {
- throw this.a.create("only-available-in-window");
- };
- I.prototype.useServiceWorker = function() {
- throw this.a.create("only-available-in-window");
- };
- I.prototype.useServiceWorker = I.prototype.useServiceWorker;
- I.prototype.onMessage = function() {
- throw this.a.create("only-available-in-window");
- };
- I.prototype.onMessage = I.prototype.onMessage;
- I.prototype.onTokenRefresh = function() {
- throw this.a.create("only-available-in-window");
- };
- I.prototype.onTokenRefresh = I.prototype.onTokenRefresh;
- I.prototype.setBackgroundMessageHandler = function() {
- throw this.a.create("only-available-in-sw");
- };
- I.prototype.setBackgroundMessageHandler = I.prototype.setBackgroundMessageHandler;
- I.prototype.delete = function() {
- D(this.c)
- };
- var J = function(a, b) {
- var c = {};
- return c["firebase-messaging-msg-type"] = a, c["firebase-messaging-msg-data"] = b, c
- };
- var K = self,
- P = function(a) {
- I.call(this, a);
- var b = this;
- this.a = new firebase.INTERNAL.ErrorFactory("messaging", "Messaging", x);
- K.addEventListener("push", function(a) {
- return L(b, a)
- }, !1);
- K.addEventListener("pushsubscriptionchange", function(a) {
- return N(b, a)
- }, !1);
- K.addEventListener("notificationclick", function(a) {
- return O(b, a)
- }, !1);
- this.b = null
- };
- f(P, I);
- var L = function(a, b) {
- var c;
- try {
- c = b.data.json()
- } catch (e) {
- return
- }
- var d = Q().then(function(b) {
- if (b) {
- if (c.notification || a.b) return R(a, c)
- } else {
- if ((b = c) && "object" === typeof b.notification) {
- var d = Object.assign({}, b.notification),
- e = {};
- d.data = (e.FCM_MSG = b, e);
- b = d
- } else b = void 0;
- if (b) return K.registration.showNotification(b.title || "", b);
- if (a.b) return a.b(c)
- }
- });
- b.waitUntil(d)
- },
- N = function(a, b) {
- var c = a.getToken().then(function(b) {
- if (!b) throw a.a.create("no-fcm-token-for-resubscribe");
- var c = a.c;
- return E(c, b).then(function(b) {
- if (!b) throw a.a.create("invalid-saved-token");
- return K.registration.pushManager.subscribe(y).then(function(a) {
- return G(b.A, a, b.w)
- }).catch(function(d) {
- return c.deleteToken(b.B).then(function() {
- throw a.a.create("unable-to-resubscribe", {
- message: d
- });
- })
- })
- })
- });
- b.waitUntil(c)
- },
- O = function(a, b) {
- if (b.notification && b.notification.data && b.notification.data.FCM_MSG) {
- b.stopImmediatePropagation();
- b.notification.close();
- var c = b.notification.data.FCM_MSG,
- d = c.notification.click_action;
- if (d) {
- var e = S(d).then(function(a) {
- return a ? a : K.clients.openWindow(d)
- }).then(function(b) {
- if (b) return delete c.notification,
- T(a, b, J("notification-clicked", c))
- });
- b.waitUntil(e)
- }
- }
- };
- P.prototype.setBackgroundMessageHandler = function(a) {
- if (a && "function" !== typeof a) throw this.a.create("bg-handler-function-expected");
- this.b = a
- };
- P.prototype.setBackgroundMessageHandler = P.prototype.setBackgroundMessageHandler;
- var S = function(a) {
- var b = (new URL(a)).href;
- return K.clients.matchAll({
- type: "window",
- includeUncontrolled: !0
- }).then(function(a) {
- for (var c = null, e = 0; e < a.length; e++)
- if ((new URL(a[e].url)).href === b) {
- c = a[e];
- break
- }
- if (c) return c.focus(), c
- })
- },
- T = function(a, b, c) {
- return new Promise(function(d, e) {
- if (!b) return e(a.a.create("no-window-client-to-msg"));
- b.postMessage(c);
- d()
- })
- },
- Q = function() {
- return K.clients.matchAll({
- type: "window",
- includeUncontrolled: !0
- }).then(function(a) {
- return a.some(function(a) {
- return "visible" ===
- a.visibilityState
- })
- })
- },
- R = function(a, b) {
- return K.clients.matchAll({
- type: "window",
- includeUncontrolled: !0
- }).then(function(c) {
- var d = J("push-msg-received", b);
- return Promise.all(c.map(function(b) {
- return T(a, b, d)
- }))
- })
- };
- P.prototype.f = function() {
- return Promise.resolve(K.registration)
- };
- var V = function(a) {
- I.call(this, a);
- var b = this;
- this.j = null;
- this.m = firebase.INTERNAL.createSubscribe(function(a) {
- b.j = a
- });
- this.s = null;
- this.o = firebase.INTERNAL.createSubscribe(function(a) {
- b.s = a
- });
- U(this)
- };
- f(V, I);
- V.prototype.getToken = function() {
- var a = this;
- return "serviceWorker" in navigator && "PushManager" in window && "Notification" in window && ServiceWorkerRegistration.prototype.hasOwnProperty("showNotification") && PushSubscription.prototype.hasOwnProperty("getKey") ? W(this).then(function() {
- return I.prototype.getToken.call(a)
- }) : Promise.reject(this.a.create("unsupported-browser"))
- };
- V.prototype.getToken = V.prototype.getToken;
- var W = function(a) {
- if (a.g) return a.g;
- var b = document.querySelector('link[rel="manifest"]');
- b ? a.g = fetch(b.href).then(function(a) {
- return a.json()
- }).catch(function() {
- return Promise.resolve()
- }).then(function(b) {
- if (b && b.gcm_sender_id && "103953800507" !== b.gcm_sender_id) throw a.a.create("incorrect-gcm-sender-id");
- }) : a.g = Promise.resolve();
- return a.g
- };
- V.prototype.requestPermission = function() {
- var a = this;
- return "granted" === Notification.permission ? Promise.resolve() : new Promise(function(b, c) {
- var d = function(d) {
- return "granted" === d ? b() : "denied" === d ? c(a.a.create("permission-blocked")) : c(a.a.create("permission-default"))
- },
- e = Notification.requestPermission(function(a) {
- e || d(a)
- });
- e && e.then(d)
- })
- };
- V.prototype.requestPermission = V.prototype.requestPermission;
- V.prototype.useServiceWorker = function(a) {
- if (!(a instanceof ServiceWorkerRegistration)) throw this.a.create("sw-registration-expected");
- if ("undefined" !== typeof this.b) throw this.a.create("use-sw-before-get-token");
- this.b = a
- };
- V.prototype.useServiceWorker = V.prototype.useServiceWorker;
- V.prototype.onMessage = function(a, b, c) {
- return this.m(a, b, c)
- };
- V.prototype.onMessage = V.prototype.onMessage;
- V.prototype.onTokenRefresh = function(a, b, c) {
- return this.o(a, b, c)
- };
- V.prototype.onTokenRefresh = V.prototype.onTokenRefresh;
- var X = function(a, b) {
- var c = b.installing || b.waiting || b.active;
- return new Promise(function(d, e) {
- if (c)
- if ("activated" === c.state) d(b);
- else if ("redundant" === c.state) e(a.a.create("sw-reg-redundant"));
- else {
- var n = function() {
- if ("activated" === c.state) d(b);
- else if ("redundant" === c.state) e(a.a.create("sw-reg-redundant"));
- else return;
- c.removeEventListener("statechange", n)
- };
- c.addEventListener("statechange", n)
- } else e(a.a.create("no-sw-in-reg"))
- })
- };
- V.prototype.f = function() {
- var a = this;
- if (this.b) return X(this, this.b);
- this.b = null;
- return navigator.serviceWorker.register("/firebase-messaging-sw.js", {
- scope: "/firebase-cloud-messaging-push-scope"
- }).catch(function(b) {
- throw a.a.create("failed-serviceworker-registration", {
- browserErrorMessage: b.message
- });
- }).then(function(b) {
- return X(a, b).then(function() {
- a.b = b;
- b.update();
- return b
- })
- })
- };
- var U = function(a) {
- "serviceWorker" in navigator && navigator.serviceWorker.addEventListener("message", function(b) {
- if (b.data && b.data["firebase-messaging-msg-type"]) switch (b = b.data, b["firebase-messaging-msg-type"]) {
- case "push-msg-received":
- case "notification-clicked":
- a.j.next(b["firebase-messaging-msg-data"])
- }
- }, !1)
- };
- if (!(firebase && firebase.INTERNAL && firebase.INTERNAL.registerService)) throw Error("Cannot install Firebase Messaging - be sure to load firebase-app.js first.");
- firebase.INTERNAL.registerService("messaging", function(a) {
- return self && "ServiceWorkerGlobalScope" in self ? new P(a) : new V(a)
- }, {
- Messaging: V
- });
- new firebase.INTERNAL.ErrorFactory("messaging", "Messaging", x);
- new firebase.INTERNAL.ErrorFactory("messaging", "Messaging", x);
- new firebase.INTERNAL.ErrorFactory("messaging", "Messaging", x);
- }).call(this);
Advertisement
Add Comment
Please, Sign In to add comment