forked from Vydia/react-native-background-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
130 lines (116 loc) · 4.57 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
declare module "react-native-background-upload" {
import type { EventSubscription } from 'react-native';
export interface EventData {
id: string;
}
export interface ProgressData extends EventData {
progress: number
}
export interface ErrorData extends EventData {
error: string
}
export interface CompletedData extends EventData {
responseCode: number
responseBody: string
responseHeaders?: Record<string, string> | null
}
export type FileInfo = {
name: string
exists: boolean
size?: number
extension?: string
mimeType?: string
}
export type NotificationOptions = {
/**
* Enable or diasable notifications. Works only on Android version < 8.0 Oreo. On Android versions >= 8.0 Oreo is required by Google's policy to display a notification when a background service run { enabled: true }
*/
enabled: boolean
/**
* Autoclear notification on complete { autoclear: true }
*/
autoClear: boolean
/**
* Sets android notificaion channel { notificationChannel: "My-Upload-Service" }
*/
notificationChannel: string
/**
* Sets whether or not to enable the notification sound when the upload gets completed with success or error { enableRingTone: true }
*/
enableRingTone: boolean
/**
* Sets notification progress title { onProgressTitle: "Uploading" }
*/
onProgressTitle: string
/**
* Sets notification progress message { onProgressMessage: "Uploading new video" }
*/
onProgressMessage: string
/**
* Sets notification complete title { onCompleteTitle: "Upload finished" }
*/
onCompleteTitle: string
/**
* Sets notification complete message { onCompleteMessage: "Your video has been uploaded" }
*/
onCompleteMessage: string
/**
* Sets notification error title { onErrorTitle: "Upload error" }
*/
onErrorTitle: string
/**
* Sets notification error message { onErrorMessage: "An error occured while uploading a video" }
*/
onErrorMessage: string
/**
* Sets notification cancelled title { onCancelledTitle: "Upload cancelled" }
*/
onCancelledTitle: string
/**
* Sets notification cancelled message { onCancelledMessage: "Video upload was cancelled" }
*/
onCancelledMessage: string
}
export interface UploadOptions {
url: string;
path: string;
type?: 'raw' | 'multipart';
method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
customUploadId?: string;
headers?: {
[index: string]: string
};
// Android notification settings
notification?: Partial<NotificationOptions>
/**
* AppGroup defined in XCode for extensions. Necessary when trying to upload things via this library
* in the context of ShareExtension.
*/
appGroup?: string;
// Necessary only for multipart type upload
field?: string
}
export interface MultipartUploadOptions extends UploadOptions {
type: 'multipart'
field: string
parameters?: {
[index: string]: string
}
}
type uploadId = string
export type UploadListenerEvent = 'progress' | 'error' | 'completed' | 'cancelled'
export default class Upload {
static startUpload(options: UploadOptions | MultipartUploadOptions): Promise<uploadId>
static addListener(event: 'progress', uploadId: uploadId | null, callback: (data: ProgressData ) => void): EventSubscription
static addListener(event: 'error', uploadId: uploadId | null, callback: (data: ErrorData) => void): EventSubscription
static addListener(event: 'completed', uploadId: uploadId | null, callback: (data: CompletedData) => void): EventSubscription
static addListener(event: 'cancelled', uploadId: uploadId | null, callback: (data: EventData) => void): EventSubscription
static getFileInfo(path: string): Promise<FileInfo>
static cancelUpload(uploadId: uploadId): Promise<boolean>
static getFileInfo: (path: string) => Promise<Object>;
static canSuspendIfBackground: () => void;
static getRemainingBgTime: () => Promise<number>;
static beginBackgroundTask: () => Promise<number>;
static endBackgroundTask: (id: number) => void;
}
}