-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreceiver.html
150 lines (125 loc) · 5.49 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!--
Copyright (C) 2014 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
overflow: hidden;
}
div {
height: 720PX;
width: 1280PX;
text-align: center;
border: 0px solid silver;
display: table-cell;
vertical-align: middle;
color: #000000;
background-color: #FFFFFF;
font-weight: bold;
font-family: Verdana, Geneva, sans-serif;
font-size: 40px;
}
</style>
<title>Diga Algo!</title>
</head>
<body>
<DIV id="message">Diga algo!</DIV>
<script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<script type="text/javascript">
window.onload = function () {
cast.receiver.logger.setLevelValue(0);
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
console.log('Starting Receiver Manager');
// handler for the 'ready' event
castReceiverManager.onReady = function (event) {
console.log('Received Ready event: ' + JSON.stringify(event.data));
window.castReceiverManager.setApplicationState("Application status is ready...");
};
// handler for 'senderconnected' event
castReceiverManager.onSenderConnected = function (event) {
console.log('Received Sender Connected event: ' + event.data);
console.log(window.castReceiverManager.getSender(event.data).userAgent);
};
// handler for 'senderdisconnected' event
castReceiverManager.onSenderDisconnected = function (event) {
console.log('Received Sender Disconnected event: ' + event.data);
if (window.castReceiverManager.getSenders().length == 0) {
window.close();
}
};
// handler for 'systemvolumechanged' event
castReceiverManager.onSystemVolumeChanged = function (event) {
console.log('Received System Volume Changed event: ' + event.data['level'] + ' ' +
event.data['muted']);
};
// Cria um CastMessageBus que irá trocar as mensagens dentro do namespace configurado
window.messageBus =
window.castReceiverManager.getCastMessageBus('urn:x-cast:com.tiagogouvea.cast.digaalgo');
// Responde pelo evento OnMessage do CastMessageBus - lida com as mensagens recebidas
window.messageBus.onMessage = function (event) {
console.log('Message [' + event.senderId + ']: ' + event.data);
// Exibir o texto enviado pelo Sender
displayText(event.data);
// Informa a todos os sender que a mensagem foi "recebida"
// Irá ivocar o listener de mensagens nos sender com a mesma mensagem recebida aqui
window.messageBus.send(event.senderId, event.data);
}
// Inicializa o CastReceiverManager com uma mensagem de status
window.castReceiverManager.start({statusText: "Aplicação iniciando"});
console.log('Receiver Manager iniciado');
};
// Método que irá exibir a mensagem na tela
function displayText(text) {
console.log(text);
var screenWidth = window.innerWidth;
var screenHeight = window.innerHeight;
var colors = ['#0140CA','#DD1812','#FCCA03','#16A61E'];
var corBackground=colors[Math.floor((Math.random() * 4))];
var fonts = ['Sans-Serif','Monospace','Fantasy','Cursive'];
var fontFamily = fonts[Math.floor((Math.random() * 4))];
var spanTag = document.createElement("span");
spanTag.innerHTML = text;
spanTag.style.fontSize= 20+Math.floor((Math.random() * 40) + 1)+'px';
spanTag.style.color = 'white';
spanTag.style.backgroundColor = corBackground;
spanTag.style.fontFamily = fontFamily;
spanTag.style.padding = '10px';
spanTag.style.position = 'fixed';
document.body.appendChild(spanTag);
spanTag.style.top = Math.floor((Math.random() * (screenHeight - spanTag.offsetHeight) + 1))+'px';
spanTag.style.left = Math.floor((Math.random() * (screenWidth - spanTag.offsetWidth) + 1))+'px';
console.log(spanTag.offsetWidth);
window.castReceiverManager.setApplicationState(text);
}
;
function verificarTamanho(){
if (typeof (window.innerWidth) == 'number') {
} else {
if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
screenWidth = document.documentElement.clientWidth;
} else {
if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
screenWidth = document.body.clientWidth;
}
}
}
if (screenWidth<1230)
mobile=true;
else
mobile=false;
draw();
}
</script>
</body>
</html>