#!/bin/sh
#
#  Immediately disconnects from current node/reflector
#  and connects back to the calling node.
#
########################################################
#
#  enlist some help
source /home/irlp/custom/my-functions.sh

if [ -a $LOCAL/call_waiting ]; then
        the_node=`ls $LOCAL/call_waiting | tail -n 1`
else
        the_node=""
fi
if [[ "$the_node" != "" && -f "$LOCAL"/active ]]; then
        if "$SCRIPT"/end; then
                text_out=""
                "$SCRIPT"/call $the_node &>/dev/null 2>&1
        else
                text_out="Problem encountered while disconnecting.  Resetting the node now."
                "$SCRIPT"/irlp_reset &>/dev/null 2>&1
        fi
else
        text_out="Node not active or no calls are waiting!"
fi
if [ "$text_out" != "" ]; then
	killall ispeaker > /dev/null 2>&1
        my_key
        swift -m text $text_out
        my_unkey
	$SCRIPT/sfswrapper > /dev/null 2>&1
fi
exit 0

