Created
April 3, 2020 12:48
-
-
Save fedorenkoalex/1c0455b38b6e3f6da11260c5a27aa884 to your computer and use it in GitHub Desktop.
Connect Lavarel Echo using Socket.IO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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