Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch SfB meetings by clicking on a link #205

Open
wants to merge 5 commits into
base: launchpad-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/purple/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
92 changes: 92 additions & 0 deletions src/purple/sipe-url-handler
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +48 to +92
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this fiddling with with windows. I guess it will work in your specific use case, however, I feel in its present shape it isn't fit for upstream:

  • The solution is X11-specific, doesn't work with Wayland and never will since these features like sending fake keyboard input to random windows were explicitly removed from Wayland specification for security reasons.
  • It is quite fragile since it relies on things like text in window headers, which is prone to get changed without notice, or getting PID of the pidgin process with pgrep (there may be several instances running at the same time if this is a multi user machine).

IMO anyone willing to implement this properly should focus on these areas:

  • Service im.pidgin.purple.PurpleService that Pidgin exposes on session DBus should be made activatable, so that we don't have to check if Pidgin is running and possibly launch it manually (line 24) - whenever the service is accessed, DBus should launch Pidgin automatically.

  • SipeJoinConferenceWithUri method should have a boolean parameter (e.g. join_call) that when True, makes Sipe connect to the conference call and screencast automatically, skipping any popup dialogs user would have to confirm.

  • Optionally, Pidgin could expose PurpleConversationSetFocus method on DBus that would bring the chat window with the given conversation to front, replacing xdotool windowactivate.

8 changes: 8 additions & 0 deletions src/purple/sipe-url-handler.desktop
Original file line number Diff line number Diff line change
@@ -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