-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal-debugger.js
255 lines (210 loc) · 9.34 KB
/
local-debugger.js
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
const Alexa = require('ask-sdk-core');
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
var token=0
var Title='défault';
var Artist='toi';
var pochette="";
//const SpeakBreak = ' ,'
const SpeakBreak ='<break time="300ms"/>';
const LongSpeakBreak ='<break time="1s"/>';
function getOffsetInMilliseconds(handlerInput) {
// Extracting offsetInMilliseconds received in the request.
return handlerInput.requestEnvelope.request.offsetInMilliseconds;
}
const StreamUrl="https://listen.radioking.com/radio/184318/stream/226369"
var offsetInMilliseconds=0
const headers = {
headers: {
"x-api-key": "L7QF50ujQm57MqDJxBB789rUGhkJ0FvB3fYOqYrl",
}
}
const ApiUrl="https://api.radioking.io/widget/radio/voltigeradio-1/track/current"
//******************FONCTION PRINCIPALE*************************************************************************************/
const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest' ||
handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
(
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ResumeIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.LoopOnIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.NextIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.PreviousIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.RepeatIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ShuffleOnIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StartOverIntent'
);
},
async handle(handlerInput) {
token =getRandomInt(31)
const STREAMS = [{
"token": "1",
"url": "https://listen.radioking.com/radio/184318/stream/226369",
"metadata": {
"title": "Voltige Radio",
"subtitle":" La génération des hits",
"art": {
"sources": [{
"contentDescription": "logo",
"url": "https://www.blablafoot.com/wp-content/uploads/2018/05/LOGO_512x512_x2-1-e1527686186121.png",
"widthPixels": 512,
"heightPixels": 512
}]
},
"backgroundImage": {
"sources": [{
"contentDescription": "example image",
"url": "https://www.blablafoot.com/wp-content/uploads/2018/05/LOGO_512x512_x2-1-e1527686186121.png",
"widthPixels": 1200,
"heightPixels": 800
}]
}
}
}];
/***** APPELLE API*********************/
/*await getRemoteDataH(ApiUrl)
.then((response) => {
const data = JSON.parse(response);
Title=data.title
Artist=data.artist
pochette=data.cover
})
.catch((err) => {
//set an optiotnal error message here
//outputSpeech = err.message;
});*/
/***************************************/
let stream = STREAMS[0];
const StreamUrl="https://listen.radioking.com/radio/184318/stream/226369"
stream.url = StreamUrl
stream.metadata.art.sources[0].url=pochette
handlerInput.responseBuilder
.addAudioPlayerPlayDirective('REPLACE_ALL', stream.url, token, offsetInMilliseconds, null, stream.metadata);
var speechText ='Bienvenue sur Voltige Radio, la génération des hits.'
//+SpeakBreak+'Vous écoutez'+SpeakBreak+Title+'de'+SpeakBreak+Artist
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
},
};
//********************************************************************************************************************/
const HelpIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const speechText = 'Pour relancer la diffusion dite, reprendre, pour mettre en pause dite';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
},
};
const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
(
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.PauseIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.LoopOffIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ShuffleOffIntent'
);
},
handle(handlerInput) {
handlerInput.responseBuilder
.addAudioPlayerClearQueueDirective('CLEAR_ALL')
.addAudioPlayerStopDirective();
offsetInMilliseconds=getOffsetInMilliseconds(handlerInput)
return handlerInput.responseBuilder
.getResponse();
},
};
const PlaybackStoppedIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'PlaybackController.PauseCommandIssued' ||
handlerInput.requestEnvelope.request.type === 'AudioPlayer.PlaybackStopped';
},
handle(handlerInput) {
offsetInMilliseconds=getOffsetInMilliseconds(handlerInput)
handlerInput.responseBuilder
.addAudioPlayerClearQueueDirective('CLEAR_ALL')
.addAudioPlayerStopDirective();
return handlerInput.responseBuilder
.getResponse();
},
};
const PlaybackStartedIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'AudioPlayer.PlaybackStarted';
},
handle(handlerInput) {
handlerInput.responseBuilder
.addAudioPlayerClearQueueDirective('CLEAR_ENQUEUED');
return handlerInput.responseBuilder
.getResponse();
},
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
return handlerInput.responseBuilder
.getResponse();
},
};
const ExceptionEncounteredRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'System.ExceptionEncountered';
},
handle(handlerInput) {
console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
return true;
},
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(`Error handled: ${error.message}`);
console.log(handlerInput.requestEnvelope.request.type);
return handlerInput.responseBuilder
.getResponse();
},
};
//**************************Fonction qui permet les appels API******************************************************************/
const getRemoteDataH = function(url) {
return new Promise((resolve, reject) => {
const client = url.startsWith('https') ? require('https') : require('http');
const request = client.get(url, (response) => {
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error('Failed with status code: ' + response.statusCode));
}
const body = [];
response.on('data', (chunk) => body.push(chunk));
response.on('end', () => resolve(body.join('')));
});
request.on('error', (err) => reject(err))
})
};
//******************************************************************************************************/
//******************************************************************************************************/
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
PlaybackStartedIntentHandler,
CancelAndStopIntentHandler,
PlaybackStoppedIntentHandler,
HelpIntentHandler,
ExceptionEncounteredRequestHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.withApiClient(new Alexa.DefaultApiClient())
.lambda();