Skip to content

A kotlin multiplatform implementation of a websocket. Supports both iOS, Android & Jvm

License

Notifications You must be signed in to change notification settings

TheArchitect123/TitanSocket

Repository files navigation


A kotlin multiplatform library to manage sockets with support for both iOS & Android


GitHub GitHub

How it works

TitanSocket handles all the websocket connections, ping & pong between the client & server, and the event notifications for when data is received or broadcasted, or any connectivity status changes happen.

To get started, import the library into your project:

implementation("io.github.thearchitect123:titansocket:0.2.7")

To use TitanSocket, generate an instance of your socket, pass the Url + any Post Connection Logic, and subscribe to the states you wish to connect to:

 val socketConnection = TitanSocket("wss://mysupersecret/websocket") {
     subscribeOn(TitanSocketEvents.CONNECTION_OPENED) {}
     subscribeOn(TitanSocketEvents.DISCONNECTION) {}
     subscribeOn(TitanSocketEvents.FAILURE) {}
     subscribeOn(TitanSocketEvents.MESSAGE_BINARY_RECEIVED) {}
     subscribeOn(TitanSocketEvents.MESSAGE_RECEIVED) {}
     subscribeOn(TitanSocketEvents.MESSAGE_SENDING) {}
})

Connect your telemetry Endpoints into TitanSocket to listen to Ping & Pong events.

 val socketConnection = TitanSocket("wss://mysupersecret/websocket") {
     subscribeOn(TitanSocketEvents.CONNECTION_OPENED) {}
     subscribeOn(TitanSocketEvents.DISCONNECTION) {}
     subscribeOn(TitanSocketEvents.FAILURE) {}
     subscribeOn(TitanSocketEvents.MESSAGE_BINARY_RECEIVED) {}
     subscribeOn(TitanSocketEvents.MESSAGE_RECEIVED) {}
     subscribeOn(TitanSocketEvents.MESSAGE_SENDING) {}
}) {
     onReceiveResponseWebSocket() {
        println("RESPONSE $it")
     }
     onSendRequestWebSocket() {
        println("REQUEST $it")
     }
}

After your Socket is configured, startup the connection.

 socketConnection.connectSocket()

Make sure to close your web socket connection after you are done with it to avoid battery issues.

socketConnection.disconnectSocket()

License

This software is licensed under the MIT license. See LICENSE for full disclosure.

About

A kotlin multiplatform implementation of a websocket. Supports both iOS, Android & Jvm

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published