예제 #1
0
    def on_message(self, message):
        clientdata = json.loads(message)

        print 'clientdata', repr(clientdata)
        
        action = clientdata['action']

        if action == 'updatelocation':
            data = {}
            data['date'] = datetime.datetime.utcnow()
            data['cookie'] = self.id
            data['name'] = self.name
            data['loc'] = clientdata['data']
            rest.postLocation(data)
            livedata = {}
            livedata['action'] = 'liveclients'

            queryList = []
            for client in self.clients:
                queryList.append(client.id)

            livedata['data'] = rest.getLive(queryList)
            
            for client in self.clients:
                client.write_message(livedata)

        elif action == 'setname':
            self.name = clientdata['data']

        elif action == 'postmessagemarker':
            newMessage = clientdata['data']
            rest.postMessageMarker(newMessage)
예제 #2
0
    def open(self):
        self.clients.append(self)
        self.id = cookies.bakeCookie()
        print 'new connection id=', self.id
        livedata = {}
        livedata['action'] = 'liveclients'

        queryList = []
        for client in self.clients:
            queryList.append(client.id)
        livedata['data'] = rest.getLive(queryList, self.id)

        self.write_message(livedata)