1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | export function calculaDtoParaSuscripcion(suscripcion) { |
9 | const key = suscripcion.getKey("p256dh") |
10 | const token = suscripcion.getKey("auth") |
11 | const supported = PushManager.supportedContentEncodings |
12 | const encodings = Array.isArray(supported) && supported.length > 0 |
13 | ? supported |
14 | : ["aesgcm"] |
15 | const endpoint = suscripcion.endpoint |
16 | const publicKey = key === null |
17 | ? null |
18 | : btoa(String.fromCharCode.apply(null, new Uint8Array(key))) |
19 | const authToken = token === null |
20 | ? null |
21 | : btoa(String.fromCharCode.apply(null, new Uint8Array(token))) |
22 | const contentEncoding = encodings[0] |
23 | return { |
24 | endpoint, |
25 | publicKey, |
26 | authToken, |
27 | contentEncoding |
28 | } |
29 | } |
30 | |