1
+ import doRequest from './do-request' ;
1
2
import BaseClient from './base-client' ;
2
3
import { version as sdkVersion } from '../package.json' ;
3
4
import { RegistrationState } from './base-client' ;
4
5
5
6
const __url = 'https://localhost:8080' ;
6
- const __pushId = 'web.io.lees.safari-push' ;
7
-
8
7
const platform = 'safari' ;
9
8
10
9
export class SafariClient extends BaseClient {
@@ -20,7 +19,8 @@ export class SafariClient extends BaseClient {
20
19
}
21
20
22
21
async _init ( ) {
23
- this . _websitePushId = await this . _fetchWebsitePushId ( ) ;
22
+ let { websitePushId } = await this . _fetchWebsitePushId ( ) ;
23
+ this . _websitePushId = websitePushId ;
24
24
this . _serviceUrl = __url ;
25
25
26
26
if ( this . _deviceId !== null ) {
@@ -64,7 +64,7 @@ export class SafariClient extends BaseClient {
64
64
window . safari . pushNotification . requestPermission (
65
65
this . _serviceUrl ,
66
66
this . _websitePushId ,
67
- { userID : 'abcdef' } ,
67
+ { } ,
68
68
resolve
69
69
) ;
70
70
} ) ;
@@ -151,11 +151,14 @@ export class SafariClient extends BaseClient {
151
151
}
152
152
153
153
_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 ) ;
158
160
}
161
+
159
162
_isSupportedBrowser ( ) {
160
163
return 'safari' in window && 'pushNotification' in window . safari ;
161
164
}
0 commit comments