Skip to content

Commit e34bc13

Browse files
committed
cleaned up some frame and widgets stuff + more offline tests
1 parent babc80a commit e34bc13

File tree

8 files changed

+71
-78
lines changed

8 files changed

+71
-78
lines changed

www/scripts/sepiaFW.frames.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ function sepiaFW_build_frames(){
224224
//Error
225225
}, function(){
226226
$('#sepiaFW-frames-view').html("Error - could not load page");
227+
SepiaFW.ui.showInfo("Custom view failed to load. URL: " + framePage, true);
227228
});
228229
}
229230

www/scripts/sepiaFW.offline.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function sepiaFW_build_offline(){
8585
data.desc = description || "Click to open";
8686
if (!url) url = "https://sepia-framework.github.io/app/search.html";
8787
/* other data content e.g.:
88-
"type": "musicSearch",
88+
"type": "musicSearch", //default, custom, websearch, musicSearch, videoSearch
8989
"brand": "Spotify"
9090
*/
9191
data.type = imageUrl? "custom" : "default";
@@ -102,7 +102,8 @@ function sepiaFW_build_offline(){
102102
"url": url
103103
}]
104104
};
105-
return cardInfoItem; //NOTE: it is ONE ITEM of the cardInfo-array! To build use e.g. [getLinkCard(...)]
105+
return cardInfoItem;
106+
//NOTE: it is ONE ITEM of the cardInfo-array! To build use e.g. [getLinkCard(...)]
106107
}
107108

108109
//------------------ custom buttons -------------------

www/scripts/sepiaFW.ui.cards.embed.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ function sepiaFW_build_ui_cards_embed(){
2020
soundcloud: "<assist_server>/widgets/mp-soundcloud.html"
2121
}
2222
function getPlayerWidget(widget){
23-
if (SepiaFW.client.isDemoMode()){
24-
return playerWidgets.template;
25-
}else{
26-
return playerWidgets[widget];
23+
var wUrl = playerWidgets[widget];
24+
if (wUrl && SepiaFW.client.isDemoMode()){
25+
wUrl = wUrl.replace("<assist_server>", "<custom_data>");
2726
}
27+
return wUrl;
2828
}
2929

3030
var activeMediaPlayers = {};
@@ -227,6 +227,7 @@ function sepiaFW_build_ui_cards_embed(){
227227
//on-load
228228
//console.error("on-load", playerId); //DEBUG
229229
});
230+
var loadTimer = setTimeout(function(){ $(thisPlayer.overlay).hide(); }, 6000); //fallback if read event never comes
230231
thisPlayer.iframe = mpObj.iframe;
231232
thisPlayer.cardItem = mpObj.card;
232233
thisPlayer.overlay = mpObj.overlay;
@@ -337,6 +338,7 @@ function sepiaFW_build_ui_cards_embed(){
337338
if (data.size && data.size.height){
338339
thisPlayer.iframe.style.height = data.size.height;
339340
}
341+
clearTimeout(loadTimer);
340342
setTimeout(function(){ $(thisPlayer.overlay).hide(); }, 500);
341343
//settings stored?
342344
if (widgetSettings){

www/templates/dynamic-frame.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<div id="sepiaFW-frame-page-1" class='sepiaFW-frames-page sepiaFW-carousel-pane'>
55
Page 1
66
</div>
7+
<!-- Page 2
8+
<div id="sepiaFW-frame-page-2" class='sepiaFW-frames-page sepiaFW-carousel-pane'>
9+
Page 2
10+
</div> -->
711
</div>
812
</div>
913
<div id="sepiaFW-frames-nav-bar" class='sepiaFW-layer-header'>
@@ -21,7 +25,7 @@
2125
<span data-localize="next">next</span><i class="material-icons md-btn2">keyboard_arrow_right</i>
2226
</button>
2327
-->
24-
<div id="sepiaFW-frames-nav-bar-page-indicator"><div>&nbsp;</div></div>
28+
<div id="sepiaFW-frames-nav-bar-page-indicator"><div>&nbsp;</div><!--<div>&nbsp;</div>--></div>
2529
</div>
2630
<script>
2731
$('#sepiaFW-frame-carousel').find('[data-localize]').each(function(){

www/templates/frames_template.html

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Custom Data Folder
22

3-
You can put own data here and call it inside the app for example via `SepiaFW.files.fetch("<custom_data>"/...)`.
3+
You can put own data here and call it inside the app for example via `SepiaFW.files.fetch("<custom_data>"/...)`.
4+
5+
NOTE: In mobile apps `<custom_data>/` will access the user-data folder available for your app.

www/xtensions/custom-data/demo-view.html renamed to www/xtensions/custom-data/views/demo-view.html

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,25 @@ <h3>Page 2 - Microphone and chat output</h3>
3131
<script>
3232
//NOTE: this is a more basic version of "<assist_server>/views/custom-view-demo.html"
3333

34+
//Use this action in your service (or Teach-UI) to trigger the demo frame:
35+
//Action name: "open_frames_view";
36+
//Action data: "info": {"pageUrl": "<custom_data>/views/demo-view.html"}
37+
38+
//Localize some UI text
3439
$('#sepiaFW-frame-carousel').find('[data-localize]').each(function(){
3540
$(this).html(SepiaFW.local.g(this.dataset.localize));
3641
});
42+
/* Currently available frame events:
43+
onFinishSetup
44+
onOpen
45+
onFramePageChange
46+
onClose
47+
onMessageHandler
48+
onMissedMessageHandler
49+
onSpeechToTextInputHandler
50+
onChatOutputHandler
51+
actionHandler (for custom actions of type: 'frames_view_action')
52+
*/
3753
//Define scope
3854
SepiaFW.frames.currentScope = {
3955
//Theme (frame: light, dark, mod.: flat, screen: dark_full)
@@ -43,23 +59,26 @@ <h3>Page 2 - Microphone and chat output</h3>
4359
load: function(){
4460
$('#sepiaFW-frames-mic').attr('class', 'entry icon-button');
4561
},
46-
sayHelloOnOpen: function(){
62+
onOpen: function(){
4763
//we use '$('#sepiaFW-frame-page-...')' to avoid conflicts with global ID:
4864
$('#sepiaFW-frame-page-1 #sepiaFW-frame-c-hello').html(
4965
"<p>Welcome to the Demo-View frame.</p>"
5066
+ "<p>This frame runs inside the scope of the SEPIA client and has open access to all features.</p>"
5167
+ "<p>This type of frames can only be used when loaded from safe origins (e.g. app folder, or SEPIA server).</p>"
5268
);
5369
},
54-
handleSttData: function(data){
70+
onClose: function(){
71+
console.log("BYE BYE");
72+
},
73+
onSpeechToTextInputHandler: function(data){
5574
$('#sepiaFW-frame-page-2 #sepiaFW-frame-c-stt-data').val(JSON.stringify(data, "", 2));
5675
//modify text to include custom tag (can be used to redirect all input to a custom service for example)
5776
if (data.text && data.isFinal){
5877
var textWithPrefix = SepiaFW.frames.currentScope.nluPrefix? (SepiaFW.frames.currentScope.nluPrefix + " " + data.text) : data.text;
5978
return textWithPrefix; //<-- return the data to actually modify it
6079
}
6180
},
62-
handleChatOutput: function(data){
81+
onChatOutputHandler: function(data){
6382
$('#sepiaFW-frame-page-2').find('#sepiaFW-frame-c-chat-data').val(JSON.stringify(data, "", 2));
6483
},
6584

@@ -71,15 +90,10 @@ <h3>Page 2 - Microphone and chat output</h3>
7190
$('#sepiaFW-frames-mic').attr('class', 'entry icon-button state-' + animState);
7291
},
7392

74-
//Custom actions (only)
93+
//For custom 'frames_view_action' (only)
7594
actionHandler: function(action){
7695
console.error(action);
7796
}
78-
79-
//Use this action in your service to trigger the demo frame:
80-
//Action name: "open_frames_view";
81-
//Action data: "info": {"pageUrl": "<custom_data>/demo-view.html", "onOpen": "sayHelloOnOpen", "onSpeechToTextInputHandler": "handleSttData", "onChatOutputHandler": "handleChatOutput"}
82-
//- alternatively use: {"pageUrl":..., "autoFillFrameEvents": true} to load all handlers via default name from frame scope
8397
}
8498
SepiaFW.frames.currentScope.load();
8599
</script>

www/templates/media-player_template.html renamed to www/xtensions/custom-data/widgets/mp-default.html

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
</div>
6262
<!-- JS -->
6363
<script type="text/javascript">
64+
//NOTE: This is a demo implementation of the SEPIA Client Media-Player Widget
65+
66+
//--------- COMMON WIDGET INTERFACE ---------
67+
6468
//postMessage listener
6569
window.addEventListener('message', function(message){
6670
if (message.data && message.data.type){
@@ -133,7 +137,7 @@
133137
//settings previously sent by the widget (widget/app specific etc. - NOTE: avoid autoplay!)
134138
handleSettingsRestore(ev);
135139
}else{
136-
console.error("event", ev); //DEBUG
140+
console.error("MediaPlayer - Unknown event", ev); //DEBUG
137141
}
138142
}
139143

@@ -147,7 +151,7 @@
147151

148152
function handleSettingsRestore(ev){
149153
//any widget specific data submitted by widget itself (either via 'postSettings' or during 'ready')
150-
console.error("Settings", ev.settings); //DEBUG
154+
console.error("MediaPlayer - Settings", ev.settings); //DEBUG
151155
var settings = ev.settings;
152156
//restore
153157
autoplay = settings.autoplay || false;
@@ -158,7 +162,7 @@
158162

159163
function handleControls(ev){
160164
//play, pause, fadeOut, fadeIn, next, previous, volumeUp, volumeDown, ... tbd
161-
console.error("Controls", ev.controls); //DEBUG
165+
console.error("MediaPlayer - Controls", ev.controls); //DEBUG
162166
var ctrl = ev.controls;
163167
switch (ev.controls){
164168
case "play":
@@ -171,13 +175,17 @@
171175
player.pause();
172176
break;
173177
case "next":
178+
//TODO: ignored for now
179+
break;
174180
case "previous":
175181
//TODO: ignored for now
176182
break;
177183
case "volumeUp":
178184
playerSetVolume(playerGetVolume() + 1);
185+
break;
179186
case "volumeDown":
180187
playerSetVolume(playerGetVolume() - 1);
188+
break;
181189
case "volumeSet":
182190
if (ev.data != undefined) playerSetVolume(ev.data);
183191
break;
@@ -197,27 +205,29 @@
197205
}
198206

199207
function handleMediaRequest(ev){
200-
console.error("Media request", ev.mediaRequest); //DEBUG
208+
console.error("MediaPlayer - mediaRequest", ev.mediaRequest, ev.autoplay); //DEBUG
201209
var mr = ev.mediaRequest;
202210
/* type: music:
203211
{
204212
"song": "",
205-
"search": "",
206213
"playlist": "",
207214
"artist": "",
208215
"album": "",
209-
"service": "",
210216
"genre": "",
217+
"search": "",
211218
"uri": "",
219+
"service": "",
212220
"serviceResult": {...} //specific to service
213221
}*/
214222
var safeRequest = ev.safeRequest; //request came from assistant or private channel?
215223
autoplay = ev.autoplay;
216224

217-
//"search" music:
218225
var url = "";
219226
var title = "";
220227

228+
//"Search" Music - SIMPLE DEMO:
229+
//Possible search terms - Artist: "ed", "virginia", Song: "twister", "titanic"
230+
//
221231
if (mr.song && mr.song.trim().toLowerCase().indexOf("twister") >= 0){
222232
url = "http://www.openmusicarchive.org/audio/Eddies_Twister.mp3";
223233
title = "Eddies Twister";
@@ -233,8 +243,8 @@
233243
title = "Titanic Blues";
234244
}
235245

246+
//Load music
236247
if (url){
237-
//Load music
238248
if (safeRequest){
239249
player.preload = "auto";
240250
}else{
@@ -258,13 +268,13 @@
258268
}
259269

260270
player.oncanplay = function(){
261-
console.error("oncanplay", arguments); //DEBUG
271+
console.error("MediaPlayer - oncanplay", arguments); //DEBUG
262272
if (autoplay){
263273
player.play();
264274
}
265275
};
266276
player.onplay = function(){
267-
console.error("onplay", arguments); //DEBUG
277+
console.error("MediaPlayer - onplay", arguments); //DEBUG
268278
postState(2, {
269279
meta: {
270280
title: player.title,
@@ -273,17 +283,20 @@
273283
});
274284
};
275285
player.onpause = function(){
276-
console.error("onpause", arguments); //DEBUG
286+
console.error("MediaPlayer - onpause", arguments); //DEBUG
277287
postState(3);
278288
};
279289
player.onended = function(){
280-
console.error("onended", arguments); //DEBUG
290+
console.error("MediaPlayer - onended", arguments); //DEBUG
281291
};
282292
player.onvolumechange = function(){
283-
console.error("onvolumechange", player.volume); //DEBUG
293+
console.error("MediaPlayer - onvolumechange", player.volume); //DEBUG
294+
postProperties({
295+
volume: playerGetVolume()
296+
});
284297
};
285298
player.onerror = function(err){
286-
console.error("onerror", err, player.error); //DEBUG
299+
console.error("MediaPlayer - onerror", err, player.error); //DEBUG
287300
if (player.error && player.error.code === 4){
288301
postError("PlayerError", "Cannot play the selected media data.", 4);
289302
}else if (err && err.name && err.name == "NotAllowedError"){
@@ -300,12 +313,13 @@
300313

301314
//--------- DEMO END ---------
302315

303-
//ready
316+
//Send 'ready' event:
304317
setTimeout(function(){
305318
postProperties({
306319
size: {
307320
height: (cardBody.getBoundingClientRect().height + "px")
308-
}
321+
},
322+
volume: playerGetVolume()
309323
});
310324
postState(1, {});
311325
}, 300);

0 commit comments

Comments
 (0)