UNPKG

2.17 kBJavaScriptView Raw
1"use strict";
2/**
3 * Copyright 2018 Google Inc. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.MediaResponse = exports.MediaObject = void 0;
19const toMediaObject = (object) => {
20 if (typeof object === 'string') {
21 return new MediaObject(object);
22 }
23 return object;
24};
25class MediaObject {
26 /**
27 * @param options MediaObject options or just a string for the url
28 * @public
29 */
30 constructor(options) {
31 if (typeof options === 'string') {
32 this.contentUrl = options;
33 return;
34 }
35 this.contentUrl = options.url;
36 this.description = options.description;
37 this.icon = options.icon;
38 this.largeImage = options.image;
39 this.name = options.name;
40 }
41}
42exports.MediaObject = MediaObject;
43const isOptions = (options) => {
44 const test = options;
45 return Array.isArray(test.objects);
46};
47class MediaResponse {
48 constructor(options, ...objects) {
49 this.mediaType = 'AUDIO';
50 if (!options) {
51 this.mediaObjects = [];
52 return;
53 }
54 if (Array.isArray(options)) {
55 this.mediaObjects = options.map(o => toMediaObject(o));
56 return;
57 }
58 if (isOptions(options)) {
59 this.mediaType = options.type || this.mediaType;
60 this.mediaObjects = options.objects.map(o => toMediaObject(o));
61 return;
62 }
63 this.mediaObjects = [options].concat(objects).map(o => toMediaObject(o));
64 }
65}
66exports.MediaResponse = MediaResponse;
67//# sourceMappingURL=media.js.map
\No newline at end of file