@atlaskit/media-client 23.2.0 → 24.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/client/file-fetcher/index.js +110 -34
- package/dist/cjs/client/media-client.js +18 -6
- package/dist/cjs/client/media-store/index.js +1 -2
- package/dist/cjs/client/mobile-upload.js +38 -2
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/utils/with-media-client-hoc.js +8 -16
- package/dist/es2019/client/file-fetcher/index.js +101 -28
- package/dist/es2019/client/media-client.js +15 -7
- package/dist/es2019/client/media-store/index.js +1 -2
- package/dist/es2019/client/mobile-upload.js +33 -2
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/utils/with-media-client-hoc.js +8 -16
- package/dist/esm/client/file-fetcher/index.js +106 -30
- package/dist/esm/client/media-client.js +19 -7
- package/dist/esm/client/media-store/index.js +1 -2
- package/dist/esm/client/mobile-upload.js +38 -2
- package/dist/esm/index.js +1 -0
- package/dist/esm/utils/with-media-client-hoc.js +8 -16
- package/dist/types/client/events.d.ts +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +10 -6
- package/dist/types/client/media-client.d.ts +10 -5
- package/dist/types/client/media-store/index.d.ts +3 -4
- package/dist/types/client/mobile-upload.d.ts +6 -2
- package/dist/types/file-streams-cache.d.ts +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/models/artifacts.d.ts +1 -14
- package/dist/types/models/file-state.d.ts +4 -73
- package/dist/types/models/media.d.ts +1 -1
- package/dist/types/models/mobile-upload.d.ts +1 -1
- package/dist/types/utils/createMediaSubject.d.ts +1 -1
- package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +1 -1
- package/dist/types/utils/mediaSubscribable/toPromise.d.ts +1 -1
- package/dist/types/utils/mediaSubscribable/types.d.ts +1 -1
- package/dist/types/utils/mobileUpload/helpers.d.ts +1 -1
- package/dist/types/utils/mobileUpload/stateMachine/index.d.ts +1 -1
- package/dist/types/utils/mobileUpload/stateMachine/types.d.ts +1 -1
- package/dist/types/utils/overrideMediaTypeIfUnknown.d.ts +1 -1
- package/dist/types/utils/shouldFetchRemoteFileStates.d.ts +1 -1
- package/dist/types/utils/with-media-client-hoc.d.ts +2 -3
- package/dist/types-ts4.5/client/events.d.ts +1 -1
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +10 -6
- package/dist/types-ts4.5/client/media-client.d.ts +10 -5
- package/dist/types-ts4.5/client/media-store/index.d.ts +3 -4
- package/dist/types-ts4.5/client/mobile-upload.d.ts +6 -2
- package/dist/types-ts4.5/file-streams-cache.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +4 -2
- package/dist/types-ts4.5/models/artifacts.d.ts +1 -14
- package/dist/types-ts4.5/models/file-state.d.ts +4 -73
- package/dist/types-ts4.5/models/media.d.ts +1 -1
- package/dist/types-ts4.5/models/mobile-upload.d.ts +1 -1
- package/dist/types-ts4.5/utils/createMediaSubject.d.ts +1 -1
- package/dist/types-ts4.5/utils/mediaSubscribable/fromObservable.d.ts +1 -1
- package/dist/types-ts4.5/utils/mediaSubscribable/toPromise.d.ts +1 -1
- package/dist/types-ts4.5/utils/mediaSubscribable/types.d.ts +1 -1
- package/dist/types-ts4.5/utils/mobileUpload/helpers.d.ts +1 -1
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/index.d.ts +1 -1
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/types.d.ts +1 -1
- package/dist/types-ts4.5/utils/overrideMediaTypeIfUnknown.d.ts +1 -1
- package/dist/types-ts4.5/utils/shouldFetchRemoteFileStates.d.ts +1 -1
- package/dist/types-ts4.5/utils/with-media-client-hoc.d.ts +2 -3
- package/package.json +5 -3
- package/report.api.md +51 -168
- package/tmp/api-report-tmp.d.ts +51 -160
|
@@ -7,7 +7,7 @@ import uuid from 'uuid/v4';
|
|
|
7
7
|
import 'setimmediate';
|
|
8
8
|
import { authToOwner } from '@atlaskit/media-core';
|
|
9
9
|
import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
|
|
10
|
-
import { MediaStore } from '../media-store';
|
|
10
|
+
import { MediaStore as MediaApi } from '../media-store';
|
|
11
11
|
import { isErrorFileState, isFinalFileState, isProcessingFileState, mapMediaFileToFileState, mapMediaItemToFileState } from '../../models/file-state';
|
|
12
12
|
import { FileFetcherError } from './error';
|
|
13
13
|
import { uploadFile } from '../../uploader';
|
|
@@ -26,9 +26,29 @@ import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaski
|
|
|
26
26
|
import { shouldFetchRemoteFileStates } from '../../utils/shouldFetchRemoteFileStates';
|
|
27
27
|
import { PollingFunction } from '../../utils/polling';
|
|
28
28
|
import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
29
|
+
import { mediaStore } from '@atlaskit/media-state';
|
|
29
30
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
30
31
|
export class FileFetcherImpl {
|
|
31
|
-
constructor(mediaStore) {
|
|
32
|
+
constructor(mediaApi, store = mediaStore) {
|
|
33
|
+
_defineProperty(this, "getErrorFileState", (error, id, occurrenceKey) => typeof error === 'string' ? {
|
|
34
|
+
status: 'error',
|
|
35
|
+
id,
|
|
36
|
+
reason: error,
|
|
37
|
+
occurrenceKey,
|
|
38
|
+
message: error
|
|
39
|
+
} : {
|
|
40
|
+
status: 'error',
|
|
41
|
+
id,
|
|
42
|
+
reason: error === null || error === void 0 ? void 0 : error.reason,
|
|
43
|
+
details: error === null || error === void 0 ? void 0 : error.attributes,
|
|
44
|
+
occurrenceKey,
|
|
45
|
+
message: error === null || error === void 0 ? void 0 : error.message
|
|
46
|
+
});
|
|
47
|
+
_defineProperty(this, "setFileState", (id, fileState) => {
|
|
48
|
+
this.store.setState(state => {
|
|
49
|
+
state.files[id] = fileState;
|
|
50
|
+
});
|
|
51
|
+
});
|
|
32
52
|
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
33
53
|
_defineProperty(this, "createDownloadFileStream", (id, collectionName, occurrenceKey) => {
|
|
34
54
|
const subject = createMediaSubject();
|
|
@@ -105,8 +125,9 @@ export class FileFetcherImpl {
|
|
|
105
125
|
preview
|
|
106
126
|
};
|
|
107
127
|
});
|
|
108
|
-
this.
|
|
109
|
-
this.
|
|
128
|
+
this.mediaApi = mediaApi;
|
|
129
|
+
this.store = store;
|
|
130
|
+
this.dataloader = createFileDataloader(mediaApi);
|
|
110
131
|
}
|
|
111
132
|
getFileState(id, options = {}) {
|
|
112
133
|
const {
|
|
@@ -115,25 +136,47 @@ export class FileFetcherImpl {
|
|
|
115
136
|
} = options;
|
|
116
137
|
if (!isValidId(id)) {
|
|
117
138
|
const subject = createMediaSubject();
|
|
118
|
-
|
|
139
|
+
const err = new FileFetcherError('invalidFileId', id, {
|
|
119
140
|
collectionName,
|
|
120
141
|
occurrenceKey
|
|
121
|
-
})
|
|
142
|
+
});
|
|
143
|
+
const errorFileState = {
|
|
144
|
+
status: 'error',
|
|
145
|
+
id,
|
|
146
|
+
reason: err === null || err === void 0 ? void 0 : err.reason,
|
|
147
|
+
message: err === null || err === void 0 ? void 0 : err.message,
|
|
148
|
+
occurrenceKey,
|
|
149
|
+
details: err === null || err === void 0 ? void 0 : err.attributes
|
|
150
|
+
};
|
|
151
|
+
subject.error(err);
|
|
152
|
+
this.setFileState(id, errorFileState);
|
|
122
153
|
return fromObservable(subject);
|
|
123
154
|
}
|
|
124
|
-
return fromObservable(getFileStreamsCache().getOrInsert(id, () =>
|
|
155
|
+
return fromObservable(getFileStreamsCache().getOrInsert(id, () => {
|
|
156
|
+
const subject = this.createDownloadFileStream(id, collectionName);
|
|
157
|
+
subject.subscribe({
|
|
158
|
+
next: fileState => {
|
|
159
|
+
this.setFileState(id, fileState);
|
|
160
|
+
},
|
|
161
|
+
error: err => {
|
|
162
|
+
const errorFileState = this.getErrorFileState(err, id, occurrenceKey);
|
|
163
|
+
this.setFileState(id, errorFileState);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return subject;
|
|
167
|
+
}));
|
|
125
168
|
}
|
|
126
169
|
getCurrentState(id, options) {
|
|
127
170
|
return toPromise(this.getFileState(id, options));
|
|
128
171
|
}
|
|
129
172
|
getArtifactURL(artifacts, artifactName, collectionName) {
|
|
130
|
-
return this.
|
|
173
|
+
return this.mediaApi.getArtifactURL(artifacts, artifactName, collectionName);
|
|
131
174
|
}
|
|
132
175
|
getFileBinaryURL(id, collectionName) {
|
|
133
|
-
return this.
|
|
176
|
+
return this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
134
177
|
}
|
|
135
178
|
touchFiles(descriptors, collection, traceContext) {
|
|
136
|
-
return this.
|
|
179
|
+
return this.mediaApi.touchFiles({
|
|
137
180
|
descriptors
|
|
138
181
|
}, {
|
|
139
182
|
collection
|
|
@@ -189,6 +232,7 @@ export class FileFetcherImpl {
|
|
|
189
232
|
subject.next(fileState);
|
|
190
233
|
// we save it into the cache as soon as possible, in case someone subscribes
|
|
191
234
|
getFileStreamsCache().set(id, subject);
|
|
235
|
+
this.setFileState(id, fileState);
|
|
192
236
|
return new Promise(async (resolve, reject) => {
|
|
193
237
|
const blob = await deferredBlob;
|
|
194
238
|
if (!blob) {
|
|
@@ -240,15 +284,19 @@ export class FileFetcherImpl {
|
|
|
240
284
|
const subject = createMediaSubject();
|
|
241
285
|
getFileStreamsCache().set(id, subject);
|
|
242
286
|
const onProgress = progress => {
|
|
243
|
-
|
|
287
|
+
const fileState = {
|
|
244
288
|
status: 'uploading',
|
|
245
289
|
...stateBase,
|
|
246
290
|
progress
|
|
247
|
-
}
|
|
291
|
+
};
|
|
292
|
+
subject.next(fileState);
|
|
293
|
+
this.setFileState(id, fileState);
|
|
248
294
|
};
|
|
249
295
|
let processingSubscription = new Subscription();
|
|
250
296
|
const onUploadFinish = error => {
|
|
251
297
|
if (error) {
|
|
298
|
+
const errorFileState = this.getErrorFileState(error, id, occurrenceKey);
|
|
299
|
+
this.setFileState(id, errorFileState);
|
|
252
300
|
return subject.error(error);
|
|
253
301
|
}
|
|
254
302
|
processingSubscription = this.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(remoteFileState => ({
|
|
@@ -256,11 +304,22 @@ export class FileFetcherImpl {
|
|
|
256
304
|
...stateBase,
|
|
257
305
|
...remoteFileState,
|
|
258
306
|
...overrideMediaTypeIfUnknown(remoteFileState, stateBase.mediaType)
|
|
259
|
-
}))).subscribe(
|
|
307
|
+
}))).subscribe({
|
|
308
|
+
next: fileState => {
|
|
309
|
+
subject.next(fileState);
|
|
310
|
+
this.setFileState(id, fileState);
|
|
311
|
+
},
|
|
312
|
+
error: err => {
|
|
313
|
+
const errorFileState = this.getErrorFileState(err, id, occurrenceKey);
|
|
314
|
+
subject.error(err);
|
|
315
|
+
this.setFileState(id, errorFileState);
|
|
316
|
+
},
|
|
317
|
+
complete: subject.complete
|
|
318
|
+
});
|
|
260
319
|
};
|
|
261
320
|
const {
|
|
262
321
|
cancel
|
|
263
|
-
} = uploadFile(file, this.
|
|
322
|
+
} = uploadFile(file, this.mediaApi, upfrontId, {
|
|
264
323
|
onUploadFinish,
|
|
265
324
|
onProgress
|
|
266
325
|
}, traceContext);
|
|
@@ -276,10 +335,8 @@ export class FileFetcherImpl {
|
|
|
276
335
|
setTimeout(onProgress, 0, 0);
|
|
277
336
|
return fromObservable(subject);
|
|
278
337
|
}
|
|
279
|
-
|
|
280
|
-
// TODO: ----- ADD TICKET
|
|
281
338
|
async downloadBinary(id, name = 'download', collectionName) {
|
|
282
|
-
const url = await this.
|
|
339
|
+
const url = await this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
283
340
|
downloadUrl(url, {
|
|
284
341
|
name
|
|
285
342
|
});
|
|
@@ -305,7 +362,7 @@ export class FileFetcherImpl {
|
|
|
305
362
|
preview,
|
|
306
363
|
mimeType
|
|
307
364
|
} = options;
|
|
308
|
-
const mediaStore = destination.mediaStore || new
|
|
365
|
+
const mediaStore = destination.mediaStore || new MediaApi({
|
|
309
366
|
authProvider: destinationAuthProvider
|
|
310
367
|
});
|
|
311
368
|
const owner = authToOwner(await authProvider({
|
|
@@ -359,25 +416,37 @@ export class FileFetcherImpl {
|
|
|
359
416
|
// mimeType should always be returned by "copyFileWithToken"
|
|
360
417
|
// but in case it's not, we don't want to penalize "copyFile"
|
|
361
418
|
copiedMimeType && (await shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview))) {
|
|
362
|
-
|
|
419
|
+
const fileState = {
|
|
363
420
|
...copiedFileState,
|
|
364
421
|
...overrideMediaTypeIfUnknown(copiedFileState, mediaType),
|
|
365
422
|
...previewOverride
|
|
366
|
-
}
|
|
423
|
+
};
|
|
424
|
+
subject.next(fileState);
|
|
425
|
+
this.setFileState(copiedId, fileState);
|
|
367
426
|
processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
|
|
368
|
-
next: remoteFileState =>
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
427
|
+
next: remoteFileState => {
|
|
428
|
+
const fileState = {
|
|
429
|
+
...remoteFileState,
|
|
430
|
+
...overrideMediaTypeIfUnknown(remoteFileState, mediaType),
|
|
431
|
+
...(!isErrorFileState(remoteFileState) && previewOverride)
|
|
432
|
+
};
|
|
433
|
+
this.setFileState(copiedId, fileState);
|
|
434
|
+
return subject.next(fileState);
|
|
435
|
+
},
|
|
436
|
+
error: err => {
|
|
437
|
+
const errorFileState = this.getErrorFileState(err, id, occurrenceKey);
|
|
438
|
+
this.setFileState(copiedId, errorFileState);
|
|
439
|
+
return subject.error(err);
|
|
440
|
+
},
|
|
374
441
|
complete: () => subject.complete()
|
|
375
442
|
});
|
|
376
443
|
} else if (!isProcessingFileState(copiedFileState)) {
|
|
377
|
-
|
|
444
|
+
const fileState = {
|
|
378
445
|
...copiedFileState,
|
|
379
446
|
...(!isErrorFileState(copiedFileState) && previewOverride)
|
|
380
|
-
}
|
|
447
|
+
};
|
|
448
|
+
subject.next(fileState);
|
|
449
|
+
this.setFileState(copiedId, fileState);
|
|
381
450
|
}
|
|
382
451
|
if (!cache.has(copiedId)) {
|
|
383
452
|
getFileStreamsCache().set(copiedId, subject);
|
|
@@ -389,12 +458,16 @@ export class FileFetcherImpl {
|
|
|
389
458
|
}
|
|
390
459
|
if (replaceFileId) {
|
|
391
460
|
const fileCache = cache.get(replaceFileId);
|
|
461
|
+
const replaceFileState = this.store.getState().files[replaceFileId];
|
|
392
462
|
if (fileCache) {
|
|
393
463
|
fileCache.error(error);
|
|
394
464
|
} else {
|
|
395
465
|
// Create a new subject with the error state for new subscriptions
|
|
396
466
|
cache.set(id, createMediaSubject(error));
|
|
397
467
|
}
|
|
468
|
+
const key = replaceFileState ? replaceFileId : id;
|
|
469
|
+
const errorFileState = this.getErrorFileState(error, id, occurrenceKey);
|
|
470
|
+
this.setFileState(key, errorFileState);
|
|
398
471
|
}
|
|
399
472
|
throw error;
|
|
400
473
|
}
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
import { EventEmitter2 } from 'eventemitter2';
|
|
2
|
-
import { MediaStore } from './media-store';
|
|
2
|
+
import { MediaStore as MediaApi } from './media-store';
|
|
3
3
|
import { FileFetcherImpl } from './file-fetcher';
|
|
4
4
|
import { StargateClient } from './stargate-client';
|
|
5
|
+
import { mediaStore } from '@atlaskit/media-state';
|
|
5
6
|
export class MediaClient {
|
|
6
7
|
// mobile upload is lazily loaded
|
|
7
8
|
|
|
8
9
|
// Deprecated value introduced for backward compatibility with Context
|
|
9
10
|
|
|
10
|
-
constructor(mediaClientConfig,
|
|
11
|
+
constructor(mediaClientConfig, store = mediaStore, mediaApi) {
|
|
11
12
|
this.mediaClientConfig = mediaClientConfig;
|
|
12
|
-
this.
|
|
13
|
-
this.mediaStore = new
|
|
13
|
+
this.store = store;
|
|
14
|
+
this.mediaStore = mediaApi !== null && mediaApi !== void 0 ? mediaApi : new MediaApi({
|
|
14
15
|
authProvider: mediaClientConfig.authProvider,
|
|
15
16
|
initialAuth: mediaClientConfig.initialAuth
|
|
16
|
-
}
|
|
17
|
+
});
|
|
17
18
|
this.config = mediaClientConfig;
|
|
18
|
-
this.file = new FileFetcherImpl(this.mediaStore);
|
|
19
|
+
this.file = new FileFetcherImpl(this.mediaStore, this.store);
|
|
19
20
|
this.eventEmitter = new EventEmitter2();
|
|
20
21
|
this.stargate = new StargateClient(mediaClientConfig.stargateBaseUrl);
|
|
21
22
|
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
__DO_NOT_USE__getMediaStore() {
|
|
28
|
+
return this.store;
|
|
29
|
+
}
|
|
22
30
|
getImage(id, params, controller, fetchMaxRes, traceContext) {
|
|
23
31
|
return this.mediaStore.getImage(id, params, controller, fetchMaxRes, traceContext);
|
|
24
32
|
}
|
|
@@ -36,7 +44,7 @@ export class MediaClient {
|
|
|
36
44
|
return this.mobileUpload;
|
|
37
45
|
}
|
|
38
46
|
const module = await import( /* webpackChunkName: "@atlaskit-internal_media-client-mobile-upload" */'./mobile-upload');
|
|
39
|
-
this.mobileUpload = new module.MobileUploadImpl(this.mediaStore);
|
|
47
|
+
this.mobileUpload = new module.MobileUploadImpl(this.mediaStore, this.store);
|
|
40
48
|
return this.mobileUpload;
|
|
41
49
|
}
|
|
42
50
|
async removeFileFromCollection(id, collectionName, occurrenceKey, traceContext) {
|
|
@@ -28,11 +28,10 @@ const jsonHeaders = {
|
|
|
28
28
|
'Content-Type': 'application/json'
|
|
29
29
|
};
|
|
30
30
|
export class MediaStore {
|
|
31
|
-
constructor(config
|
|
31
|
+
constructor(config) {
|
|
32
32
|
_defineProperty(this, "resolveAuth", authContext => resolveAuth(this.config.authProvider, authContext));
|
|
33
33
|
_defineProperty(this, "resolveInitialAuth", () => resolveInitialAuth(this.config.initialAuth));
|
|
34
34
|
this.config = config;
|
|
35
|
-
this.featureFlags = featureFlags;
|
|
36
35
|
}
|
|
37
36
|
async removeCollectionFile(id, collectionName, occurrenceKey, traceContext) {
|
|
38
37
|
const metadata = {
|
|
@@ -1,10 +1,32 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
|
|
3
|
+
import { mediaStore } from '@atlaskit/media-state';
|
|
2
4
|
import { getFileStreamsCache } from '../file-streams-cache';
|
|
3
5
|
import { createFileDataloader } from '../utils/createFileDataLoader';
|
|
4
6
|
import { createServicesCache, createMobileUploadStateMachine, createMobileUploadService, createMobileFileStateSubject } from '../utils/mobileUpload';
|
|
5
7
|
export class MobileUploadImpl {
|
|
6
|
-
constructor(mediaStore) {
|
|
7
|
-
this
|
|
8
|
+
constructor(mediaApi, store = mediaStore) {
|
|
9
|
+
_defineProperty(this, "getErrorFileState", (error, id, occurrenceKey) => typeof error === 'string' ? {
|
|
10
|
+
status: 'error',
|
|
11
|
+
id,
|
|
12
|
+
reason: error,
|
|
13
|
+
occurrenceKey,
|
|
14
|
+
message: error
|
|
15
|
+
} : {
|
|
16
|
+
status: 'error',
|
|
17
|
+
id,
|
|
18
|
+
reason: error === null || error === void 0 ? void 0 : error.reason,
|
|
19
|
+
details: error === null || error === void 0 ? void 0 : error.attributes,
|
|
20
|
+
occurrenceKey,
|
|
21
|
+
message: error === null || error === void 0 ? void 0 : error.message
|
|
22
|
+
});
|
|
23
|
+
_defineProperty(this, "setFileState", (id, fileState) => {
|
|
24
|
+
this.store.setState(state => {
|
|
25
|
+
state.files[id] = fileState;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
this.store = store;
|
|
29
|
+
this.dataloader = createFileDataloader(mediaApi);
|
|
8
30
|
this.servicesCache = createServicesCache();
|
|
9
31
|
}
|
|
10
32
|
notifyUploadStart(event) {
|
|
@@ -33,6 +55,15 @@ export class MobileUploadImpl {
|
|
|
33
55
|
};
|
|
34
56
|
const service = createMobileUploadService(createMobileUploadStateMachine(this.dataloader, initialState, collectionName));
|
|
35
57
|
const subject = createMobileFileStateSubject(service);
|
|
58
|
+
subject.subscribe({
|
|
59
|
+
next: fileState => {
|
|
60
|
+
this.setFileState(fileId, fileState);
|
|
61
|
+
},
|
|
62
|
+
error: err => {
|
|
63
|
+
const errorFileState = this.getErrorFileState(err, fileId, occurrenceKey);
|
|
64
|
+
this.setFileState(fileId, errorFileState);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
36
67
|
this.servicesCache.set(fileId, service);
|
|
37
68
|
getFileStreamsCache().set(fileId, subject);
|
|
38
69
|
}
|
package/dist/es2019/index.js
CHANGED
|
@@ -24,6 +24,7 @@ export { globalMediaEventEmitter } from './globalMediaEventEmitter';
|
|
|
24
24
|
export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
|
|
25
25
|
export { createMediaSubscribable, fromObservable } from './utils/mediaSubscribable';
|
|
26
26
|
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
|
|
27
|
+
export { getFileStreamsCache } from './file-streams-cache';
|
|
27
28
|
|
|
28
29
|
// TODO MEX-659 Remove these exports when all the usages from media-client are replaced with media-common.
|
|
29
30
|
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { MediaClient } from '../client/media-client';
|
|
4
|
-
const NO_FLAGS = 'NO_FLAGS';
|
|
5
4
|
const mediaClientsMap = new Map();
|
|
6
|
-
export const getMediaClient =
|
|
7
|
-
|
|
8
|
-
const flagsMapKey = featureFlags || NO_FLAGS;
|
|
9
|
-
let mediaClient = (_mediaClientsMap$get = mediaClientsMap.get(mediaClientConfig)) === null || _mediaClientsMap$get === void 0 ? void 0 : _mediaClientsMap$get.get(flagsMapKey);
|
|
5
|
+
export const getMediaClient = mediaClientConfig => {
|
|
6
|
+
let mediaClient = mediaClientsMap.get(mediaClientConfig);
|
|
10
7
|
if (!mediaClient) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
subMap = new Map();
|
|
14
|
-
mediaClientsMap.set(mediaClientConfig, subMap);
|
|
15
|
-
}
|
|
16
|
-
mediaClient = new MediaClient(mediaClientConfig, featureFlags);
|
|
17
|
-
subMap.set(flagsMapKey, mediaClient);
|
|
8
|
+
mediaClient = new MediaClient(mediaClientConfig);
|
|
9
|
+
mediaClientsMap.set(mediaClientConfig, mediaClient);
|
|
18
10
|
}
|
|
19
11
|
return mediaClient;
|
|
20
12
|
};
|
|
21
|
-
const createEmptyMediaClient =
|
|
13
|
+
const createEmptyMediaClient = () => {
|
|
22
14
|
const emptyConfig = {
|
|
23
15
|
authProvider: () => Promise.resolve({
|
|
24
16
|
clientId: '',
|
|
@@ -26,9 +18,9 @@ const createEmptyMediaClient = featureFlags => {
|
|
|
26
18
|
baseUrl: ''
|
|
27
19
|
})
|
|
28
20
|
};
|
|
29
|
-
return new MediaClient(emptyConfig
|
|
21
|
+
return new MediaClient(emptyConfig);
|
|
30
22
|
};
|
|
31
|
-
export const withMediaClient =
|
|
23
|
+
export const withMediaClient = Component => {
|
|
32
24
|
return class extends React.Component {
|
|
33
25
|
render() {
|
|
34
26
|
// TODO MPT-315: clean up after we move mediaClientConfig into FileIdentifier
|
|
@@ -36,7 +28,7 @@ export const withMediaClient = (Component, featureFlags) => {
|
|
|
36
28
|
mediaClientConfig,
|
|
37
29
|
...otherProps
|
|
38
30
|
} = this.props;
|
|
39
|
-
const mediaClient = !mediaClientConfig ? createEmptyMediaClient(
|
|
31
|
+
const mediaClient = !mediaClientConfig ? createEmptyMediaClient() : getMediaClient(mediaClientConfig);
|
|
40
32
|
return /*#__PURE__*/React.createElement(Component, _extends({}, otherProps, {
|
|
41
33
|
mediaClient: mediaClient
|
|
42
34
|
}));
|