https://s3-us-west-2.amazonaws.com/secure.notion-static.com/7dd57e6e-8982-4007-ae05-19bd905e5755/Untitled.png

var stompClient = null;
var isConnected = false;

function connect() {
	if (isConnected) {
		return;
	}
	/* 웹소켓 호환제안*/
	if (!('WebSocket' in window || 'MozWebSocket' in window)) {
		alert("지원되지 않습니다.");
		return;
	}

    var socket = new SockJS("<https://www.itlo.org/message>");
    stompClient = Stomp.over(socket);
      stompClient.debug = null;   
    stompClient.connect({}, function (frame) {
        setConnected(true);
        isConnected = true;
        stompClient.subscribe('/user/58038/notify', onMessage);
          stompClient.subscribe('/subscribe/notice', pingpong); 
          var tx = stompClient.begin();
          // console.log(tx);
    });
}
function setConnected(connected) {
	 
	 if (connected) {
         $("#nonread").show();
        
     }
     else {
         $("#nonread").hide();
         
     }
	 
	 
}
function onMessage(message){
	 
	 
	 var alertnum=JSON.parse(message.body);
	 var alertnumber=alertnum.num;
	 alertnumber*+1;
	 if(alertnum.type == 'alertnum'){
		 $("#nonread").html(alertnum.num); 
		 
		if(alertnumber>=1){
		 
			 $("#iconmovecss").addClass("faa-ring animated");
			 
		/* 	 $("#msgresponId").fadeIn();
			 $("#msgresponId").fadeOut(2500); */
		}else{
			$("#iconmovecss").removeClass("faa-ring animated");
		}
		 
		  
		  
			}
	
	
	
	}
function pingpong(message){
	
	 var pingdata=JSON.parse(message.body);
	if(pingdata.type == 'ping'){
		
		var link = document.location.href;
 
	stompClient.send("/app/echo",{}, JSON.stringify({'type':'pong','id':'58038','link':link}));
	}
	
	
	
	
	
	if(pingdata.type == 'bookon'){
	alertify.set('notifier','position', 'top-right');
    alertify.set('notifier','delay', 0);
    alertify.notify('도서:"'+pingdata.title+'" 가 등록 되었습니다.'); 
	}
	
	}
connect();