This commit is contained in:
aqu415
2022-03-05 19:24:59 +08:00
parent b1dd73b9a7
commit fe9034f8a1
2 changed files with 17 additions and 7 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ class ChatConsumer(WebsocketConsumer):
def connect(self): def connect(self):
self.room_group_name = 'chat%s' % bytes.decode(self.scope['query_string']) self.room_group_name = 'chat%s' % bytes.decode(self.scope['query_string'])
print(self.room_group_name) # print(self.room_group_name)
# Join room group # Join room group
async_to_sync(self.channel_layer.group_add)( async_to_sync(self.channel_layer.group_add)(
+16 -6
View File
@@ -105,7 +105,7 @@
// //
const resp_data_array = resp.data const resp_data_array = resp.data
resp_data_array.forEach(item => { resp_data_array.forEach(item => {
me._handle_msg_inner(item) me._handle_msg_inner(item, true)
}) })
}) })
}, },
@@ -134,11 +134,11 @@
// 调用jsmind接口 // 调用jsmind接口
_handle_jsmind_with_ws_message: function (message) { _handle_jsmind_with_ws_message: function (message) {
const msg_json = JSON.parse(message) const msg_json = JSON.parse(message)
this._handle_msg_inner(msg_json) this._handle_msg_inner(msg_json, false)
}, },
// 处理消息广告方法 // 处理消息广告方法
_handle_msg_inner(msg_json) { _handle_msg_inner(msg_json, is_batch) {
// 校验 client_id // 校验 client_id
const client_id = msg_json.client_id const client_id = msg_json.client_id
@@ -148,7 +148,13 @@
const log_content = JSON.parse(msg_json.log_content) const log_content = JSON.parse(msg_json.log_content)
const log_id = msg_json.id const log_id = msg_json.id
if (log_id > this.coop_mind_log_id) { if (log_id > this.coop_mind_log_id) {
this.coop_mind_log_last_id = this.coop_mind_log_id // 第一次批量获得日志和被动接收日志,设置coop_mind_log_last_id和coop_mind_log_id 相同,不进行批量保存快照
if (is_batch || client_id !== this.client_id) {
this.coop_mind_log_last_id = log_id
} else {
// 设置 coop_mind_log_last_id 便于批量保存快照
this.coop_mind_log_last_id = this.coop_mind_log_id
}
this.coop_mind_log_id = log_id this.coop_mind_log_id = log_id
} }
@@ -232,8 +238,12 @@
'type': 'snapshot', 'type': 'snapshot',
'data_format': 'node_tree' 'data_format': 'node_tree'
} }
Jm.util.ajax.post(me.coop_api_url, param, function (resp) { // 保存快照,保存完毕后设置 coop_mind_log_last_id 和 coop_mind_log_id
}) if (me.coop_mind_log_id > me.coop_mind_log_last_id) {
Jm.util.ajax.post(me.coop_api_url, param, function (resp) {
me.coop_mind_log_last_id = me.coop_mind_log_id
})
}
}, 10000) }, 10000)
} }
} }