Passing nickname to the server

Once our setup is done, we are able to start the server and see the login page. It's time to pass the nickname or server and enter the chat room.

We have written a function named onLoginButtonClicked(). The body for this function should like this:

    private fun onLoginButtonClicked(): (Event) -> Unit {      return {        if (!nickName.isBlank()) {            val formContainer = document.getElementById("loginDiv") as              HTMLDivElement            formContainer.remove()            callback(nickName)        }      }    }

The preceding function does two special things:

  • Smart casting
  • Registering a simple callback

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.