This repository has been archived by the owner on Jul 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiver.html
executable file
·101 lines (80 loc) · 3.4 KB
/
receiver.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html>
<head>
<title>Flickr Chromecast</title>
<link rel="stylesheet" href="common.css" />
<link rel="stylesheet" href="receiver.css" />
</head>
<body>
<div id="flickr-container"></div>
<script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<script type="text/javascript" src="flickrapi/browser/flickrapi.dev.js"></script>
<script type="text/javascript" src="js/ReceiverApplication.js"></script>
<script type="text/javascript">
// Setup the cast SDK configuraiton
var chromecastConfiguration = new cast.receiver.CastReceiverManager.Config();
chromecastConfiguration.maxInactivity = 6400;
// Hookup the messagebus so we can hook into incoming messages
var receiverManager = cast.receiver.CastReceiverManager.getInstance();
var messageBus = receiverManager.getCastMessageBus("urn:x-cast:com.danielsgroves.plymouthjs");
messageBus.onMessage = newMessageHandler;
// Start the SDK
receiverManager.start(chromecastConfiguration);
var flickr = null;
/**
* Callback for newly received messages.
* This parses the message and determins the correct methods to call.
* @param {cast.receiver.CastMessageBus.Event} data - The incoming message object.
*/
function newMessageHandler(data) {
// Parse the custom part of the message (as sent from the sender).
var message = JSON.parse(data.data);
console.log("Message is of type " + message.key);
// Initiate the API if it's key is setup
if (message.key === 'setup') {
var userId = message.value.uid;
var apiKey = message.value.apikey;
flickr = new FlickrApiWrapper(apiKey, userId);
}
// Show album if the key is showalbum
if (message.key === 'showalbum') {
var albumId = message.value;
flickr.showAlbumMeta(albumId, displayAlbum);
}
// Show the single image if the key is showimage
if (message.key === 'showimage') {
var imageId = message.value;
flickr.showSingleImage(imageId, displayImage);
}
}
/**
* Callback to display the `showAlbumMeta` results from the FlickrAPI wrapper.
* @param {Object} data - Generic object containing the results from the Fickr API call.
*/
function displayAlbum(data) {
var article = document.createElement('article');
article.style.backgroundImage = "url(" + data.imageUrl + ")";
var title = document.createElement('h1');
title.innerHTML = data.title;
var description = document.createElement('p');
description.innerHTML = data.description;
article.appendChild(title);
article.appendChild(description);
var container = document.getElementById('flickr-container');
container.innerHTML = '';
container.appendChild(article);
}
/**
* Callback to display the `showSingleImage` results from the FlickrAPI wrapper.
* @param {String} The URL of the selected image.
*/
function displayImage(imageUrl) {
var image = document.createElement('img');
image.src = imageUrl;
var container = document.getElementById('flickr-container');
container.innerHTML = '';
container.appendChild(image);
}
</script>
</body>
</html>