use of org.openhab.binding.freeswitch.FreeswitchBindingProvider in project openhab1-addons by openhab.
the class FreeswitchBinding method initMessageItems.
/**
* query freeswitch for the message count for VM accounts. This should
* be done every time we connect to the system.
*/
private void initMessageItems() {
mwiCache.clear();
for (FreeswitchBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
FreeswitchBindingConfig config = provider.getFreeswitchBindingConfig(itemName);
if (config.getType() == FreeswitchBindingType.MESSAGE_WAITING) {
String account = config.getArgument();
if (!mwiCache.containsKey(account) && clientValid()) {
EslMessage msg = inboudClient.sendSyncApiCommand("vm_boxcount", account);
if (msg.getBodyLines().size() == 1) {
try {
int messages = Integer.parseInt(msg.getBodyLines().get(0));
mwiCache.put(account, new MWIModel(messages > 0, messages));
updateMessageWaitingItem(config);
} catch (Exception e) {
logger.error("Could not parse messages", e);
}
}
}
}
}
}
}
use of org.openhab.binding.freeswitch.FreeswitchBindingProvider in project openhab1-addons by openhab.
the class FreeswitchBinding method handleNewCallEvent.
/**
* Handle Answer or Media (ringing) events and add an entry to our cache
*
* @param event
*/
private void handleNewCallEvent(EslEvent event) {
String uuid = getHeader(event, UUID);
logger.debug("Adding Call with uuid " + uuid);
Channel channel = new Channel(event);
// we should not get duplicate events, but lets be safe
if (eventCache.containsKey(uuid)) {
return;
}
eventCache.put(uuid, channel);
itemMap.put(uuid, new LinkedList<FreeswitchBindingConfig>());
CallType call = channel.getCall();
logger.debug("new call to : {} from : {}", call.getDestNum(), call.getOrigNum());
for (FreeswitchBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
FreeswitchBindingConfig config = provider.getFreeswitchBindingConfig(itemName);
if (config.getType() == FreeswitchBindingType.ACTIVE) {
/*
* Add the item if it is filtered and matches or if it is
* un-filtered and inbound
*/
if ((config.filtered() && matchCall(channel, config.getArgument())) || (!config.filtered() && isInboundCall(channel))) {
itemMap.get(uuid).add(config);
newCallItemUpdate(config, channel);
}
}
}
}
}
Aggregations