暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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