Django Channels: delayed group message

342 views Asked by At

I'm writing multiplayer online browser game and have some trouble now

My consumer:

@channel_session
def tankAction(message):
    user = message.channel_session.session_key
    room = message.channel_session['room']
    data = json.loads(rdb.get('battle-'+room))
    recieve_data = json.loads(message.content['text'])

    if recieve_data['action'] == 'tankDestroyed':
        for tank in data['tanks']:
            if tank['id'] != recieve_data['data']:
                tank['score'] += 1

        Group('battle-%s' % room).send({
            'text': json.dumps({
                'action': 'setScore',
                'tanks': data['tanks']
            })
        })

        data = json.dumps(data)
        rdb.set('battle-' + room, data)

        p = Process(target=startGame, args=(room, ))
        p.start()

and function:

def startGame(room):
    sleep(3)
    Group('battle-%s' % room).send({
            'text': json.dumps({
                'action': 'respawn',
            })
    })
    print ('battle-%s' % room +' respawn')

But there isn't any message from server on client-side. With Django Channels.delay i don't know how to release it. I've combined in one consumer message.send and group.send - all work fine, but this thing doesn't want to do it.

0

There are 0 answers