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'})})
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})})
def ws_name(name): Group('chat').send({ 'text': json.dumps({ 'name': name.content['text'], 'sender': name.reply_channel.name }) })
def ws_message(message): Group('chat').send({ 'text': json.dumps({ 'message': message.content['text'], 'sender': message.reply_channel.name }) })
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)
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)})
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, } )
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 } } }
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 })})
def ws_connect(message): Group('test').add(message.reply_channel) message.reply_channel.send({"accept": True, "text": "İşlem Başarılı."})
def kri_connect(message): Group('chat').add(message.reply_channel) message.reply_channel.send({"accept": True})
def ws_disconnect(message): Group('test').discard(message.reply_channel) Group('test').send({ "close": True, })
def ws_connect(message): Group('chat').add(message.reply_channel)
def state_changed(sender: ModelBase, instance: SipState, **kwargs): Group(str(instance.username)).send( {'text': json.dumps({'state': instance.last_state})})
def ws_disconnect(message): item_id = message.content['path'].strip("/") Group(str(item_id)).discard(message.reply_channel)
def ws_disconnect(message): Group('all').discard(message.reply_channel)
def ws_connect(message): obj = {'type': 'CONNECT_HANDSHAKE'} message.reply_channel.send({'text': json.dumps(obj)}) Group('all').add(message.reply_channel)
def send_object(obj): if COMMON_APP_CONFIG['web_sockets']: Group('all').send({'text': json.dumps(obj)})
def ws_connect(message): message.reply_channel.send({"accept": True}) Group(message.user.username).add(message.reply_channel) send_user_state(message.user)
def chat_connect(message, pk=0): message.reply_channel.send({"accept": True}) Group('chat-{}'.format(pk)).add(message.reply_channel)
def ws_connect(message): Group('chat').add(message.reply_channel) Group('chat').send({'text':'You connect'})
def kri_disconnect(message): Group('chat').discard(message.reply_channel)
def ws_connect(message): message.reply_channel.send({'accept': True}) item_id = message.content['path'].strip("/") Group(str(item_id)).add(message.reply_channel)
def chat_disconnect(message, pk=0): Group('chat-{}'.format(pk)).discard(message.reply_channel)
def ws_disconnect(message): Group(message.user.username).discard(message.reply_channel)