aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/api/pushmanager/subscribe
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
commit074785cea106179cb3305637055ab0a009ca74f2 (patch)
treee6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/ru/web/api/pushmanager/subscribe
parentda78a9e329e272dedb2400b79a3bdeebff387d47 (diff)
downloadtranslated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz
translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2
translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip
initial commit
Diffstat (limited to 'files/ru/web/api/pushmanager/subscribe')
-rw-r--r--files/ru/web/api/pushmanager/subscribe/index.html144
1 files changed, 144 insertions, 0 deletions
diff --git a/files/ru/web/api/pushmanager/subscribe/index.html b/files/ru/web/api/pushmanager/subscribe/index.html
new file mode 100644
index 0000000000..a264d593d7
--- /dev/null
+++ b/files/ru/web/api/pushmanager/subscribe/index.html
@@ -0,0 +1,144 @@
+---
+title: PushManager.subscribe()
+slug: Web/API/PushManager/subscribe
+translation_of: Web/API/PushManager/subscribe
+---
+<p>{{SeeCompatTable}}{{ApiRef("Push API")}}</p>
+
+<p><code style=""><font face="Arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;">Метод </span></font><strong>subscribe()</strong></code> интерфейса {{domxref("PushManager")}} позволяет осуществлять подписку на push-уведомления.</p>
+
+<p>Возвращает {{jsxref("Promise")}}, который разрешается в объект {{domxref("PushSubscription")}}, содержащий детали push-подписки. Новая push-подписка создается в случае, если сервис-воркер не имеет существующей подписки.</p>
+
+<h2 id="Синтакс">Синтакс</h2>
+
+<pre class="syntaxbox">​PushManager.subscribe(options).then(function(pushSubscription) { ... } );</pre>
+
+<h3 id="Свойства">Свойства</h3>
+
+<dl>
+ <dt><code>options {{optional_inline}}</code></dt>
+ <dd>Объект, содержащий необязательные параметры конфигурации. Может иметь следующие свойства:
+ <ul>
+ <li><code>userVisibleOnly</code>: Булевое значение, указывающее на то, будет ли возвращаемая подписка использоваться для сообщений, чей эффект может быть видим для пользователя.</li>
+ <li><code>applicationServerKey</code>: открытый ключ ECDSA P-256, закодированный в Base64 {{domxref ('DOMString')}} или {{domxref ('ArrayBuffer')}}}, содержащий , который push-сервер будет использовать для аутентификации сервера приложений. Если указано, все сообщения с сервера Вашего приложения должны использовать схему аутентификации VAPID и включать JWT, подписанный соответствующим закрытым ключом. Этот ключ <strong><em>НЕ </em></strong>тот же ключ ECDH, который вы используете для шифрования данных. Для получения дополнительной информации см. «<a href="https://blog.mozilla.org/services/2016/04/04/using-vapid-with-webpush/">Using VAPID with WebPush</a>».</li>
+ </ul>
+
+ <div class="blockIndicator note">
+ <p><em><strong>Примечание: </strong>Свойство, требуемое некоторыми браузерами, например Chrome и Edge.</em></p>
+ </div>
+ </dd>
+</dl>
+
+<h3 id="Возвращает">Возвращает</h3>
+
+<p>{{jsxref("Promise")}} который разрешается в объект {{domxref("PushSubscription")}}.</p>
+
+<h2 id="Пример">Пример</h2>
+
+<pre class="brush: js">this.onpush = function(event) {
+ console.log(event.data);
+ <code>// Отсюда можно записывать данные в IndexedDB, отправлять их в любое
+ // открытое окно, отображать уведомление и т. д.</code>
+}
+
+navigator.serviceWorker.register('serviceworker.js').then(
+ function(serviceWorkerRegistration) {
+ serviceWorkerRegistration.pushManager.subscribe().then(
+ function(pushSubscription) {
+ console.log(pushSubscription.subscriptionId);
+ console.log(pushSubscription.endpoint);
+ <code>// Детали push-подписки, требуемые сервером приложения,
+ // теперь доступны, и могут быть отправлены, к примеру,
+ // при помощи XMLHttpRequest.</code>
+ }, function(error) {
+ <code>// При разработке это часто помогает отлавливать ошибки в консоли.
+ // В продакшен-среде это также может быть полезно для отправки отчета
+ // об ошибках на сервер приложения.</code>
+ console.log(error);
+ }
+ );
+ });</pre>
+
+<h2 id="Спецификации">Спецификации</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Push API', '#widl-PushManager-subscribe-Promise-PushSubscription--PushSubscriptionOptions-options', 'subscribe()')}}</td>
+ <td>{{Spec2('Push API')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Совместимость_с_браузерами">Совместимость с браузерами</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th style="line-height: 16px;">Feature</th>
+ <th style="line-height: 16px;">Chrome</th>
+ <th style="line-height: 16px;">Firefox (Gecko)</th>
+ <th style="line-height: 16px;">Internet Explorer</th>
+ <th style="line-height: 16px;">Opera</th>
+ <th style="line-height: 16px;">Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome(42.0)}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th style="line-height: 16px;">Feature</th>
+ <th style="line-height: 16px;">Android</th>
+ <th style="line-height: 16px;">Android Webview</th>
+ <th style="line-height: 16px;">Firefox Mobile (Gecko)</th>
+ <th style="line-height: 16px;">Firefox OS</th>
+ <th style="line-height: 16px;">IE Mobile</th>
+ <th style="line-height: 16px;">Opera Mobile</th>
+ <th style="line-height: 16px;">Safari Mobile</th>
+ <th style="line-height: 16px;">Chrome for Android</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatChrome(42.0)}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="Смотрите_также">Смотрите также</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/API/Push_API/Using_the_Push_API">Using the Push API</a></li>
+ <li><a href="http://updates.html5rocks.com/2015/03/push-notificatons-on-the-open-web">Push Notifications on the Open Web</a>, Matt Gaunt</li>
+</ul>
+
+<p> </p>
+
+<p> </p>