def EventServerClients(rhost, rport, whiteboardBackplane="WHITEBOARD", audioBackplane="AUDIO"): # plug a TCPClient into the backplane loadingmsg = "Fetching sketch from server..." return Graphline( # initial messages sent to the server, and the local whiteboard GETIMG = Pipeline( OneShot(msg=[["GETIMG"]]), tokenlists_to_lines() ), BLACKOUT = OneShot(msg="CLEAR 0 0 0\r\n" "WRITE 100 100 24 255 255 255 "+loadingmsg+"\r\n"), NETWORK = TCPClient(host=rhost,port=rport), APPCOMMS = clientconnector(whiteboardBackplane=whiteboardBackplane, audioBackplane=audioBackplane), linkages = { ("GETIMG", "outbox") : ("NETWORK", "inbox"), # Single shot out ("APPCOMMS", "outbox") : ("NETWORK", "inbox"), # Continuous out ("BLACKOUT", "outbox") : ("APPCOMMS", "inbox"), # Single shot in ("NETWORK", "outbox") : ("APPCOMMS", "inbox"), # Continuous in } )
def clientconnector(whiteboardBackplane="WHITEBOARD", audioBackplane="AUDIO", port=1500): return Pipeline( chunks_to_lines(), lines_to_tokenlists(), Graphline( ROUTER=Router(((lambda T: T[0] == "SOUND"), "audio"), ((lambda T: T[0] != "SOUND"), "whiteboard")), WHITEBOARD=FilteringPubsubBackplane(whiteboardBackplane), AUDIO=Pipeline( SimpleDetupler(1), # remove 'SOUND' tag SpeexDecode(3), FilteringPubsubBackplane(audioBackplane, dontRemoveTag=True), RawAudioMixer(), SpeexEncode(3), Entuple(prefix=["SOUND"], postfix=[]), ), linkages={ # incoming messages go to a router ("", "inbox"): ("ROUTER", "inbox"), # distribute messages to appropriate destinations ("ROUTER", "audio"): ("AUDIO", "inbox"), ("ROUTER", "whiteboard"): ("WHITEBOARD", "inbox"), # aggregate all output ("AUDIO", "outbox"): ("", "outbox"), ("WHITEBOARD", "outbox"): ("", "outbox"), # shutdown routing, not sure if this will actually work, but hey! ("", "control"): ("ROUTER", "control"), ("ROUTER", "signal"): ("AUDIO", "control"), ("AUDIO", "signal"): ("WHITEBOARD", "control"), ("WHITEBOARD", "signal"): ("", "signal"), }, ), tokenlists_to_lines(), )
def clientconnector(whiteboardBackplane="WHITEBOARD", audioBackplane="AUDIO", port=1500): return Pipeline( chunks_to_lines(), lines_to_tokenlists(), Graphline( ROUTER = Router( ((lambda T : T[0]=="SOUND"), "audio"), ((lambda T : T[0]!="SOUND"), "whiteboard"), ), WHITEBOARD = FilteringPubsubBackplane(whiteboardBackplane), AUDIO = Pipeline( SimpleDetupler(1), # remove 'SOUND' tag SpeexDecode(3), FilteringPubsubBackplane(audioBackplane, dontRemoveTag=True), RawAudioMixer(), SpeexEncode(3), Entuple(prefix=["SOUND"],postfix=[]), ), linkages = { # incoming messages go to a router ("", "inbox") : ("ROUTER", "inbox"), # distribute messages to appropriate destinations ("ROUTER", "audio") : ("AUDIO", "inbox"), ("ROUTER", "whiteboard") : ("WHITEBOARD", "inbox"), # aggregate all output ("AUDIO", "outbox") : ("", "outbox"), ("WHITEBOARD", "outbox") : ("", "outbox"), # shutdown routing, not sure if this will actually work, but hey! ("", "control") : ("ROUTER", "control"), ("ROUTER", "signal") : ("AUDIO", "control"), ("AUDIO", "signal") : ("WHITEBOARD", "control"), ("WHITEBOARD", "signal") : ("", "signal") }, ), tokenlists_to_lines(), )
if __name__=="__main__": from Kamaelia.Internet.TCPClient import TCPClient from Kamaelia.File.Reading import PromptedFileReader from Kamaelia.File.Writing import SimpleFileWriter from Kamaelia.Apps.Whiteboard.SingleShot import OneShot try: if "--help" in sys.argv: sys.stderr.write("Usage:\n ./WhiteboardRecorder.py filename host port\n\n") sys.exit(0) filename = sys.argv[1] rhost = sys.argv[2] rport = int(sys.argv[3]) except: sys.stderr.write("Usage:\n ./WhiteboardRecorder.py filename host port\n\n") sys.exit(1) print "Recording..." Pipeline( OneShot(msg=[["GETIMG"]]), tokenlists_to_lines(), TCPClient(host=rhost, port=rport), chunks_to_lines(), Timestamp(), IntersperseNewlines(), SimpleFileWriter(filename), ).run()