| 88 | } |
| 89 | |
| 90 | export class Task implements ITask { |
| 91 | _native: FIRStorageUploadTask | FIRStorageDownloadTask; |
| 92 | |
| 93 | static fromNative(value: FIRStorageUploadTask | FIRStorageDownloadTask) { |
| 94 | if (value instanceof FIRStorageUploadTask || value instanceof FIRStorageDownloadTask) { |
| 95 | const task = new Task(); |
| 96 | task._native = value; |
| 97 | return task; |
| 98 | } |
| 99 | return null; |
| 100 | } |
| 101 | |
| 102 | get native() { |
| 103 | return this._native; |
| 104 | } |
| 105 | |
| 106 | get ios() { |
| 107 | return this.native; |
| 108 | } |
| 109 | |
| 110 | get snapshot(): TaskSnapshot { |
| 111 | return TaskSnapshot.fromNative(this.native.snapshot); |
| 112 | } |
| 113 | |
| 114 | cancel(): boolean { |
| 115 | this.native?.cancel(); |
| 116 | return this.native.snapshot.progress.cancelled; |
| 117 | } |
| 118 | |
| 119 | on(event: TaskEvent, nextOrObserver?: TaskSnapshotObserver | ((a: TaskSnapshot) => any), error?: (a: FirebaseError) => any, complete?: () => void) { |
| 120 | if (event !== TaskEvent.STATE_CHANGED) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | if (nextOrObserver) { |
| 125 | if (typeof nextOrObserver === 'function') { |
| 126 | this.native.observeStatusHandler(FIRStorageTaskStatus.Progress, (snapshot) => { |
| 127 | nextOrObserver(TaskSnapshot.fromNative(snapshot)); |
| 128 | }); |
| 129 | |
| 130 | this.native.observeStatusHandler(FIRStorageTaskStatus.Pause, (snapshot) => { |
| 131 | nextOrObserver(TaskSnapshot.fromNative(snapshot)); |
| 132 | }); |
| 133 | |
| 134 | this.native.observeStatusHandler(FIRStorageTaskStatus.Resume, (snapshot) => { |
| 135 | nextOrObserver(TaskSnapshot.fromNative(snapshot)); |
| 136 | }); |
| 137 | } else if (typeof nextOrObserver === 'object') { |
| 138 | this.native.observeStatusHandler(FIRStorageTaskStatus.Progress, (snapshot) => { |
| 139 | nextOrObserver?.next(TaskSnapshot.fromNative(snapshot)); |
| 140 | }); |
| 141 | |
| 142 | this.native.observeStatusHandler(FIRStorageTaskStatus.Pause, (snapshot) => { |
| 143 | nextOrObserver?.next(TaskSnapshot.fromNative(snapshot)); |
| 144 | }); |
| 145 | |
| 146 | this.native.observeStatusHandler(FIRStorageTaskStatus.Resume, (snapshot) => { |
| 147 | nextOrObserver?.next(TaskSnapshot.fromNative(snapshot)); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…