diff --git a/src/purple/Makefile.am b/src/purple/Makefile.am index 608a8978f..807191355 100644 --- a/src/purple/Makefile.am +++ b/src/purple/Makefile.am @@ -152,6 +152,11 @@ TESTS = $(check_PROGRAMS) install-exec-local: rm -f $(DESTDIR)$(libdir)/pidgin/libsipe.so +desktopdir = $(datadir)/applications +desktop_DATA = sipe-url-handler.desktop + +bin_SCRIPTS = sipe-url-handler + if SIPE_WITH_APPSTREAM pidginmetainfofiledir = $(datadir)/metainfo pidginmetainfofile_DATA = pidgin-sipe.metainfo.xml diff --git a/src/purple/sipe-url-handler b/src/purple/sipe-url-handler new file mode 100644 index 000000000..4d7519831 --- /dev/null +++ b/src/purple/sipe-url-handler @@ -0,0 +1,92 @@ +#!/bin/bash + +LOG_FILE=/tmp/sipe-uri-handler.log + +log() { + # Debug message if $LOG_FILE exists + if [ -f $LOG_FILE ]; then + echo "$@" >> $LOG_FILE + fi +} + +log "$0 $@" + +# Get meeting URL +MEETURL=$(echo $1 | sed -n 's/^sfb:.*meeturl=\([^&]*\).*/\1/p' | sed 's/_/=/g;s/!/=/g' | base64 -d) +if echo $MEETURL | grep origurl=; then + MEETURL=$(echo ${MEETURL#*origurl=} | sed 's/_/=/g;s/!/=/g' | base64 -d) +fi +log "MEETURL = $MEETURL" + +if [ -n "$MEETURL" ]; then + # Start Pidgin if it is not running + if [ -z "$(pgrep pidgin)" ]; then + pidgin & + # Wait up to 120 seconds for pidgin to start and present a valid ACCOUNT number + SECONDS=0 + while [ $SECONDS -lt 120 ]; do + ACCOUNT=$(purple-remote PurpleAccountsFindConnected?name=\&protocol=prpl-sipe) + if [ -n "$ACCOUNT" ] && [ $ACCOUNT -ne 0 ]; then + break + fi + sleep 1 + done + fi + + # Get SIPE Account number + ACCOUNT=$(purple-remote PurpleAccountsFindConnected?name=\&protocol=prpl-sipe) + log "ACCOUNT = $ACCOUNT" + if [ -z "$ACCOUNT" ] || [ $ACCOUNT -eq 0 ]; then + log "No SfB Account found" + exit 1 + fi + + # Join meeting + purple-remote SipeJoinConferenceWithUri?account=$ACCOUNT\&uri=$MEETURL +fi + +# Close SfB tab in browser +if hash xdotool 2>/dev/null; then + WID=$(xdotool search --name "Skype for Business Web App" | head -1) + if [ -n "$WID" ]; then + xdotool windowactivate --sync $WID + xdotool key --clearmodifiers ctrl+w + fi +fi + +# Make Pidgin chat window active (Skip "Buddy List") +if hash xdotool 2>/dev/null; then + for PIDGIN_PID in $(pgrep pidgin); do + for WID in $(xdotool search --onlyvisible --pid $PIDGIN_PID); do + if [ "$(xdotool getwindowname $WID)" != "Buddy List" ]; then + xdotool windowactivate --sync $WID + fi + done + done +fi + +# Auto join meeting +if hash xdotool 2>/dev/null; then + SECONDS=0 + while [ $SECONDS -lt 120 ]; do + WID=$(xdotool search --name "Office Communicator" | head -1) + if [ -n "$WID" ]; then + xdotool windowactivate --sync $WID + xdotool key --clearmodifiers Return + break + fi + done +fi + +# Auto join shared screen +if hash xdotool 2>/dev/null; then + SECONDS=0 + while [ $SECONDS -lt 30 ]; do + WID=$(xdotool search --name "Office Communicator" | head -1) + if [ -n "$WID" ]; then + xdotool windowactivate --sync $WID + xdotool key --clearmodifiers Return + break + fi + done +fi diff --git a/src/purple/sipe-url-handler.desktop b/src/purple/sipe-url-handler.desktop new file mode 100644 index 000000000..6d01fd623 --- /dev/null +++ b/src/purple/sipe-url-handler.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=Skype for Business conference URL handler +Comment=Start Skype for Bussiness meeting in Pidgin +Exec=/usr/bin/sipe-url-handler %U +MimeType=x-scheme-handler/sfb; +NoDisplay=true +Type=Application +