-
Notifications
You must be signed in to change notification settings - Fork 2
/
engineApi.js
73 lines (63 loc) · 2.18 KB
/
engineApi.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
/*
this is the API to be used by the underlying voice/messaging system
public functions throw exceptions when called in a wrong way.
*/
var uuid = require("uuid");
//var appConfig = require("./etc/app.json");
//var addressBook = require("./" + appConfig.addressBook);
var wss = require("./websocket");
var myLib = require("./myLib");
var mixerLib = require("./mixerLib");
var s = require("./localStorage");
//
//voice
//
exports.channelUpdate = function (channel_id, channel) {
if (!myLib.checkObjectProperties(channel)) {
myLib.consoleLog('panic', 'engineApi::channelUpdate', "invalid input", channel);
} else if (mixerLib.channelCreate(channel_id, channel) || mixerLib.channelMode(channel_id, channel) || mixerLib.channelUpdateProperties(channel_id, channel)) {
mixerLib.channelUpdateEvent([channel_id]);
// } else {
// myLib.consoleLog('debug', 'engineApi::channelUpdate', "nothing to do for " + channel_id, channel);
}
};
//
// messagging
//
exports.inboxUpdate = function (data) {
var required = ["type", "timestamp", "endpoint", "content"];
if (!myLib.checkObjectProperties(data, required)) {
myLib.consoleLog('panic', 'engineApi::inboxUpdate', "invalid input", data);
} else {
var key = uuid.v1();
s.messages.save('inbox.' + key, data);
var newMessage = {};
data.id = key;
newMessage[key] = data;
//wss.broadcastEvent("inboxUpdate", newMessage);
wss.broadcastEvent("messages:update", newMessage);
var msgType = data.type.split('_');
myLib.jsonLog({
endpoint: data.endpoint,
channel_id: data.channel_id,
type: msgType[0],
direction: msgType[1]
}, ["telegraf"], ["inbox"], { message: { value: 1 }}, data.content);
}
};
exports.callUpdate = function(data) {
let required = ["number", "name", "timestamp", "filename"];
if (!myLib.checkObjectProperties(data, required)) {
myLib.consoleLog('panic', 'engineApi::callUpdate', "invalid input", data);
} else {
data.id = uuid.v1();
s.calls.save(data.id, data);
wss.broadcastEvent("calls:update", { [data.id]: data });
/*let call = Object.assign({}, data);
call.id = uuid.v1();
s.calls.save(call.id, call);
let newCall = {};
newCall[call.id] = call;
wss.broadcastEvent("calls:update", newCall);*/
}
};