Skip to content

Commit a10860a

Browse files
authored
feat: add project to GitHub (#1)
* chore: add demo project * feat: add gradle boilerplate * feat: create WebSocketClient.kt * chore: add .gitignore * chore: add github actions * docs: add README.md * Make gradlew executable
1 parent 8d741e5 commit a10860a

41 files changed

Lines changed: 1554 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "gradle" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "daily"

.github/workflows/build-linux.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Android Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up JDK 17
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: '17'
23+
distribution: 'oracle'
24+
25+
- name: Setup Gradle
26+
uses: gradle/actions/setup-gradle@v5
27+
28+
- name: Build with Gradle
29+
run: ./gradlew compileReleaseKotlinAndroid

.github/workflows/build-mac.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: iOS Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
runs-on: macos-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up JDK 17
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: '17'
23+
distribution: 'oracle'
24+
25+
- name: Setup Gradle
26+
uses: gradle/actions/setup-gradle@v5
27+
28+
- name: Build with Gradle
29+
run: ./gradlew compileKotlinIosSimulatorArm64

.github/workflows/docs.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build docs and push to docs branch
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [ released, prereleased ]
7+
8+
jobs:
9+
build:
10+
name: Compile and Push
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: 'zulu'
21+
java-version: '17'
22+
23+
- name: Setup Gradle
24+
uses: gradle/actions/setup-gradle@v5
25+
26+
- name: Build documentation
27+
run: ./gradlew dokkaHtml --no-configuration-cache
28+
29+
- name: Push to docs branch
30+
uses: peaceiris/actions-gh-pages@v3
31+
with:
32+
github_token: ${{ secrets.GITHUB_TOKEN }}
33+
publish_dir: ./docs
34+
publish_branch: kdocs

.github/workflows/publish.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish to Maven Central
2+
on:
3+
workflow_dispatch:
4+
release:
5+
types: [released, prereleased]
6+
7+
jobs:
8+
publish:
9+
name: Release build and publish
10+
runs-on: macos-latest
11+
steps:
12+
- name: Check out code
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Java
16+
uses: actions/setup-java@v4
17+
with:
18+
distribution: 'zulu'
19+
java-version: 17
20+
21+
- name: Setup Gradle
22+
uses: gradle/actions/setup-gradle@v5
23+
24+
- name: Publish to MavenCentral
25+
run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
26+
env:
27+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
28+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
29+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
30+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
31+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }}

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*.iml
2+
.kotlin
3+
.gradle
4+
**/build/
5+
xcuserdata
6+
!src/**/build/
7+
local.properties
8+
.idea
9+
.DS_Store
10+
captures
11+
.externalNativeBuild
12+
.cxx
13+
*.xcodeproj/*
14+
!*.xcodeproj/project.pbxproj
15+
!*.xcodeproj/xcshareddata/
16+
!*.xcodeproj/project.xcworkspace/
17+
!*.xcworkspace/contents.xcworkspacedata
18+
**/xcshareddata/WorkspaceSettings.xcsettings
19+
node_modules/

README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
1-
# kmp-web-sockets
2-
Kotlin Multiplatform Library for Web Sockets
1+
<img alt="Wannaverse Logo" src="./assets/logo.png" width="288"/>
2+
3+
[![Build iOS](https://github.com/WannaverseOfficial/kmp-web-sockets/actions/workflows/build-mac.yaml/badge.svg)](https://github.com/WannaverseOfficial/kmp-web-sockets/actions)
4+
[![Build Linux](https://github.com/WannaverseOfficial/kmp-web-sockets/actions/workflows/build-linux.yaml/badge.svg)](https://github.com/WannaverseOfficial/kmp-web-sockets/actions)
5+
6+
# Web Socket Client
7+
8+
A Kotlin Multiplatform web socket library for Android, iOS and Desktop.
9+
10+
## ✅ Supported Platform
11+
12+
| Platform | Supported |
13+
|:---------|:----------|
14+
| Android | ✔️ |
15+
| iOS | ✔️ |
16+
| Desktop | ✔️ |
17+
| Web | ❌️ |
18+
19+
## 🚀 Installation
20+
See the releases section of this repository for the latest version.
21+
22+
To your `build.gradle` under `commonMain.dependencies` add:
23+
24+
```kotlin
25+
implementation "com.wannaverse:kmp-web-sockets:<version>"
26+
```
27+
28+
## Usage
29+
30+
[KDocs](https://wannaverseofficial.github.io/kmp-web-sockets/)
31+
32+
Below is a sample code that you may use.
33+
34+
Example `ViewModel`:
35+
```kotlin
36+
class AppViewModel : ViewModel() {
37+
private var wsManager: WebSocketManager? = null
38+
39+
var isLoading = mutableStateOf(false)
40+
var connected = mutableStateOf(false)
41+
val websocketURL = mutableStateOf("wss://ws.ifelse.io")
42+
val messages = mutableStateListOf<String>()
43+
44+
fun connectToServer() = viewModelScope.launch {
45+
isLoading.value = true
46+
47+
if (wsManager == null) {
48+
wsManager = WebSocketManager(websocketURL.value)
49+
wsManager?.incomingMessages?.onEach { message ->
50+
messages.add("Server: $message")
51+
}?.launchIn(viewModelScope)
52+
}
53+
54+
wsManager?.connect()
55+
56+
isLoading.value = false
57+
connected.value = true
58+
}
59+
60+
fun sendMessage(message: String) {
61+
messages.add("You: $message")
62+
wsManager?.send(message)
63+
}
64+
65+
fun disconnect() {
66+
connected.value = false
67+
wsManager?.disconnect()
68+
}
69+
70+
override fun onCleared() {
71+
connected.value = false
72+
super.onCleared()
73+
wsManager?.clear()
74+
}
75+
}
76+
```
77+
78+
## 📄 License
79+
MIT LICENSE. See [LICENSE](./LICENSE) for details.
80+
81+
## 🙌 Contributing
82+
Pull requests and feature requests are welcome!
83+
If you encounter any issues, feel free to open an issue.

assets/logo.png

11.2 KB
Loading

build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
alias(libs.plugins.androidApplication) apply false
3+
alias(libs.plugins.androidLibrary) apply false
4+
alias(libs.plugins.composeMultiplatform) apply false
5+
alias(libs.plugins.composeCompiler) apply false
6+
alias(libs.plugins.kotlinMultiplatform) apply false
7+
}

demo/build.gradle.kts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
3+
4+
plugins {
5+
alias(libs.plugins.kotlinMultiplatform)
6+
alias(libs.plugins.androidApplication)
7+
alias(libs.plugins.composeMultiplatform)
8+
alias(libs.plugins.composeCompiler)
9+
}
10+
11+
kotlin {
12+
androidTarget {
13+
compilerOptions {
14+
jvmTarget.set(JvmTarget.JVM_11)
15+
}
16+
}
17+
18+
listOf(
19+
iosArm64(),
20+
iosSimulatorArm64()
21+
).forEach { iosTarget ->
22+
iosTarget.binaries.framework {
23+
baseName = "ComposeApp"
24+
isStatic = true
25+
}
26+
}
27+
28+
jvm()
29+
30+
sourceSets {
31+
androidMain.dependencies {
32+
implementation(compose.preview)
33+
implementation(libs.androidx.activity.compose)
34+
}
35+
commonMain.dependencies {
36+
implementation(compose.runtime)
37+
implementation(compose.foundation)
38+
implementation(compose.material3)
39+
implementation(compose.ui)
40+
implementation(compose.components.resources)
41+
implementation(compose.components.uiToolingPreview)
42+
implementation(libs.androidx.lifecycle.viewmodelCompose)
43+
44+
implementation(project(":websockets"))
45+
}
46+
jvmMain.dependencies {
47+
implementation(compose.desktop.currentOs)
48+
implementation(libs.kotlinx.coroutinesSwing)
49+
}
50+
}
51+
}
52+
53+
android {
54+
namespace = "com.wannaverse.websocket"
55+
compileSdk = libs.versions.android.compileSdk.get().toInt()
56+
57+
defaultConfig {
58+
applicationId = "com.wannaverse.websocket"
59+
minSdk = libs.versions.android.minSdk.get().toInt()
60+
targetSdk = libs.versions.android.targetSdk.get().toInt()
61+
versionCode = 1
62+
versionName = "1.0"
63+
}
64+
packaging {
65+
resources {
66+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
67+
}
68+
}
69+
buildTypes {
70+
getByName("release") {
71+
isMinifyEnabled = false
72+
}
73+
}
74+
compileOptions {
75+
sourceCompatibility = JavaVersion.VERSION_11
76+
targetCompatibility = JavaVersion.VERSION_11
77+
}
78+
}
79+
80+
dependencies {
81+
debugImplementation(compose.uiTooling)
82+
}
83+
84+
compose.desktop {
85+
application {
86+
mainClass = "com.wannaverse.websocket.MainKt"
87+
88+
nativeDistributions {
89+
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
90+
packageName = "com.wannaverse.websocket"
91+
packageVersion = "1.0.0"
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)