Пример #1
0
def send_user_state(user: User):
    sip_account = SipState.objects.filter(username=user.username).first()
    if sip_account:
        Group(user.username).send(
            {'text': json.dumps({'state': sip_account.last_state})})
    else:
        Group(user.username).send({'text': json.dumps({'state': 'N/A'})})
Пример #2
0
def kri_message(message):
    data = json.loads(message.content['text'])

    user = message.user
    room = Room.objects.get(pk=data['room_id'])

    if data['text'].isupper():
        screaming = True
    else:
        screaming = False


    msg = Message(
        sender=user,
        room=room,
        text=data['text'],
        is_loud=screaming
    )
    
    msg.save()


    Group('chat').send({'text': json.dumps({'message': data['text'],
    										'sender': user.username,
    										'screaming': screaming})})
Пример #3
0
def ws_name(name):
    Group('chat').send({
        'text':
        json.dumps({
            'name': name.content['text'],
            'sender': name.reply_channel.name
        })
    })
Пример #4
0
def ws_message(message):
    Group('chat').send({
        'text':
        json.dumps({
            'message': message.content['text'],
            'sender': message.reply_channel.name
        })
    })
Пример #5
0
def kri_message(message):
    Group('chat').send({
        'text':
        json.dumps({
            'message': message.content['text'],
            'sender': message.user.username
        })
    })
    def send_messages(self, instance, group_names, action, **kwargs):
        """
        """
        if not group_names:
            return  # no need to serialize, bail.
        self.signal_kwargs = kwargs
        payload = self.serialize(instance, action)
        if payload == {}:
            return  # nothing to send, bail.

        payload['data'] = 'Your assignment has been graded.'

        assert self.stream is not None
        message = self.encode(self.stream, payload)
        for group_name in group_names:
            group = Group(group_name)
            group.send(message)
Пример #7
0
def callback(sender, **kwargs):
    toppings = kwargs['toppings']
    jo = json.loads(toppings)
    data = jo['data']
    for item in data:
        item_id = item['itemid']
        if item_id == 23314:
            print(item)
        Group(str(item_id)).send({'text': json.dumps(item)})
Пример #8
0
 def test_party_member_joined(self):
     test_channel = 'test-channel'
     Group(PartyConsumer.LOBBY_GROUP.format(self.party.pk)).add(test_channel)
     PartyConsumer.party_member_joined(party_member=self.party_member)
     result = self.get_next_message(test_channel, require=True)
     self.assertEqual(
         json.loads(result.content['text']),
         {
             'party_member': model_to_dict(self.party_member),
             'action': PartyConsumer.PARTY_MEMBER_JOINED,
         }
     )
Пример #9
0
 def receive_helo(self, content, multiplexer, user, tenant, **kwargs):
     client = content["request"]["client"]
     client_id = client["id"] if client else uuid.uuid4().hex
     client_reply_channel = client["reply_channel"] if client else None
     if client_reply_channel and (client_reply_channel !=
                                  self.message.reply_channel.name):
         for group in self.connection_groups(**kwargs):
             Group(group, channel_layer=self.message.channel_layer).discard(
                 client_reply_channel)
     return {
         "status": status.STATUS_200_OK,
         "response": {
             "target": "client:*",
             "client": {
                 "id": client_id,
                 "reply_channel": self.message.reply_channel.name
             }
         }
     }
Пример #10
0
def chat_message(message, pk=0):
    data = json.loads(message.content['text'])

    chat = Chat.objects.get(pk=pk)
    print(chat)
    print(chat.pk)

    if data['type'] == 'got_message':
        chat.messages.exclude(author=message.user).update(is_read=True)
    elif data['type'] == 'message':
        ChatMessage.objects.create(chat=chat,
                                   text=escape(data['text']),
                                   author=message.user)
        serializer = UserSerializer(message.user)
        sender = serializer.data
        Group('chat-{}'.format(pk)).send(
            {'text': json.dumps({
                'message': data['text'],
                'sender': sender
            })})
Пример #11
0
def ws_connect(message):
    Group('test').add(message.reply_channel)
    message.reply_channel.send({"accept": True, "text": "İşlem Başarılı."})
Пример #12
0
def kri_connect(message):
    Group('chat').add(message.reply_channel)
    message.reply_channel.send({"accept": True})
Пример #13
0
def ws_disconnect(message):
    Group('test').discard(message.reply_channel)
    Group('test').send({
        "close": True,
    })
Пример #14
0
def ws_connect(message):
    Group('chat').add(message.reply_channel)
Пример #15
0
def state_changed(sender: ModelBase, instance: SipState, **kwargs):
    Group(str(instance.username)).send(
        {'text': json.dumps({'state': instance.last_state})})
Пример #16
0
def ws_disconnect(message):
    item_id = message.content['path'].strip("/")
    Group(str(item_id)).discard(message.reply_channel)
Пример #17
0
def ws_disconnect(message):
    Group('all').discard(message.reply_channel)
Пример #18
0
def ws_connect(message):
    obj = {'type': 'CONNECT_HANDSHAKE'}
    message.reply_channel.send({'text': json.dumps(obj)})
    Group('all').add(message.reply_channel)
Пример #19
0
def send_object(obj):
    if COMMON_APP_CONFIG['web_sockets']:
        Group('all').send({'text': json.dumps(obj)})
Пример #20
0
def ws_connect(message):
    message.reply_channel.send({"accept": True})
    Group(message.user.username).add(message.reply_channel)
    send_user_state(message.user)
Пример #21
0
def chat_connect(message, pk=0):
    message.reply_channel.send({"accept": True})
    Group('chat-{}'.format(pk)).add(message.reply_channel)
Пример #22
0
def ws_connect(message):
	Group('chat').add(message.reply_channel)
	Group('chat').send({'text':'You connect'})
Пример #23
0
def kri_disconnect(message):
    Group('chat').discard(message.reply_channel)
Пример #24
0
def ws_connect(message):
    message.reply_channel.send({'accept': True})
    item_id = message.content['path'].strip("/")
    Group(str(item_id)).add(message.reply_channel)
Пример #25
0
def chat_disconnect(message, pk=0):
    Group('chat-{}'.format(pk)).discard(message.reply_channel)
Пример #26
0
def ws_disconnect(message):
    Group(message.user.username).discard(message.reply_channel)