-
Notifications
You must be signed in to change notification settings - Fork 40
/
MMM-GoogleAssistant.js
61 lines (56 loc) · 1.69 KB
/
MMM-GoogleAssistant.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
/* Magic Mirror
* Module: MMM-GoogleAssistant
*
* By Gaurav
*
*/
Module.register("MMM-GoogleAssistant", {
// Module config defaults.
defaults: {
header: "Google Asistant",
maxWidth: "100%",
publishKey: 'PUBLISH_KEY',
subscribeKey: 'SUBSCRIBE_KEY',
updateDelay: 500
},
// Define start sequence.
start: function() {
Log.info('Starting module: Google Assistant Now');
var self = this;
this.assistantActive = false;
this.processing = false;
this.userQuery = null;
//this.sendSocketNotification('INIT', 'handshake');
this.sendSocketNotification('INIT', self.config);
},
getDom: function() {
Log.log('Updating DOM for GA');
var wrapper = document.createElement("div");
if (this.assistantActive == true) {
if (this.processing == true) {
wrapper.innerHTML = "<img src='MMM-GoogleAssistant/assistant_active.png'></img><br/>" + this.userQuery;
} else {
wrapper.innerHTML = "<img src='MMM-GoogleAssistant/assistant_active.png'></img>";
}
} else {
wrapper.innerHTML = "<img src='MMM-GoogleAssistant/assistant_inactive.png'></img>";
}
return wrapper;
},
socketNotificationReceived: function(notification, payload) {
var self = this;
delay = self.config.updateDelay;
if (notification == 'ON_CONVERSATION_TURN_STARTED') {
this.assistantActive = true;
delay = 0;
} else if (notification == 'ON_CONVERSATION_TURN_FINISHED') {
this.assistantActive = false;
this.processing = false;
} else if (notification == 'ON_RECOGNIZING_SPEECH_FINISHED') {
this.userQuery = payload;
this.processing = true;
delay = 0;
}
this.updateDom(delay);
},
});