Search in sources :

Example 1 with FreeswitchBindingProvider

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : EslMessage(org.freeswitch.esl.client.transport.message.EslMessage) FreeswitchBindingProvider(org.openhab.binding.freeswitch.FreeswitchBindingProvider) ConfigurationException(org.osgi.service.cm.ConfigurationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with FreeswitchBindingProvider

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);
                }
            }
        }
    }
}
Also used : CallType(org.openhab.library.tel.types.CallType) FreeswitchBindingProvider(org.openhab.binding.freeswitch.FreeswitchBindingProvider)

Aggregations

FreeswitchBindingProvider (org.openhab.binding.freeswitch.FreeswitchBindingProvider)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 EslMessage (org.freeswitch.esl.client.transport.message.EslMessage)1 CallType (org.openhab.library.tel.types.CallType)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1