forked from kalliope-project/MMM-kalliope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-ovos-wakeword.js
101 lines (82 loc) · 2.42 KB
/
MMM-ovos-wakeword.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
/* global Module */
/* Magic Mirror
* Module: MMM-ovos-wakeword
*
* Fork from https://github.com/kalliope-project/MMM-kalliope
* Modified by Gaëtan Trellu
* MIT Licensed.
*/
// Message structure
class Message {
constructor(text) {
this.text = text;
}
}
Module.register('MMM-ovos-wakeword', {
requiresVersion: '2.12.0',
defaults: {
maxMessages: 5,
title: 'Open Voice OS',
image: 'wakeword.png',
width: '100%',
height: '100%',
opacity: 1.0,
apiKey: '',
},
/* Initiate messages list variable.
* This will be the list of messages to display on the screen.
*/
messages: [],
start: function () {
var self = this;
Log.info('Starting module: ' + self.name);
/* sendSocketNotification(notification, payload)
* Send a socket notification to the node helper.
*/
self.sendSocketNotification('INIT', self.config.apiKey);
setInterval(() => {
self.updateDom();
}, 1000);
},
// Override dom generator
getDom: function () {
var self = this;
var wrapper = document.createElement('div');
if (self.messages.length == 0) {
wrapper.innerHTML = '';
return wrapper;
}
var title = document.createElement('div');
var image = document.createElement('img');
image.style.maxWidth = self.config.width;
image.style.maxHeight = self.config.height;
image.style.opacity = self.config.opacity;
image.src = 'modules/' + self.name + '/images/' + self.config.image;
title.className = 'light small dimmed';
title.innerHTML = self.config.title;
wrapper.appendChild(image);
wrapper.appendChild(title);
var table = document.createElement('table');
for (var i = 0; i < self.messages.length; i++) {
var row = document.createElement('tr');
table.appendChild(row);
var messageCell = document.createElement('td');
messageCell.innerHTML = self.messages[i].text;
row.appendChild(messageCell);
}
wrapper.appendChild(table);
return wrapper;
},
socketNotificationReceived: function (notification, payload) {
var self = this;
if (notification == 'OVOS_SEND_MESSAGE') {
var newMessage = new Message(payload);
self.messages.push(newMessage);
while (self.messages.length > self.config.maxMessages) {
self.messages.shift();
}
} else if (notification == 'OVOS_DELETE_MESSAGE') {
self.messages.splice(0, self.messages.length);
}
},
});