perwendel / spark-kotlin

A Spark DSL in idiomatic kotlin // dependency: com.sparkjava:spark-kotlin:1.0.0-alpha
Apache License 2.0
988 stars 43 forks source link

WebSocket API #17

Open 0x41111111 opened 7 years ago

0x41111111 commented 7 years ago

This PR adds support for mounting WebSocket handler classes on URLs.

The API call essentially mirrors its Java counterpart. It takes a URL and a class containing WebSocket handler methods.

In addition, webSocketIdleTimeoutMillis has also been implemented, which, like webSocket, works exactly like the Java version.

The examples under src/test/ have been updated and a sample handler class has been added.

Usage:

// Attach a WebSocket handler to a Spark instance
val http = ignite()
http.webSocket("/ws", MyTotallyImplementedWebSocketHandler::class)
// Make connections time out after 30 seconds with no activity
http.webSocketIdleTimeoutMillis(30000)

// Attach a WebSocket handler to a static Spark environment
webSocket("/ws", MyTotallyImplementedWebSocketHandler::class)
// Set the inactivity timeout to 30 seconds
webSocketIdleTimeoutMillis(30000)

Related to #11.