feat: update RTC bot migration and device interaction consumers
All checks were successful
Build and Deploy LTY / build-and-deploy (push) Successful in 9m19s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
pmc 2026-04-10 18:08:05 +08:00
parent 8dcef0cff2
commit 29b4913723
3 changed files with 49 additions and 6 deletions

View File

@ -201,7 +201,11 @@
"Bash(cmd //c \"netstat -ano | findstr LISTENING | findstr /R \\\\\"8000 3000\\\\\"\")",
"Bash(cmd //c \"netstat -ano\")",
"Bash(/c/python/python.exe -m daphne -b 0.0.0.0 -p 8000 qy_lty.asgi:application)",
"Bash(kill %1)"
"Bash(kill %1)",
"Bash(python -c ':*)",
"Bash(xargs ls:*)",
"Bash(find /c/Users/admin/Desktop/Lila-Server -name \"*.py\" -exec grep -l \"connect\\\\|disconnect\\\\|presence\\\\|heartbeat\" {} \\\\;)",
"Bash(grep -E \"\\\\.py$|app$\")"
],
"additionalDirectories": [
"C:\\Users\\admin\\.claude"

View File

@ -3,10 +3,17 @@ from django.db import migrations
def create_rtc_bot(apps, schema_editor):
Bot = apps.get_model('aiapp', 'Bot')
Bot.objects.get_or_create(
name='RTC_Voice_Agent',
defaults={'description': 'RTC实时语音智能体'}
)
if not Bot.objects.filter(name='RTC_Voice_Agent').exists():
# 手动指定一个不会冲突的 id
from django.db import connection
with connection.cursor() as cursor:
cursor.execute("SELECT COALESCE(MAX(id), 0) + 1 FROM aiapp_bot")
next_id = cursor.fetchone()[0]
Bot.objects.create(
id=next_id,
name='RTC_Voice_Agent',
description='RTC实时语音智能体'
)
def remove_rtc_bot(apps, schema_editor):

View File

@ -354,11 +354,26 @@ class DeviceConsumer(AsyncWebsocketConsumer):
'user_id': self.user_id
}
)
await self.send(text_data=json.dumps({
'status': 'success',
'message': '恢复出厂设置指令已发送'
}))
elif message_type == 'device_state':
# 处理手机设备状态消息
await self.channel_layer.group_send(
self.group_name,
{
'type': 'device_state',
'message': message,
'user_id': self.user_id
}
)
await self.send(text_data=json.dumps({
'status': 'success',
'message': '设备状态消息已发送'
}))
else:
# 处理普通文本消息
await self.channel_layer.group_send(
@ -548,6 +563,23 @@ class DeviceConsumer(AsyncWebsocketConsumer):
except Exception as e:
logger.error(f"Error in factory_reset: {str(e)}")
async def device_state(self, event):
"""
处理手机设备状态消息
将设备状态信息转发给 WebSocket
"""
try:
message = event['message']
user_id = event['user_id']
await self.send(text_data=json.dumps({
'type': 'device_state',
'message': message,
'user_id': user_id
}))
except Exception as e:
logger.error(f"Error in device_state: {str(e)}")
async def device_info(self, event):
"""
处理设备信息上报消息