/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.siso.horario.socket;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

/**
 *
 * @author sistem20user
 */
@ServerEndpoint("/SocketHorario")
public class SocketHorario {

	private static List<Session> listaSesiones = new ArrayList<>();

	@OnOpen
	public void onOpen(Session session) {
		if (!listaSesiones.contains(session)) {
			listaSesiones.add(session);
		}
	}

	@OnMessage
	public String onMessage(String message) throws IOException {		
		if(message.equals("listarVistaDobleWS")){
			for(Session session : listaSesiones){
				session.getBasicRemote().sendText(message);
			}
		}
		return null;
	}
	
	@OnClose
	public void onClose(Session session) {
		if (listaSesiones.contains(session)) {
			listaSesiones.remove(session);
		}
	}

}
