No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.esm.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import firebase from '@firebase/app-compat';
  2. import { Component } from '@firebase/component';
  3. import { __awaiter, __generator } from 'tslib';
  4. import { getToken, deleteToken, onMessage } from '@firebase/messaging';
  5. import { isIndexedDBAvailable, areCookiesEnabled } from '@firebase/util';
  6. import { onBackgroundMessage } from '@firebase/messaging/sw';
  7. var name = "@firebase/messaging-compat";
  8. var version = "0.2.1";
  9. /**
  10. * @license
  11. * Copyright 2020 Google LLC
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License");
  14. * you may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. function isSupported() {
  26. if (self && 'ServiceWorkerGlobalScope' in self) {
  27. // Running in ServiceWorker context
  28. return isSwSupported();
  29. }
  30. else {
  31. // Assume we are in the window context.
  32. return isWindowSupported();
  33. }
  34. }
  35. /**
  36. * Checks to see if the required APIs exist.
  37. * Unlike the modular version, it does not check if IndexedDB.open() is allowed
  38. * in order to keep isSupported() synchronous and maintain v8 compatibility.
  39. */
  40. function isWindowSupported() {
  41. return (typeof window !== 'undefined' &&
  42. isIndexedDBAvailable() &&
  43. areCookiesEnabled() &&
  44. 'serviceWorker' in navigator &&
  45. 'PushManager' in window &&
  46. 'Notification' in window &&
  47. 'fetch' in window &&
  48. ServiceWorkerRegistration.prototype.hasOwnProperty('showNotification') &&
  49. PushSubscription.prototype.hasOwnProperty('getKey'));
  50. }
  51. /**
  52. * Checks to see if the required APIs exist within SW Context.
  53. */
  54. function isSwSupported() {
  55. return (isIndexedDBAvailable() &&
  56. 'PushManager' in self &&
  57. 'Notification' in self &&
  58. ServiceWorkerRegistration.prototype.hasOwnProperty('showNotification') &&
  59. PushSubscription.prototype.hasOwnProperty('getKey'));
  60. }
  61. var MessagingCompatImpl = /** @class */ (function () {
  62. function MessagingCompatImpl(app, _delegate) {
  63. this.app = app;
  64. this._delegate = _delegate;
  65. this.app = app;
  66. this._delegate = _delegate;
  67. }
  68. MessagingCompatImpl.prototype.getToken = function (options) {
  69. return __awaiter(this, void 0, void 0, function () {
  70. return __generator(this, function (_a) {
  71. return [2 /*return*/, getToken(this._delegate, options)];
  72. });
  73. });
  74. };
  75. MessagingCompatImpl.prototype.deleteToken = function () {
  76. return __awaiter(this, void 0, void 0, function () {
  77. return __generator(this, function (_a) {
  78. return [2 /*return*/, deleteToken(this._delegate)];
  79. });
  80. });
  81. };
  82. MessagingCompatImpl.prototype.onMessage = function (nextOrObserver) {
  83. return onMessage(this._delegate, nextOrObserver);
  84. };
  85. MessagingCompatImpl.prototype.onBackgroundMessage = function (nextOrObserver) {
  86. return onBackgroundMessage(this._delegate, nextOrObserver);
  87. };
  88. return MessagingCompatImpl;
  89. }());
  90. /**
  91. * @license
  92. * Copyright 2020 Google LLC
  93. *
  94. * Licensed under the Apache License, Version 2.0 (the "License");
  95. * you may not use this file except in compliance with the License.
  96. * You may obtain a copy of the License at
  97. *
  98. * http://www.apache.org/licenses/LICENSE-2.0
  99. *
  100. * Unless required by applicable law or agreed to in writing, software
  101. * distributed under the License is distributed on an "AS IS" BASIS,
  102. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  103. * See the License for the specific language governing permissions and
  104. * limitations under the License.
  105. */
  106. var messagingCompatFactory = function (container) {
  107. if (self && 'ServiceWorkerGlobalScope' in self) {
  108. // in sw
  109. return new MessagingCompatImpl(container.getProvider('app-compat').getImmediate(), container.getProvider('messaging-sw').getImmediate());
  110. }
  111. else {
  112. // in window
  113. return new MessagingCompatImpl(container.getProvider('app-compat').getImmediate(), container.getProvider('messaging').getImmediate());
  114. }
  115. };
  116. var NAMESPACE_EXPORTS = {
  117. isSupported: isSupported
  118. };
  119. function registerMessagingCompat() {
  120. firebase.INTERNAL.registerComponent(new Component('messaging-compat', messagingCompatFactory, "PUBLIC" /* ComponentType.PUBLIC */).setServiceProps(NAMESPACE_EXPORTS));
  121. }
  122. /**
  123. * @license
  124. * Copyright 2020 Google LLC
  125. *
  126. * Licensed under the Apache License, Version 2.0 (the "License");
  127. * you may not use this file except in compliance with the License.
  128. * You may obtain a copy of the License at
  129. *
  130. * http://www.apache.org/licenses/LICENSE-2.0
  131. *
  132. * Unless required by applicable law or agreed to in writing, software
  133. * distributed under the License is distributed on an "AS IS" BASIS,
  134. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  135. * See the License for the specific language governing permissions and
  136. * limitations under the License.
  137. */
  138. registerMessagingCompat();
  139. firebase.registerVersion(name, version);
  140. //# sourceMappingURL=index.esm.js.map