As you've noticed, GroupKit automatically takes care of users joining and leaving conferences, without your intervention. However, its often useful to be notified when people come and go. To do this, GroupKit provides a set of three conference events.
Conference events are similar to bindings that you can attach to widgets. But rather than executing a piece of callback code when something happens to a widget (e.g. the user presses a button), conference events execute a piece of code you provide as users join and leave the conference.
To specify handlers for conference events, you use the "gk::event bind" command, which works very similarly to Tk's bind command, right down to its use of "percent substitutions" to pass event parameters to your callback code. The general format of the command is:
gk::event bind event-type callback-code
gk::event bind newUserArrived { set newuser %U set name [gk::users get $newuser.username] toplevel .new$newuser pack [label .new$newuser.lbl -text "$name just arrived."] pack [button .new$newuser.ok -text Ok -command "destroy .new$newuser"] }
gk::event bind userDeleted { catch { .notepad itemconfig user%U -fill black } }
Figure XX. Updating latecomers.
This information is normally sent via the "gk::to user" RPC, described earlier. This call needs the user number to send the message to, again extracted from the event via the "%U" substitution.
gk::event bind updateEntrant { foreach item [.notepad find all] set x [lindex [.notepad coords $item] 0] set y [lindex [.notepad coords $item] 1] foreach tag [.notepad gettags $item] { if {[string range $tag 0 3]=="user"} { set usernum [string range $tag 4 end] } else { if {$tag!="selected"} {set id $tag} } } set idea [.notepad itemcget $item -text] gk::to %U doAddIdea $id $usernum $x $y $idea } }The updateEntrant event is also used to make conferences persist (that is, make them stick around after the last user has left, so that they can be rejoined later). You've noticed that when you quit the last program in the conference, you're asked if you'd like to delete the conference or have it save its contents (persist). If you ask it to persist, GroupKit sends an updateEntrant event to your program, but rather than asking it (via the %U parameter) to update a new user, GroupKit passes a special user number that causes your program to send messages to a special persistence server that records them. When a user next joins the conference, the messages stored in the server are played back, exactly as if they were sent from the last user.
It is also possible to create your own events, specific to your application. This can be useful as your programs get large, as a way of communicating changes between different parts of your program. See the gk::event and gk::notifier pages in the reference manual for more information.