正在显示
5 个修改的文件
包含
90 行增加
和
27 行删除
| 1 | -# client-sdk-android | 1 | +# Android Kotlin SDK for LiveKit |
| 2 | 2 | ||
| 3 | -## Setup | 3 | +Official Android Client SDK for [LiveKit](https://github.com/livekit/livekit-server). Easily add video & audio capabilities to your Android apps. |
| 4 | 4 | ||
| 5 | -Requires `protocol` repo to exist at the same level as this repo to generate protobufs correctly. | 5 | +## Docs |
| 6 | 6 | ||
| 7 | -### Optional (Dev convenience) | 7 | +Docs and guides at [https://docs.livekit.io](https://docs.livekit.io) |
| 8 | 8 | ||
| 9 | -1. Download webrtc sources from https://webrtc.googlesource.com/src | ||
| 10 | -2. Add sources to Android Studio by pointing at the `webrtc/sdk/android` folder. | 9 | +## Installation |
| 10 | + | ||
| 11 | +LiveKit for Android is available as a Maven package. | ||
| 12 | + | ||
| 13 | +```groovy title="build.gradle" | ||
| 14 | +... | ||
| 15 | +dependencies { | ||
| 16 | + implementation "io.livekit:livekit-android:<version>" | ||
| 17 | +} | ||
| 18 | +``` | ||
| 19 | + | ||
| 20 | +## Usage | ||
| 21 | + | ||
| 22 | +LiveKit uses WebRTC-provided `org.webrtc.SurfaceViewRenderer` to render video tracks. Subscribed audio tracks are automatically played. | ||
| 23 | + | ||
| 24 | +```kt | ||
| 25 | +class MainActivity : AppCompatActivity(), RoomListener { | ||
| 26 | + override fun onCreate(savedInstanceState: Bundle?) { | ||
| 27 | + super.onCreate(savedInstanceState) | ||
| 28 | + ... | ||
| 29 | + val url = "wss://your_host"; | ||
| 30 | + val token = "your_token" | ||
| 11 | 31 | ||
| 12 | -## Publishing releases | 32 | + launch { |
| 33 | + val room = LiveKit.connect( | ||
| 34 | + applicationContext, | ||
| 35 | + url, | ||
| 36 | + token, | ||
| 37 | + ConnectOptions(), | ||
| 38 | + this | ||
| 39 | + ) | ||
| 40 | + val localParticipant = room.localParticipant | ||
| 41 | + val audioTrack = localParticipant.createAudioTrack() | ||
| 42 | + localParticipant.publishAudioTrack(audioTrack) | ||
| 43 | + val videoTrack = localParticipant.createVideoTrack() | ||
| 44 | + localParticipant.publishVideoTrack(videoTrack) | ||
| 45 | + videoTrack.startCapture() | ||
| 13 | 46 | ||
| 14 | -1. Ensure you have your `.gradle/gradle.properties` filled with the requisite credentials: | 47 | + attachVideo(videoTrack, localParticipant) |
| 48 | + } | ||
| 49 | + } | ||
| 15 | 50 | ||
| 16 | -```` | ||
| 17 | -nexusUsername=<sonatype username> | ||
| 18 | -nexusPassword=<sonatype password> | ||
| 19 | -signing.keyId=<signing key id> | ||
| 20 | -signing.password=<signing key password> | ||
| 21 | -signing.secretKeyRingFile=<signing pgp key path> | ||
| 22 | -```` | 51 | + override fun onTrackSubscribed( |
| 52 | + track: Track, | ||
| 53 | + publication: RemoteTrackPublication, | ||
| 54 | + participant: RemoteParticipant, | ||
| 55 | + room: Room | ||
| 56 | + ) { | ||
| 57 | + if (track is VideoTrack) { | ||
| 58 | + attachVideo(track, participant) | ||
| 59 | + } | ||
| 60 | + } | ||
| 23 | 61 | ||
| 24 | -2. Update `VERSION_NAME` in `gradle.properties` to reflect the release version. (Remove "-SNAPSHOT" when releasing.) | ||
| 25 | -3. Run `gradle publish closeAndReleaseRepository` to upload to maven. | ||
| 26 | -4. Update `VERSION_NAME` in `gradle.properties` to prepare for next release version. | 62 | + private fun attachVideo(videoTrack: VideoTrack, participant: Participant) { |
| 63 | + // viewBinding.renderer is a `org.webrtc.SurfaceViewRenderer` in your | ||
| 64 | + // layout | ||
| 65 | + videoTrack.addRenderer(viewBinding.renderer) | ||
| 66 | + } | ||
| 67 | +} | ||
| 68 | +``` | ||
| 69 | + | ||
| 70 | +## Dev Environment | ||
| 71 | + | ||
| 72 | +To develop the Android SDK itself, you'll need | ||
| 73 | + | ||
| 74 | +- Check out the [protocol](https://github.com/livekit/protocol) repo to exist at the same level as this repo. | ||
| 75 | +- Install [Android Studio Arctic Fox Beta](https://developer.android.com/studio/preview) | ||
| 76 | + | ||
| 77 | +### Optional (Dev convenience) | ||
| 78 | + | ||
| 79 | +1. Download webrtc sources from https://webrtc.googlesource.com/src | ||
| 80 | +2. Add sources to Android Studio by pointing at the `webrtc/sdk/android` folder. |
| @@ -11,7 +11,7 @@ buildscript { | @@ -11,7 +11,7 @@ buildscript { | ||
| 11 | 11 | ||
| 12 | } | 12 | } |
| 13 | dependencies { | 13 | dependencies { |
| 14 | - classpath 'com.android.tools.build:gradle:7.0.0-beta04' | 14 | + classpath 'com.android.tools.build:gradle:7.0.0-beta05' |
| 15 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | 15 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |
| 16 | classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" | 16 | classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" |
| 17 | classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" | 17 | classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" |
release-instructions.md
0 → 100644
| 1 | +## Publishing releases | ||
| 2 | + | ||
| 3 | +1. Ensure you have your `.gradle/gradle.properties` filled with the requisite credentials: | ||
| 4 | + | ||
| 5 | +```` | ||
| 6 | +nexusUsername=<sonatype username> | ||
| 7 | +nexusPassword=<sonatype password> | ||
| 8 | +signing.keyId=<signing key id> | ||
| 9 | +signing.password=<signing key password> | ||
| 10 | +signing.secretKeyRingFile=<signing pgp key path> | ||
| 11 | +```` | ||
| 12 | + | ||
| 13 | +2. Update `VERSION_NAME` in `gradle.properties` to reflect the release version. (Remove "-SNAPSHOT" when releasing.) | ||
| 14 | +3. Run `gradle publish closeAndReleaseRepository` to upload to maven. | ||
| 15 | +4. Update `VERSION_NAME` in `gradle.properties` to prepare for next release version. |
| @@ -108,8 +108,8 @@ class MainActivity : AppCompatActivity() { | @@ -108,8 +108,8 @@ class MainActivity : AppCompatActivity() { | ||
| 108 | const val PREFERENCES_KEY_URL = "url" | 108 | const val PREFERENCES_KEY_URL = "url" |
| 109 | const val PREFERENCES_KEY_TOKEN = "token" | 109 | const val PREFERENCES_KEY_TOKEN = "token" |
| 110 | 110 | ||
| 111 | - const val URL = "ws://192.168.11.5:7880" | 111 | + const val URL = "wss://livekit.watercooler.fm" |
| 112 | const val TOKEN = | 112 | const val TOKEN = |
| 113 | - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTk0NDkwNTMsImlzcyI6IkFQSXdMZWFoN2c0ZnVMWURZQUplYUtzU0UiLCJqdGkiOiJwaG9uZTIiLCJuYmYiOjE2MTY4NTcwNTMsInZpZGVvIjp7InJvb20iOiJteXJvb20iLCJyb29tSm9pbiI6dHJ1ZX19.OiemzgYXe5269q_VDXb912LG3QoqoKy-52-xEWcTr3A" | 113 | + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5ODQyMzE0OTgsImlzcyI6IkFQSU1teGlMOHJxdUt6dFpFb1pKVjlGYiIsImp0aSI6ImZvcnRoIiwibmJmIjoxNjI0MjMxNDk4LCJ2aWRlbyI6eyJyb29tIjoibXlyb29tIiwicm9vbUpvaW4iOnRydWV9fQ.PVx_lXAIGxcD2VRslosrbkigc777GXbu-DQME8hjJKI" |
| 114 | } | 114 | } |
| 115 | } | 115 | } |
-
请 注册 或 登录 后发表评论