Skip to content

Commit bea8c12

Browse files
author
James Lees
committed
Fetch website push ID from beams
1 parent 8a864e6 commit bea8c12

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/safari-client.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import doRequest from './do-request';
12
import BaseClient from './base-client';
23
import { version as sdkVersion } from '../package.json';
34
import { RegistrationState } from './base-client';
45

56
const __url = 'https://localhost:8080';
6-
const __pushId = 'web.io.lees.safari-push';
7-
87
const platform = 'safari';
98

109
export class SafariClient extends BaseClient {
@@ -20,7 +19,8 @@ export class SafariClient extends BaseClient {
2019
}
2120

2221
async _init() {
23-
this._websitePushId = await this._fetchWebsitePushId();
22+
let { websitePushId } = await this._fetchWebsitePushId();
23+
this._websitePushId = websitePushId;
2424
this._serviceUrl = __url;
2525

2626
if (this._deviceId !== null) {
@@ -64,7 +64,7 @@ export class SafariClient extends BaseClient {
6464
window.safari.pushNotification.requestPermission(
6565
this._serviceUrl,
6666
this._websitePushId,
67-
{ userID: 'abcdef' },
67+
{},
6868
resolve
6969
);
7070
});
@@ -151,11 +151,14 @@ export class SafariClient extends BaseClient {
151151
}
152152

153153
_fetchWebsitePushId() {
154-
return new Promise(resolve => {
155-
// TODO temporary
156-
resolve(__pushId);
157-
});
154+
const path = `${this._baseURL}/device_api/v1/instances/${encodeURIComponent(
155+
this.instanceId
156+
)}/safari-website-push-id`;
157+
158+
const options = { method: 'GET', path };
159+
return doRequest(options);
158160
}
161+
159162
_isSupportedBrowser() {
160163
return 'safari' in window && 'pushNotification' in window.safari;
161164
}

0 commit comments

Comments
 (0)