Skip to content

Commit 8dfed8c

Browse files
author
James Lees
authored
Merge pull request #88 from pusher/fetch-website-push-id
Fetch website push ID
2 parents 7068dd8 + bea8c12 commit 8dfed8c

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) {
@@ -66,7 +66,7 @@ export class SafariClient extends BaseClient {
6666
window.safari.pushNotification.requestPermission(
6767
this._serviceUrl,
6868
this._websitePushId,
69-
{ userID: 'abcdef' },
69+
{},
7070
resolve
7171
);
7272
});
@@ -153,11 +153,14 @@ export class SafariClient extends BaseClient {
153153
}
154154

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

0 commit comments

Comments
 (0)