package uk.co.rossbinden.transferencevoid.controller

import com.badlogic.gdx.Gdx
import org.eclipse.jetty.websocket.servlet.WebSocketServlet
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory
import uk.co.rossbinden.transferencevoid.component.SocketComponent
import uk.co.rossbinden.transferencevoid.screen.MainScreen

class ControllerWebSocketServlet: WebSocketServlet() {

    override fun configure(factory: WebSocketServletFactory) {
        factory.policy.idleTimeout = 1800000
        factory.setCreator({ req, resp ->
            val socket = ControllerWebSocket()
            Gdx.app.postRunnable {
                val player = MainScreen.createPlayer()
                player.add(SocketComponent(socket))
                socket.player = player
            }
            return@setCreator socket
        })
    }

}