|
1 | 1 | import { FilePayload, MessagingService, Config, Device, DeviceConnectedMessage, SdkCallbacks, ConnectedDevices } from "nativescript-preview-sdk"; |
2 | 2 | import { EventEmitter } from "events"; |
3 | 3 | import { PreviewSdkEventNames, PubnubKeys } from "./preview-app-constants"; |
| 4 | +const pako = require("pako"); |
4 | 5 |
|
5 | 6 | export class PreviewSdkService extends EventEmitter implements IPreviewSdkService { |
6 | 7 | private messagingService: MessagingService = null; |
7 | 8 | private instanceId: string = null; |
8 | 9 | public connectedDevices: Device[] = []; |
9 | 10 |
|
10 | 11 | constructor(private $errors: IErrors, |
11 | | - private $logger: ILogger) { |
| 12 | + private $logger: ILogger, |
| 13 | + private $httpClient: Server.IHttpClient) { |
12 | 14 | super(); |
13 | 15 | } |
14 | 16 |
|
@@ -70,7 +72,24 @@ export class PreviewSdkService extends EventEmitter implements IPreviewSdkServic |
70 | 72 | } |
71 | 73 | }, |
72 | 74 | onDevicesPresence: (devices: Device[]) => ({ }), |
73 | | - onSendingChange: (sending: boolean) => ({ }) |
| 75 | + onSendingChange: (sending: boolean) => ({ }), |
| 76 | + onBiggerFilesUpload: async (filesContent, callback) => { |
| 77 | + // TODO: stop using the playground endpoint when we have a direct Amazon one |
| 78 | + const gzippedContent = new Buffer(pako.gzip(filesContent)); |
| 79 | + const playgroundUploadResponse = await this.$httpClient.httpRequest({ |
| 80 | + url: "https://play.telerik.rocks/api/files", |
| 81 | + method: "POST", |
| 82 | + body: gzippedContent, |
| 83 | + headers: { |
| 84 | + "Content-Encoding": "gzip", |
| 85 | + "Content-Type": "text/plain" |
| 86 | + } |
| 87 | + }); |
| 88 | + |
| 89 | + const responseBody = JSON.parse(playgroundUploadResponse.body); |
| 90 | + const location = responseBody && responseBody.location; |
| 91 | + callback(location, playgroundUploadResponse.error); |
| 92 | + } |
74 | 93 | }; |
75 | 94 | } |
76 | 95 | } |
|
0 commit comments