-
Notifications
You must be signed in to change notification settings - Fork 0
/
emotion.js
61 lines (48 loc) · 1.39 KB
/
emotion.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
class RTAWEmotion {
#socket = null;
#data = {};
#isblock = false;
currentemote = '';
currentstr = '';
currenteadjust = {};
isstart = false;
constructor() { }
start = (key, adjustdata) => {
const self = this;
self.#data = adjustdata;
self.isstart = true;
// 接続
self.#socket = new WebSocket(`wss://cloud.achex.ca/rtaw${key}`);
// ソケットが開いたら認証開始
self.#socket.addEventListener('open', function (event) {
self.#socket.send(`{ "auth": "${key}" }`);
});
// 表情データ受信処理
self.#socket.addEventListener('message', function (event) {
const msg = JSON.parse(event.data);
console.log('[Message] ', msg);
if (self.#isblock || !msg['emotion']) {
return;
}
self.currentemote = msg['emotion'] || 'neutral';
self.currentstr = msg['strength'] || 0;
self.currenteadjust = self.#data[self.currentemote];
});
};
blocking = (isblock) => {
const self = this;
self.#isblock = isblock;
};
getPrefix = () => {
const self = this;
return self.currenteadjust['prefix'] || '';
};
getAdjustPitch = () => {
const self = this;
return self.currenteadjust['pitch'] || 0;
};
getAdjustRate = () => {
const self = this;
return self.currenteadjust['rate'] || 0;
};
};