Skip to content

Commit

Permalink
Add callback for when student leaves presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
joshterrell805 committed May 21, 2014
1 parent 1842306 commit 13c5067
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
# a connection to a student
class Presenter_ServerOf_Student(BaseConnection):
def __init__(self):
pass
self.__joinCallback = None
self.__leaveCallback = None
self.__joinSuccessResponse = None

def onClose(self, reason):
pass
if self.__joinSuccessResponse != None and self.__leaveCallback != None:
self.__leaveCallback(self.__joinSuccessResponse['username'])

def setCentralClient(self, centralClient):
# the connection to the central client
Expand All @@ -16,6 +19,9 @@ def setCentralClient(self, centralClient):
def setJoinCallback(self, joinCallback):
# called when a new student joins the presentation. username is only param
self.__joinCallback = joinCallback
def setLeaveCallback(self, leaveCallback):
# called when a student leave the presentation. username is only param
self.__leaveCallback = leaveCallback

def onMessage(self, message):
if message['code'] == 'join':
Expand All @@ -28,6 +34,7 @@ def onStudentValidation(response):
'response' : response
})
if response['success']:
self.__joinSuccessResponse = response
self.__joinCallback(response['username'])
else:
self.close()
Expand Down
7 changes: 4 additions & 3 deletions implementation/source/python/model/Connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def tryAuth():

self.__connectCentral(tryAuth, self.__connectCentralFail(callback))

def hostPresentation(self, className, callback, joinCallback):
def hostPresentation(self, className, callback, joinCallback, leaveCallback):
def onHost(response):
if response['success']:
self.__addCallback(callback, [
Expand All @@ -91,7 +91,7 @@ def tryHost():
def doneStarting():
self.__connectCentral(tryHost, self.__connectCentralFail(callback))

self.__startPresentationServer(doneStarting, joinCallback)
self.__startPresentationServer(doneStarting, joinCallback, leaveCallback)

def joinPresentation(self, className, presenterLastName,
presenterFirstName, callback
Expand Down Expand Up @@ -225,7 +225,7 @@ def setPresenter(connection):
else:
callback()

def __startPresentationServer(self, callback, joinCallback):
def __startPresentationServer(self, callback, joinCallback, leaveCallback):
def setPresenter(listeningPort):
if not self.__presenterServer:
self.__presenterServer = listeningPort
Expand All @@ -237,6 +237,7 @@ def onConnection(connection):
self.__presenterServer.connections.append(connection)
connection.setCentralClient(self.__centralClient)
connection.setJoinCallback(joinCallback)
connection.setLeaveCallback(leaveCallback)

if not self.__presenterServer:
Server.listen(
Expand Down
7 changes: 5 additions & 2 deletions implementation/source/python/view/HostPresentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def host(self, event):
selected = EClass.GetInstance().classes[self.list_ctrl.GetFocusedItem()]

EClass.GetInstance().connection.hostPresentation(
selected['name'], self.callback,self.joinCallback
selected['name'], self.callback, self.joinCallback, self.leaveCallback
)

def callback(self, response):
Expand All @@ -58,5 +58,8 @@ def callback(self, response):
self.reasonText.SetLabel(response.reason)

def joinCallback(self, username):
print username + 'joined'
print username + ' joined the presentation!'

def leaveCallback(self, username):
print username + ' left the presentation.'

0 comments on commit 13c5067

Please sign in to comment.