reworking handling finished/missed calls #134
This commit is contained in:
parent
2a07cab638
commit
9a4df9fd28
2 changed files with 55 additions and 40 deletions
|
@ -1,16 +1,17 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
LOGDIR="$XDG_DATA_HOME"/sxmo/modem
|
LOGDIR="$XDG_DATA_HOME"/sxmo/modem
|
||||||
ALSASTATEFILE="/tmp/precall.alsa.state"
|
ALSASTATEFILE="$XDG_CACHE_HOME"/precall.alsa.state
|
||||||
|
CACHEDIR="$XDG_CACHE_HOME"/sxmo
|
||||||
trap "gracefulexit" INT TERM
|
trap "gracefulexit" INT TERM
|
||||||
|
|
||||||
modem_n() {
|
modem_n() {
|
||||||
MODEMS="$(mmcli -L)"
|
MODEMS="$(mmcli -L)"
|
||||||
echo "$MODEMS" | grep -qoE 'Modem\/([0-9]+)' || fatalerr "Couldn't find modem - is your modem enabled?"
|
echo "$MODEMS" | grep -qoE 'Modem\/([0-9]+)' || finish "Couldn't find modem - is your modem enabled?"
|
||||||
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
|
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fatalerr() {
|
finish() {
|
||||||
# E.g. hangup all calls, switch back to default audio, notify user, and die
|
# E.g. hangup all calls, switch back to default audio, notify user, and die
|
||||||
sxmo_vibratepine 1000 &
|
sxmo_vibratepine 1000 &
|
||||||
mmcli -m "$(modem_n)" --voice-hangup-all
|
mmcli -m "$(modem_n)" --voice-hangup-all
|
||||||
|
@ -24,14 +25,18 @@ fatalerr() {
|
||||||
else
|
else
|
||||||
alsactl --file /usr/share/sxmo/alsa/default_alsa_sound.conf restore
|
alsactl --file /usr/share/sxmo/alsa/default_alsa_sound.conf restore
|
||||||
fi
|
fi
|
||||||
echo "$1">&2
|
|
||||||
notify-send "$1"
|
|
||||||
setsid -f sh -c 'sleep 2; sxmo_statusbarupdate.sh'
|
setsid -f sh -c 'sleep 2; sxmo_statusbarupdate.sh'
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
echo "$1">&2
|
||||||
|
notify-send "$1"
|
||||||
|
fi
|
||||||
kill -9 0
|
kill -9 0
|
||||||
|
pkill -9 dmenu #just in case the call menu survived somehow?
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
gracefulexit() {
|
gracefulexit() {
|
||||||
fatalerr "Terminated via SIGTERM/SIGINT"
|
finish "Call ended"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +44,7 @@ modem_cmd_errcheck() {
|
||||||
RES="$(mmcli "$@" 2>&1)"
|
RES="$(mmcli "$@" 2>&1)"
|
||||||
OK="$?"
|
OK="$?"
|
||||||
echo "Command: mmcli $*">&2
|
echo "Command: mmcli $*">&2
|
||||||
if [ "$OK" != 0 ]; then fatalerr "Problem executing mmcli command!\n$RES"; fi
|
if [ "$OK" != 0 ]; then finish "Problem executing mmcli command!\n$RES"; fi
|
||||||
echo "$RES"
|
echo "$RES"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,11 +102,13 @@ acceptcall() {
|
||||||
echo "Invoking pickup hook (async)">&2
|
echo "Invoking pickup hook (async)">&2
|
||||||
"$XDG_CONFIG_HOME/sxmo/hooks/pickup" &
|
"$XDG_CONFIG_HOME/sxmo/hooks/pickup" &
|
||||||
fi
|
fi
|
||||||
|
touch "$CACHEDIR/${CALLID}.pickedupcall" #this signals that we picked this call up
|
||||||
|
#to other asynchronously running processes
|
||||||
modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --accept
|
modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --accept
|
||||||
log_event "call_pickup" "$CALLID"
|
log_event "call_pickup" "$CALLID"
|
||||||
echo "Picked up call $CALLID">&2
|
echo "Picked up call $CALLID">&2
|
||||||
else
|
else
|
||||||
fatalerr "Couldn't initialize call with callid <$CALLID>; unknown direction <$DIRECTION>"
|
finish "Couldn't initialize call with callid <$CALLID>; unknown direction <$DIRECTION>"
|
||||||
fi
|
fi
|
||||||
alsactl --file "$ALSASTATEFILE" store
|
alsactl --file "$ALSASTATEFILE" store
|
||||||
}
|
}
|
||||||
|
@ -143,11 +150,11 @@ incallmonitor() {
|
||||||
while true; do
|
while true; do
|
||||||
sxmo_statusbarupdate.sh
|
sxmo_statusbarupdate.sh
|
||||||
if mmcli -m "$(modem_n)" -K -o "$CALLID" | grep -E "^call.properties.state.+terminated"; then
|
if mmcli -m "$(modem_n)" -K -o "$CALLID" | grep -E "^call.properties.state.+terminated"; then
|
||||||
mmcli -m "$(modem_n)" --voice-delete-call="$CALLID"
|
#note: deletion will be handled asynchronously by sxmo_modemmonitor's checkforfinishedcalls()
|
||||||
if [ "$NUMBER" = "--" ]; then
|
if [ "$NUMBER" = "--" ]; then
|
||||||
fatalerr "Call with unknown number terminated"
|
finish "Call with unknown number terminated"
|
||||||
else
|
else
|
||||||
fatalerr "Call with $NUMBER terminated"
|
finish "Call with $NUMBER terminated"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo "Call still in progress">&2
|
echo "Call still in progress">&2
|
||||||
|
@ -214,5 +221,5 @@ pickup() {
|
||||||
incallmenuloop "$1"
|
incallmenuloop "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
modem_n || fatalerr "Couldn't determine modem number - is modem online?"
|
modem_n || finish "Couldn't determine modem number - is modem online?"
|
||||||
"$@"
|
"$@"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
LOGDIR="$XDG_DATA_HOME"/sxmo/modem
|
LOGDIR="$XDG_DATA_HOME"/sxmo/modem
|
||||||
NOTIFDIR="$XDG_DATA_HOME"/sxmo/notifications
|
NOTIFDIR="$XDG_DATA_HOME"/sxmo/notifications
|
||||||
|
CACHEDIR="$XDG_CACHE_HOME"/sxmo
|
||||||
trap "gracefulexit" INT TERM
|
trap "gracefulexit" INT TERM
|
||||||
|
|
||||||
err() {
|
err() {
|
||||||
|
@ -48,35 +49,41 @@ lookupcontactname() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
checkformissedcalls() {
|
checkforfinishedcalls() {
|
||||||
if pgrep -vf sxmo_modemcall.sh; then
|
#find all finished calls
|
||||||
# Add a notification for every missed call
|
for FINISHEDCALLID in $(
|
||||||
# Note sxmo_modemcall.sh cleanups/delete the callid from the modem; so
|
mmcli -m "$(modem_n)" --voice-list-calls |
|
||||||
# effectivly any incoming call thats terminated here is a missed call!
|
grep incoming |
|
||||||
for MISSEDCALLID in $(
|
grep terminated |
|
||||||
mmcli -m "$(modem_n)" --voice-list-calls |
|
grep -oE "Call\/[0-9]+" |
|
||||||
grep incoming |
|
cut -d'/' -f2
|
||||||
grep terminated |
|
); do
|
||||||
grep -oE "Call\/[0-9]+" |
|
FINISHEDNUMBER="$(lookupnumberfromcallid "$FINISHEDCALLID")"
|
||||||
cut -d'/' -f2
|
mmcli -m "$(modem_n)" --voice-delete-call "$FINISHEDCALLID"
|
||||||
); do
|
rm -f "$NOTIFDIR/incomingcall_${FINISHEDCALLID}_notification"
|
||||||
MISSEDNUMBER="$(lookupnumberfromcallid "$MISSEDCALLID")"
|
|
||||||
mmcli -m "$(modem_n)" --voice-delete-call "$MISSEDCALLID"
|
|
||||||
rm -f "$NOTIFDIR/incomingcall_${MISSEDCALLID}_notification"
|
|
||||||
|
|
||||||
|
TIME="$(date --iso-8601=seconds)"
|
||||||
|
mkdir -p "$LOGDIR"
|
||||||
|
if [ -f "$CACHEDIR/${FINISHEDCALLID}.pickedupcall" ]; then
|
||||||
|
#this call was picked up
|
||||||
|
pkill -f sxmo_modemcall.sh #kill call (softly) in case it is still in progress (remote party hung up)
|
||||||
|
echo "Finished call from $FINISHEDNUMBER">&2
|
||||||
|
rm -f "$CACHEDIR/${FINISHEDCALLID}.pickedupcall"
|
||||||
|
printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$LOGDIR/modemlog.tsv"
|
||||||
|
else
|
||||||
|
#this is a missed call
|
||||||
|
# Add a notification for every missed call
|
||||||
|
echo "Missed call from $FINISHEDNUMBER">&2
|
||||||
|
printf %b "$TIME\tcall_missed\t$FINISHEDNUMBER\n" >> "$LOGDIR/modemlog.tsv"
|
||||||
|
|
||||||
TIME="$(date --iso-8601=seconds)"
|
CONTACT="$(lookupcontactname "$FINISHEDNUMBER")"
|
||||||
mkdir -p "$LOGDIR"
|
|
||||||
printf %b "$TIME\tcall_missed\t$MISSEDNUMBER\n" >> "$LOGDIR/modemlog.tsv"
|
|
||||||
|
|
||||||
CONTACT="$(lookupcontactname "$MISSEDNUMBER")"
|
|
||||||
sxmo_notificationwrite.sh \
|
sxmo_notificationwrite.sh \
|
||||||
random \
|
random \
|
||||||
"st -f Terminus-20 -e sh -c \"echo 'Missed call from $CONTACT at $(date)' && read\"" \
|
"st -f Terminus-20 -e sh -c \"echo 'Missed call from $CONTACT at $(date)' && read\"" \
|
||||||
none \
|
none \
|
||||||
"Missed call - $CONTACT"
|
"Missed call - $CONTACT"
|
||||||
done
|
fi
|
||||||
fi
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
checkforincomingcalls() {
|
checkforincomingcalls() {
|
||||||
|
@ -151,26 +158,26 @@ checkfornewtexts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mainloop() {
|
mainloop() {
|
||||||
checkformissedcalls
|
checkforfinishedcalls
|
||||||
checkforincomingcalls
|
checkforincomingcalls
|
||||||
checkfornewtexts
|
checkfornewtexts
|
||||||
|
|
||||||
# Monitor for incoming calls
|
# Monitor for incoming calls
|
||||||
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'" | \
|
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'" | \
|
||||||
while read -r; do
|
while read -r line; do
|
||||||
checkforincomingcalls
|
checkforincomingcalls
|
||||||
done &
|
done &
|
||||||
|
|
||||||
# Monitor for incoming texts
|
# Monitor for incoming texts
|
||||||
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Messaging',type='signal',member='Added'" | \
|
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Messaging',type='signal',member='Added'" | \
|
||||||
while read -r; do
|
while read -r line; do
|
||||||
checkfornewtexts
|
checkfornewtexts
|
||||||
done &
|
done &
|
||||||
|
|
||||||
# Monitor for missed calls
|
# Monitor for finished calls
|
||||||
dbus-monitor --system "interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Call'" | \
|
dbus-monitor --system "interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Call'" | \
|
||||||
while read -r; do
|
while read -r line; do
|
||||||
checkformissedcalls
|
checkforfinishedcalls
|
||||||
done &
|
done &
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
@ -178,4 +185,5 @@ mainloop() {
|
||||||
wait
|
wait
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rm -f "$CACHEDIR"/*.pickedupcall 2>/dev/null #new session, forget all calls we picked up previously
|
||||||
mainloop
|
mainloop
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue