1 | ;
|
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 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.Available = exports.AvailableSurfaces = exports.AvailableSurfacesCapabilities = exports.Capabilities = exports.Surface = void 0;
|
19 | class Surface {
|
20 | /** @hidden */
|
21 | constructor(surface = {}) {
|
22 | this.capabilities = new Capabilities(surface.capabilities);
|
23 | }
|
24 | /**
|
25 | * Checks if surface has an attribute like a capability
|
26 | *
|
27 | * @example
|
28 | * ```javascript
|
29 | *
|
30 | * app.intent('Default Welcome Intent', conv => {
|
31 | * if (conv.surface.has('actions.capability.AUDIO_OUTPUT')) {
|
32 | * conv.ask('You can hear me! How are you?')
|
33 | * } else {
|
34 | * conv.ask('You can read this! How are you?')
|
35 | * }
|
36 | * })
|
37 | * ```
|
38 | *
|
39 | * @param attribute An attribute like SurfaceCapability
|
40 | * @public
|
41 | */
|
42 | has(attribute) {
|
43 | if (this.capabilities.has(attribute)) {
|
44 | return true;
|
45 | }
|
46 | return false;
|
47 | }
|
48 | }
|
49 | exports.Surface = Surface;
|
50 | class Capabilities {
|
51 | /** @hidden */
|
52 | constructor(list = []) {
|
53 | this.list = list;
|
54 | }
|
55 | /**
|
56 | * Returns true if user device has a given surface capability.
|
57 | * @public
|
58 | */
|
59 | has(capability) {
|
60 | return this.list.map(c => c.name).indexOf(capability) > -1;
|
61 | }
|
62 | }
|
63 | exports.Capabilities = Capabilities;
|
64 | class AvailableSurfacesCapabilities {
|
65 | /** @hidden */
|
66 | constructor(surfaces) {
|
67 | this.surfaces = surfaces;
|
68 | }
|
69 | /**
|
70 | * Returns true if user has an available surface which includes all given
|
71 | * capabilities. Available surfaces capabilities may exist on surfaces other
|
72 | * than that used for an ongoing conversation.
|
73 | * @public
|
74 | */
|
75 | has(capability) {
|
76 | return (this.surfaces.findIndex(surface => surface.capabilities.has(capability)) >
|
77 | -1);
|
78 | }
|
79 | }
|
80 | exports.AvailableSurfacesCapabilities = AvailableSurfacesCapabilities;
|
81 | class AvailableSurfaces {
|
82 | /** @hidden */
|
83 | constructor(list) {
|
84 | this.list = list.map(surface => new Surface(surface));
|
85 | this.capabilities = new AvailableSurfacesCapabilities(this.list);
|
86 | }
|
87 | /**
|
88 | * Checks if available surfaces has an attribute like a capability
|
89 | *
|
90 | * @example
|
91 | * ```javascript
|
92 | *
|
93 | * app.intent('Default Welcome Intent', conv => {
|
94 | * if (conv.available.surfaces.has('actions.capability.SCREEN_OUTPUT')) {
|
95 | * conv.ask('You have a device that can view images! How are you?')
|
96 | * } else {
|
97 | * conv.ask('You do not have a device that can view images! How are you?')
|
98 | * }
|
99 | * })
|
100 | * ```
|
101 | *
|
102 | * @param attribute An attribute like SurfaceCapability
|
103 | * @public
|
104 | */
|
105 | has(attribute) {
|
106 | if (this.capabilities.has(attribute)) {
|
107 | return true;
|
108 | }
|
109 | return false;
|
110 | }
|
111 | }
|
112 | exports.AvailableSurfaces = AvailableSurfaces;
|
113 | class Available {
|
114 | /** @hidden */
|
115 | constructor(surfaces = []) {
|
116 | this.surfaces = new AvailableSurfaces(surfaces);
|
117 | }
|
118 | }
|
119 | exports.Available = Available;
|
120 | //# sourceMappingURL=surface.js.map |
\ | No newline at end of file |