Skip to content

Commit

Permalink
Add spotless (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidliu authored Jan 9, 2024
1 parent ac08f1f commit 4f656d5
Show file tree
Hide file tree
Showing 23 changed files with 375 additions and 38 deletions.
39 changes: 39 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# https://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
max_line_length = 180

end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{java,kt,kts,scala,rs,xml,kt.spec,kts.spec,gradle,md}]
indent_size = 4

[*.{kt,kts}]
ktlint_code_style = android_studio

# default IntelliJ IDEA style, same as alphabetical, but with "java", "javax", "kotlin" and alias imports in the end of the imports list
ij_kotlin_imports_layout = *, java.**, javax.**, kotlin.**, ^

ktlint_standard = enabled
ktlint_standard_annotation = disabled
ktlint_standard_no-wildcard-imports = disabled

ktlint_standard_trailing-comma-on-call-site = disabled
ij_kotlin_allow_trailing_comma_on_call_site = true
ktlint_standard_trailing-comma-on-declaration-site = disabled
ij_kotlin_allow_trailing_comma = true

ktlint_standard_wrapping = disabled

[*.md]
trim_trailing_whitespace = false
max_line_length = unset

[*.yml]
ij_yaml_spaces_within_brackets = false
3 changes: 2 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions LicenseHeaderFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright $YEAR LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class Main {
public static void main(String[] args) throws IOException {

RoomServiceClient client = RoomServiceClient.create(
"http://example.com",
"http://example.com",
"apiKey",
"secret");

Expand Down Expand Up @@ -97,7 +97,7 @@ System.out.println("New access token: " + token.toJwt())
```

By default, tokens expire 6 hours after generation. You may override this by using `token.setTtl(long millis)`.

<!--BEGIN_REPO_NAV-->
<br/><table>
<thead><tr><th colspan="2">LiveKit Ecosystem</th></tr></thead>
Expand Down
57 changes: 47 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ plugins {
id("org.jetbrains.dokka") version "1.5.0"
id("io.codearte.nexus-staging") version "0.30.0"
id("com.google.protobuf") version "0.8.19"
id("com.diffplug.spotless") version "6.21.0"
}


Expand All @@ -41,18 +42,54 @@ tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

spotless {
// optional: limit format enforcement to just the files changed by this feature branch
ratchetFrom("origin/main")

format("misc") {
// define the files to apply `misc` to
target("*.gradle", "*.md", ".gitignore")

// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
java {
// apply a specific flavor of google-java-format
googleJavaFormat("1.17.0").aosp().reflowLongStrings()
// fix formatting of type annotations
formatAnnotations()
// make sure every file has the following copyright header.
// optionally, Spotless can set copyright years by digging
// through git history (see "license" section below)
licenseHeaderFile(rootProject.file("LicenseHeaderFile.txt"))
removeUnusedImports()
toggleOffOn()
}
kotlin {
target("src/*/java/**/*.kt", "src/*/kotlin/**/*.kt")
ktlint("0.50.0")
.setEditorConfigPath("$rootDir/.editorconfig")
licenseHeaderFile(rootProject.file("LicenseHeaderFile.txt"))
.named("license")
endWithNewline()
toggleOffOn()
}
}

val protoc_platform: String? by project
val protoSrc = arrayOf(
"$projectDir/protocol/livekit_analytics.proto",
"$projectDir/protocol/livekit_egress.proto",
"$projectDir/protocol/livekit_ingress.proto",
"$projectDir/protocol/livekit_internal.proto",
"$projectDir/protocol/livekit_models.proto",
"$projectDir/protocol/livekit_room.proto",
"$projectDir/protocol/livekit_rpc_internal.proto",
"$projectDir/protocol/livekit_rtc.proto",
"$projectDir/protocol/livekit_webhook.proto",
)
"$projectDir/protocol/livekit_analytics.proto",
"$projectDir/protocol/livekit_egress.proto",
"$projectDir/protocol/livekit_ingress.proto",
"$projectDir/protocol/livekit_internal.proto",
"$projectDir/protocol/livekit_models.proto",
"$projectDir/protocol/livekit_room.proto",
"$projectDir/protocol/livekit_rpc_internal.proto",
"$projectDir/protocol/livekit_rtc.proto",
"$projectDir/protocol/livekit_webhook.proto",
)
val protobufVersion = "3.21.7"
val protobufDep = "com.google.protobuf:protobuf-java:$protobufVersion"
protobuf {
Expand Down
2 changes: 1 addition & 1 deletion module.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Module livekit-android-sdk

Server SDK to [LiveKit](https://github.com/livekit/livekit-server).
Server SDK to [LiveKit](https://github.com/livekit/livekit-server).
19 changes: 17 additions & 2 deletions src/main/kotlin/io/livekit/server/AccessToken.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.livekit.server

import com.auth0.jwt.JWT
Expand All @@ -7,7 +23,6 @@ import java.time.Instant
import java.util.*
import java.util.concurrent.TimeUnit


/**
* Access tokens are required to connect to the server.
*
Expand Down Expand Up @@ -145,4 +160,4 @@ internal fun JWTCreator.Builder.withClaimAny(name: String, value: Any) {
withClaim(name, value as Map<String, *>)
}
}
}
}
17 changes: 16 additions & 1 deletion src/main/kotlin/io/livekit/server/EgressService.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.livekit.server

import livekit.LivekitEgress
Expand Down Expand Up @@ -74,5 +90,4 @@ interface EgressService {
@Body request: LivekitEgress.StopEgressRequest,
@Header("Authorization") authorization: String
): Call<LivekitEgress.EgressInfo>

}
17 changes: 16 additions & 1 deletion src/main/kotlin/io/livekit/server/EgressServiceClient.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.livekit.server

import io.livekit.server.retrofit.TransformCall
Expand Down Expand Up @@ -579,7 +595,6 @@ class EgressServiceClient(
@JvmStatic
@JvmOverloads
fun create(host: String, apiKey: String, secret: String, logging: Boolean = false): EgressServiceClient {

val okhttp = with(OkHttpClient.Builder()) {
if (logging) {
val loggingInterceptor = HttpLoggingInterceptor()
Expand Down
19 changes: 16 additions & 3 deletions src/main/kotlin/io/livekit/server/IngressService.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.livekit.server

import livekit.LivekitIngress
Expand Down Expand Up @@ -40,7 +56,4 @@ interface IngressService {
@Body request: LivekitIngress.DeleteIngressRequest,
@Header("Authorization") authorization: String
): Call<LivekitIngress.IngressInfo>

}


19 changes: 16 additions & 3 deletions src/main/kotlin/io/livekit/server/IngressServiceClient.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.livekit.server

import io.livekit.server.retrofit.TransformCall
Expand Down Expand Up @@ -115,7 +131,6 @@ class IngressServiceClient(
return service.updateIngress(request, credentials)
}


/**
* List ingress
* @param roomName when null or empty, list all rooms.
Expand Down Expand Up @@ -164,7 +179,6 @@ class IngressServiceClient(
@JvmStatic
@JvmOverloads
fun create(host: String, apiKey: String, secret: String, logging: Boolean = false): IngressServiceClient {

val okhttp = with(OkHttpClient.Builder()) {
if (logging) {
val loggingInterceptor = HttpLoggingInterceptor()
Expand All @@ -184,5 +198,4 @@ class IngressServiceClient(
return IngressServiceClient(service, apiKey, secret)
}
}

}
19 changes: 17 additions & 2 deletions src/main/kotlin/io/livekit/server/RoomService.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.livekit.server

import livekit.LivekitModels
Expand Down Expand Up @@ -76,5 +92,4 @@ interface RoomService {
@Headers("Content-Type: application/protobuf")
@POST("/twirp/livekit.RoomService/SendData")
fun sendData(@Body request: LivekitRoom.SendDataRequest, @Header("Authorization") authorization: String): Call<Void>

}
}
19 changes: 17 additions & 2 deletions src/main/kotlin/io/livekit/server/RoomServiceClient.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.livekit.server

import com.google.protobuf.ByteString
Expand Down Expand Up @@ -311,7 +327,6 @@ class RoomServiceClient(
logging: Boolean = false,
okHttpConfigurator: Consumer<OkHttpClient.Builder>? = null
): RoomServiceClient {

val okhttp = with(OkHttpClient.Builder()) {
if (logging) {
val loggingInterceptor = HttpLoggingInterceptor()
Expand All @@ -331,4 +346,4 @@ class RoomServiceClient(
return RoomServiceClient(service, apiKey, secret)
}
}
}
}
Loading

0 comments on commit 4f656d5

Please sign in to comment.