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 ) {
@@ -66,7 +66,7 @@ export class SafariClient extends BaseClient {
66
66
window . safari . pushNotification . requestPermission (
67
67
this . _serviceUrl ,
68
68
this . _websitePushId ,
69
- { userID : 'abcdef' } ,
69
+ { } ,
70
70
resolve
71
71
) ;
72
72
} ) ;
@@ -153,11 +153,14 @@ export class SafariClient extends BaseClient {
153
153
}
154
154
155
155
_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 ) ;
160
162
}
163
+
161
164
_isSupportedBrowser ( ) {
162
165
return 'safari' in window && 'pushNotification' in window . safari ;
163
166
}
0 commit comments