@@ -1021,6 +1021,9 @@ <h3>Sign-Up</h3>
10211021 // 노드의 위치를 새로운 좌표로 업데이트
10221022 nodeElement . style . left = `${ nodeData . x } px` ;
10231023 nodeElement . style . top = `${ nodeData . y } px` ;
1024+
1025+ // 선 업데이트
1026+ updateLine ( nodeElement ) ;
10241027 } else {
10251028 console . error ( `Node with ID ${ nodeData . nodeId } not found.` ) ;
10261029 }
@@ -1029,25 +1032,35 @@ <h3>Sign-Up</h3>
10291032 // WebSocket을 통해 마우스 좌표 수신
10301033 stompClient . subscribe ( `/topic/mouse/${ projectId } ` , function ( message ) {
10311034 const mouseData = JSON . parse ( message . body ) ;
1032- const { name, x, y } = mouseData ;
1033-
1034- // 커서 요소가 이미 존재하는지 확인
1035- if ( ! userCursors [ name ] ) {
1036- // 커서 요소 생성
1037- const cursorElement = document . createElement ( 'div' ) ;
1038- cursorElement . className = 'cursor' ;
1039- cursorElement . style . position = 'absolute' ;
1040- cursorElement . innerHTML = `<span>${ name } </span>` ;
1041- document . body . appendChild ( cursorElement ) ;
1042-
1043- // 사용자 커서 저장
1044- userCursors [ name ] = cursorElement ;
1035+
1036+ if ( mouseData . type === "disconnect" ) {
1037+ const { name } = mouseData ; // mouseData에서 name 가져오기
1038+ if ( userCursors [ name ] ) {
1039+ userCursors [ name ] . remove ( ) ; // DOM 요소 삭제
1040+ delete userCursors [ name ] ; // userCursors에서 제거
1041+ }
10451042 }
1043+ else {
1044+ const { name, x, y } = mouseData ;
1045+
1046+ // 커서 요소가 이미 존재하는지 확인
1047+ if ( ! userCursors [ name ] ) {
1048+ // 커서 요소 생성
1049+ const cursorElement = document . createElement ( 'div' ) ;
1050+ cursorElement . className = 'cursor' ;
1051+ cursorElement . style . position = 'absolute' ;
1052+ cursorElement . innerHTML = `<span>${ name } </span>` ;
1053+ document . body . appendChild ( cursorElement ) ;
1054+
1055+ // 사용자 커서 저장
1056+ userCursors [ name ] = cursorElement ;
1057+ }
10461058
1047- // 커서 위치 업데이트
1048- const cursorElement = userCursors [ name ] ;
1049- cursorElement . style . left = `${ x } px` ;
1050- cursorElement . style . top = `${ y } px` ;
1059+ // 커서 위치 업데이트
1060+ const cursorElement = userCursors [ name ] ;
1061+ cursorElement . style . left = `${ x } px` ;
1062+ cursorElement . style . top = `${ y } px` ;
1063+ }
10511064 } ) ;
10521065
10531066 // 노드 삭제 이벤트 구독
@@ -1063,7 +1076,10 @@ <h3>Sign-Up</h3>
10631076 }
10641077
10651078 if ( document . getElementById ( `node-${ nodeID } ` ) ) {
1066- deleteNode ( nodeID ) ; // 해당 노드를 삭제하는 함수 호출
1079+ document . getElementById ( `node-${ nodeID } ` ) ?. remove ( ) ;
1080+ document . getElementById ( `path-${ nodeID } ` ) ?. remove ( ) ;
1081+ upadteNodeCheck ( ) ;
1082+ console . log ( "Node deleted successfully." ) ;
10671083 }
10681084 } ) ;
10691085
@@ -1076,12 +1092,44 @@ <h3>Sign-Up</h3>
10761092 const mouseData = {
10771093 name : currentUserName , // 사용자 이름 추가
10781094 x : event . clientX + window . scrollX ,
1079- y : event . clientY + window . scrollY
1095+ y : event . clientY + window . scrollY ,
1096+ type : "connect"
10801097 } ;
10811098 stompClient . send ( `/app/mouse/${ CurrentProjectId } ` , { } , JSON . stringify ( mouseData ) ) ;
10821099 }
10831100 } ) ;
10841101
1102+ document . addEventListener ( "visibilitychange" , function ( ) {
1103+ if ( document . visibilityState === "hidden" ) {
1104+ // 사용자가 페이지를 벗어남
1105+ const mouseData = {
1106+ type : "disconnect" ,
1107+ name : currentUserName ,
1108+ projectId : CurrentProjectId ,
1109+ } ;
1110+ stompClient . send ( `/app/mouse/${ CurrentProjectId } ` , { } , JSON . stringify ( mouseData ) ) ;
1111+ } else if ( document . visibilityState === "visible" ) {
1112+ // 사용자가 페이지로 돌아옴
1113+ const mouseData = {
1114+ type : "connect" , // 재접속 메시지
1115+ name : currentUserName ,
1116+ x : window . scrollX ,
1117+ y : window . scrollY ,
1118+ projectId : CurrentProjectId ,
1119+ } ;
1120+ stompClient . send ( `/app/mouse/${ CurrentProjectId } ` , { } , JSON . stringify ( mouseData ) ) ;
1121+ }
1122+ } ) ;
1123+
1124+ window . addEventListener ( "beforeunload" , function ( ) {
1125+ const mouseData = {
1126+ type : "disconnect" ,
1127+ name : currentUserName ,
1128+ projectId : CurrentProjectId ,
1129+ } ;
1130+ stompClient . send ( `/app/mouse/${ CurrentProjectId } ` , { } , JSON . stringify ( mouseData ) ) ;
1131+ } ) ;
1132+
10851133 //드래그 가능한 기능을 추가하는 함수 - nodeForm에 대해 적용되어있음
10861134 function makeDraggable ( element ) {
10871135 let offsetX , offsetY ;
0 commit comments