Skip to content

Instantly share code, notes, and snippets.

@fedorenkoalex
Created April 3, 2020 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedorenkoalex/1c0455b38b6e3f6da11260c5a27aa884 to your computer and use it in GitHub Desktop.
Save fedorenkoalex/1c0455b38b6e3f6da11260c5a27aa884 to your computer and use it in GitHub Desktop.
Connect Lavarel Echo using Socket.IO
private fun connectEcho() {
val socketIO = IO.socket("http://url:port")
socketIO.open()
socketIO.on(Manager.EVENT_ERROR) {
Log.d("IO.socket", "Error: ${it.toString()}")
}
val auth = JSONObject()
val headers = JSONObject()
headers.put(
"Authentication",
"auth_token"
)
auth.put("headers", headers)
val subscribe = JSONObject()
subscribe.put("channel", "channel_name")
subscribe.put("auth", auth)
socketIO.emit("subscribe", subscribe)
socketIO.on("event_in_channel") {
Log.d("IO.socket", "Received event_in_channel: ${it.toString()}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment