1 | import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
|
2 |
|
3 | const appMapping = {
|
4 | 'make-music': 'music',
|
5 | 'make-light': 'art',
|
6 | 'kano-draw': 'art',
|
7 | 'make-apps': 'app',
|
8 | lightboard: 'app',
|
9 | };
|
10 | const loadedImports = {};
|
11 |
|
12 | class KwcSharePlayer extends PolymerElement {
|
13 | static get template() {
|
14 | return html`
|
15 | <style>
|
16 | kwc-app-player,
|
17 | kwc-art-player {
|
18 | animation: fade-in 200ms linear;
|
19 | }
|
20 | </style>
|
21 | <template is="dom-if" if="[[_usePlayer('app', _player)]]" restamp>
|
22 | <kwc-app-player share="[[share]]" display-code="[[displayCode]]" on-hide-code="_hideCode">
|
23 | <slot slot="hardware" name="hardware-list"></slot>
|
24 | </kwc-app-player>
|
25 | </template>
|
26 | <template is="dom-if" if="[[_usePlayer('art', _player)]]" restamp>
|
27 | <kwc-art-player share="[[share]]" display-code="[[displayCode]]"></kwc-art-player>
|
28 | </template>
|
29 | <template is="dom-if" if="[[_usePlayer('music', _player)]]" restamp>
|
30 | <kwc-music-player share="[[share]]"></kwc-music-player>
|
31 | </template>
|
32 | <template is="dom-if" if="[[_usePlayer('default', _player)]]" restamp>
|
33 | <kwc-player share="[[share]]"></kwc-player>
|
34 | </template>
|
35 | `;
|
36 | }
|
37 | static get properties() {
|
38 | return {
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | displayCode: {
|
45 | type: Boolean,
|
46 | value: false,
|
47 | notify: true,
|
48 | },
|
49 | |
50 |
|
51 |
|
52 |
|
53 | share: {
|
54 | type: Object,
|
55 | value: () => ({}),
|
56 | },
|
57 | |
58 |
|
59 |
|
60 |
|
61 | _player: {
|
62 | type: String,
|
63 | value: '',
|
64 | },
|
65 | };
|
66 | }
|
67 | static get observers() {
|
68 | return [
|
69 | '_shareChanged(share.*)',
|
70 | ];
|
71 | }
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | _shareChanged(shareChange) {
|
80 | const share = shareChange.base;
|
81 |
|
82 | if (!share || !Object.keys(share).length) {
|
83 | return;
|
84 | }
|
85 | const player = appMapping[share.app] || 'default';
|
86 |
|
87 | if (loadedImports[player]) {
|
88 | this.set('_player', player);
|
89 | } else {
|
90 | this.lazyImport(player).then(() => {
|
91 | loadedImports[player] = true;
|
92 | this.set('_player', player);
|
93 | });
|
94 | }
|
95 | }
|
96 | lazyImport(id) {
|
97 |
|
98 | switch (id) {
|
99 | case 'app': {
|
100 | return import('./kwc-app-player.js');
|
101 | }
|
102 | case 'art': {
|
103 | return import('./kwc-art-player.js');
|
104 | }
|
105 | case 'music': {
|
106 | return import('./kwc-music-player.js');
|
107 | }
|
108 | default: {
|
109 | return import('./kwc-player.js');
|
110 | }
|
111 | }
|
112 | }
|
113 | |
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | _usePlayer(key, player) {
|
120 | return key === player;
|
121 | }
|
122 |
|
123 | |
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | _hideCode(e) {
|
130 | this.displayCode = false;
|
131 | this.dispatchEvent(new CustomEvent('hide-code', { detail: e.detail }));
|
132 | }
|
133 | }
|
134 |
|
135 |
|
136 | customElements.define('kwc-share-player', KwcSharePlayer);
|