@@ -77,18 +77,19 @@ def on_create_room(data):
7777 print (session )
7878
7979 # Spring 로직 추가 => 방 생성
80- create_room_request (data , request .sid )
80+ response = create_room_request (data , request .sid )
8181 print ("방 생성됨!!!!!!!!!!!!!!!!!" )
8282
8383 emit ("join-request" )
8484
8585 # elasticsearch
86- user_nickname = data ["userNickname" ]
87- room_id = data ["roomName" ]
88- date = datetime .datetime .now ()
89- now = date .strftime ('%m/%d/%y %H:%M:%S' )
90- doc_create = {"des" : "create room" , "room_id" : room_id , "user_nickname" : user_nickname , "@timestamp" : utc_time ()}
91- es .index (index = index_name , doc_type = "log" , body = doc_create )
86+ users_in_room = response .json ()
87+
88+ if len (users_in_room ) == 1 :
89+ room_id = data ["roomName" ]
90+ doc_create = {"des" : "create room" , "room_id" : room_id , "@timestamp" : utc_time ()}
91+ es .index (index = index_name , doc_type = "log" , body = doc_create )
92+
9293
9394@socketio .on ("join-room" )
9495def on_join_room (data ):
@@ -114,12 +115,10 @@ def on_join_room(data):
114115 print ("[{}] New member joined: {}<{}>" .format (room_id , display_name , sid ))
115116
116117 ### elasticsearch
117- user_nickname = data ["userNickname" ]
118- date = datetime .datetime .now ()
119- now = date .strftime ('%m/%d/%y %H:%M:%S' )
120- doc_join = {"des" : "New member joined" , "room_id" : room_id , "sid" : sid , "user_nickname" :user_nickname , "@timestamp" : utc_time ()}
121- es .index (index = index_name , doc_type = "log" , body = doc_join )
122- emit ("user-connect" , {"sid" : sid , "name" : display_name }, broadcast = True , include_self = False , room = room_id )
118+ if len (users_in_room ) > 1 :
119+ doc_join = {"des" : "New member joined" , "room_id" : room_id , "sid" : sid , "@timestamp" : utc_time ()}
120+ es .index (index = index_name , doc_type = "log" , body = doc_join )
121+ emit ("user-connect" , {"sid" : sid , "name" : display_name }, broadcast = True , include_self = False , room = room_id )
123122
124123 message = {
125124 "sid" : sid ,
@@ -157,7 +156,7 @@ def on_join_room(data):
157156 print (key )
158157 print (users_in_room [key ])
159158 if users_in_room [key ] is display_name :
160- del usrlist [key ]
159+ del users_in_room [key ]
161160 emit ("user-list" , {"list" : usrlist , "my_id" : sid })
162161
163162 # print("\n users: ", users_in_room, "\n")
@@ -169,11 +168,10 @@ def on_disconnect():
169168 room_id = rooms_sid [sid ]
170169 display_name = names_sid [sid ]
171170
172- ### elasticsearch
173- user_nickname = display_name
171+ ### elk
174172 now = datetime .datetime .now ()
175173 now = now .strftime ('%m/%d/%y %H:%M:%S' )
176- doc_disconnect = {"des" : "user-disconnect" , "room_id" : room_id , "sid" : sid , "user_nickname" : user_nickname , " @timestamp" : utc_time ()}
174+ doc_disconnect = {"des" : "user-disconnect" , "room_id" : room_id , "sid" : sid , "@timestamp" : utc_time ()}
177175 es .index (index = index_name , doc_type = "log" , body = doc_disconnect )
178176
179177 print ("[{}] Member left: {}<{}>" .format (room_id , display_name , sid ))
@@ -219,17 +217,16 @@ def send_message(message):
219217 text = message ["text" ]
220218 room_id = message ["room_id" ]
221219
222- ### elasticsearch
220+ ### elk
223221
224222 # date = datetime.datetime.now()
225223 # now = date.strftime('%m/%d/%y %H:%M:%S')
226224 # doc_chatting= {"des" : "chatting", "room_id" : room_id, "chatting message" : text,"@timestamp": utc_time()}
227225 # es.index(index=index_name, doc_type="log", body=doc_chatting)
228-
229- user_nickname = message ["sender" ]
226+
230227 date = datetime .datetime .now ()
231228 now = date .strftime ('%m/%d/%y %H:%M:%S' )
232- doc_chatting = {"des" : "chatting" , "room_id" : room_id , "user_nickname" : user_nickname , " chatting message" : text , "@timestamp" : utc_time ()}
229+ doc_chatting = {"des" : "chatting" , "room_id" : room_id , "chatting message" : text , "@timestamp" : utc_time ()}
233230 es .index (index = index_name , doc_type = "log" , body = doc_chatting )
234231
235232 data = {
0 commit comments