-
Notifications
You must be signed in to change notification settings - Fork 1
/
remote-process.js
96 lines (82 loc) · 1.98 KB
/
remote-process.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
/*
This is an example of a remote process client
that interacts with a valid AI Service.
Concretely, this is how Teacher Moment's DCSS
application server will interact with third
party services.
*/
const {
performance
} = require('perf_hooks');
const io = require('socket.io-client');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: '> '
});
// The developer token
const token = '8070cb2467d22a15dabafd5f5128cacc04af86f1';
const transports = ['websocket'];
const PORT = process.env.PORT || 4000;
const endpoint = process.env.NODE_ENV && process.env.NODE_ENV === 'production'
? 'ws://dcss-caa-production.herokuapp.com'
: `http://localhost:${PORT}`;
const agent = {
id: 1,
name: 'Confusion Analysis Agent',
configuration: {
source: 'cli'
}
};
const chat = {
id: 2
};
const user = {
id: 4,
name: 'Remote Process User'
};
const auth = {
agent,
chat,
token,
user,
};
const options = {
transports,
auth
};
console.log('endpoint', endpoint);
console.log('options', options);
const socket = io(endpoint, options);
socket.on('response', ({value, result}) => {
console.log(result);
console.log(`The participant's response ${result ? 'did' : 'did not'} sound confused.`);
});
socket.on('interjection', ({message}) => {
console.log(`Agent says: "${message}"`);
});
rl.prompt();
rl.on('line', (line) => {
const value = line.trim();
if (value === 'end') {
socket.emit('end', auth);
return;
}
if (!value) {
// Hit <enter> to execute
socket.emit('request', {
value: 'https://teacher-moments-staging.herokuapp.com/api/media/audio/2660/466c0c30-bd69-4a35-9dd3-b04bbdcf02b5/380/0ec33c6c-9102-4206-bc35-d6e06a85fcb7.mp3'
});
} else {
// If value is not "end", assume its a url
socket.emit('request', {
value
});
}
console.log(`Processing audio...`);
rl.prompt();
}).on('close', () => {
console.log('Goodbye!');
process.exit(0);
});