Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

[EX-483] Code cleanups required after library merge #16

Merged
merged 8 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[*.{kt,kts}]
ktlint_code_style = ktlint_official
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_filename = disabled
ktlint_standard_function-naming = disabled
ktlint_standard_property-naming = disabled
ij_kotlin_allow_trailing_comma = false
ij_kotlin_allow_trailing_comma_on_call_site = false
7 changes: 5 additions & 2 deletions .github/workflows/build_lint_test.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change occured?
If it is on GA should it be reflected in project?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just move from using gradlew lintKotlin to ktlint.
I've update README

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ jobs:
java-version: 17
distribution: zulu

- name: Lint
run: ./gradlew lintKotlin
- name: Download ktlint
run: curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.1.1/ktlint && chmod a+x ktlint && sudo mv ktlint /usr/local/bin/

- name: Run linter
run: ktlint **/*.kt

- name: Build
run: ./gradlew assembleRelease
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typealias TrackContext = JellyfishTrackContext

data class Config(
val websocketUrl: String,
val token: String,
val token: String
)

class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
Expand Down Expand Up @@ -73,7 +73,7 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
fun createVideoTrack(
videoParameters: VideoParameters,
metadata: Metadata,
captureDeviceName: String? = null,
captureDeviceName: String? = null
): LocalVideoTrack {
return client.webrtcClient.createVideoTrack(videoParameters, metadata, captureDeviceName)
}
Expand Down Expand Up @@ -105,13 +105,13 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
mediaProjectionPermission: Intent,
videoParameters: VideoParameters,
metadata: Metadata,
onEnd: (() -> Unit)? = null,
): LocalScreencastTrack? {
onEnd: (() -> Unit)? = null
): LocalScreencastTrack {
return client.webrtcClient.createScreencastTrack(
mediaProjectionPermission,
videoParameters,
metadata,
onEnd,
onEnd
)
}

Expand All @@ -135,7 +135,10 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
* @param trackId an id of a remote track
* @param encoding an encoding to receive
*/
fun setTargetTrackEncoding(trackId: String, encoding: TrackEncoding) {
fun setTargetTrackEncoding(
trackId: String,
encoding: TrackEncoding
) {
client.webrtcClient.setTargetTrackEncoding(trackId, encoding)
}

Expand All @@ -145,7 +148,10 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
* @param trackId an id of a local track
* @param encoding an encoding that will be enabled
*/
fun enableTrackEncoding(trackId: String, encoding: TrackEncoding) {
fun enableTrackEncoding(
trackId: String,
encoding: TrackEncoding
) {
client.webrtcClient.enableTrackEncoding(trackId, encoding)
}

Expand All @@ -155,7 +161,10 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
* @param trackId and id of a local track
* @param encoding an encoding that will be disabled
*/
fun disableTrackEncoding(trackId: String, encoding: TrackEncoding) {
fun disableTrackEncoding(
trackId: String,
encoding: TrackEncoding
) {
client.webrtcClient.disableTrackEncoding(trackId, encoding)
}

Expand All @@ -178,7 +187,10 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
* If the metadata is different from what is already tracked in the room, the optional
* callback `onTrackUpdated` will be triggered for other peers in the room.
*/
fun updateTrackMetadata(trackId: String, trackMetadata: Metadata) {
fun updateTrackMetadata(
trackId: String,
trackMetadata: Metadata
) {
client.webrtcClient.updateTrackMetadata(trackId, trackMetadata)
}

Expand All @@ -189,7 +201,10 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
* @param trackId track id of a video track
* @param bandwidthLimit bandwidth in kbps
*/
fun setTrackBandwidth(trackId: String, bandwidthLimit: TrackBandwidthLimit.BandwidthLimit) {
fun setTrackBandwidth(
trackId: String,
bandwidthLimit: TrackBandwidthLimit.BandwidthLimit
) {
client.webrtcClient.setTrackBandwidth(trackId, bandwidthLimit)
}

Expand All @@ -202,7 +217,7 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
fun setEncodingBandwidth(
trackId: String,
encoding: String,
bandwidthLimit: TrackBandwidthLimit.BandwidthLimit,
bandwidthLimit: TrackBandwidthLimit.BandwidthLimit
) {
client.webrtcClient.setEncodingBandwidth(trackId, encoding, bandwidthLimit)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typealias Peer = Endpoint

internal class JellyfishClientInternal(
appContext: Context,
private val listener: JellyfishClientListener,
private val listener: JellyfishClientListener
) :
MembraneRTCListener {
private var webSocket: WebSocket? = null
Expand All @@ -36,42 +36,58 @@ internal class JellyfishClientInternal(

fun connect(config: Config) {
val request = Request.Builder().url(config.websocketUrl).build()
val webSocket = OkHttpClient().newWebSocket(
request,
object : WebSocketListener() {
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
listener.onSocketClose(code, reason)
}
val webSocket =
OkHttpClient().newWebSocket(
request,
object : WebSocketListener() {
override fun onClosed(
webSocket: WebSocket,
code: Int,
reason: String
) {
listener.onSocketClose(code, reason)
}

override fun onMessage(webSocket: WebSocket, bytes: ByteString) {
try {
val peerMessage = PeerMessage.parseFrom(bytes.toByteArray())
if (peerMessage.hasAuthenticated()) {
listener.onAuthSuccess()
} else if (peerMessage.hasMediaEvent()) {
receiveEvent(peerMessage.mediaEvent.data)
} else {
Timber.w("Received unexpected websocket message: $peerMessage")
override fun onMessage(
webSocket: WebSocket,
bytes: ByteString
) {
try {
val peerMessage = PeerMessage.parseFrom(bytes.toByteArray())
if (peerMessage.hasAuthenticated()) {
listener.onAuthSuccess()
} else if (peerMessage.hasMediaEvent()) {
receiveEvent(peerMessage.mediaEvent.data)
} else {
Timber.w("Received unexpected websocket message: $peerMessage")
}
} catch (e: Exception) {
Timber.e("Received invalid websocket message", e)
}
} catch (e: Exception) {
Timber.e("Received invalid websocket message", e)
}
}

override fun onOpen(webSocket: WebSocket, response: Response) {
listener.onSocketOpen()
val authRequest = PeerMessage
.newBuilder()
.setAuthRequest(PeerMessage.AuthRequest.newBuilder().setToken(config.token))
.build()
sendEvent(authRequest)
}
override fun onOpen(
webSocket: WebSocket,
response: Response
) {
listener.onSocketOpen()
val authRequest =
PeerMessage
.newBuilder()
.setAuthRequest(PeerMessage.AuthRequest.newBuilder().setToken(config.token))
.build()
sendEvent(authRequest)
}

override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
listener.onSocketError(t, response)
override fun onFailure(
webSocket: WebSocket,
t: Throwable,
response: Response?
) {
listener.onSocketError(t, response)
}
}
},
)
)

this.webSocket = webSocket
}
Expand Down Expand Up @@ -108,30 +124,31 @@ internal class JellyfishClientInternal(
}

override fun onSendMediaEvent(event: SerializedMediaEvent) {
val mediaEvent = PeerMessage
.newBuilder()
.setMediaEvent(MediaEvent.newBuilder().setData(event))
.build()
val mediaEvent =
PeerMessage
.newBuilder()
.setMediaEvent(MediaEvent.newBuilder().setData(event))
.build()
sendEvent(mediaEvent)
}

override fun onTrackAdded(ctx: TrackContext) {
var trackContext = TrackContext(ctx)
val trackContext = TrackContext(ctx)
listener.onTrackAdded(trackContext)
}

override fun onTrackReady(ctx: TrackContext) {
var trackContext = TrackContext(ctx)
val trackContext = TrackContext(ctx)
listener.onTrackReady(trackContext)
}

override fun onTrackRemoved(ctx: TrackContext) {
var trackContext = TrackContext(ctx)
val trackContext = TrackContext(ctx)
listener.onTrackRemoved(trackContext)
}

override fun onTrackUpdated(ctx: TrackContext) {
var trackContext = TrackContext(ctx)
val trackContext = TrackContext(ctx)
listener.onTrackUpdated(trackContext)
}

Expand All @@ -143,7 +160,10 @@ internal class JellyfishClientInternal(
listener.onJoinError(metadata)
}

override fun onConnected(peerID: String, peersInRoom: List<Peer>) {
override fun onConnected(
peerID: String,
peersInRoom: List<Peer>
) {
listener.onJoined(peerID, peersInRoom)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ interface JellyfishClientListener {
/**
* Emitted when the websocket connection is closed
*/
fun onSocketClose(code: Int, reason: String) {
fun onSocketClose(
code: Int,
reason: String
) {
Timber.i("Socket was closed with code $code reason: $reason")
}

/**
* Emitted when occurs an error in the websocket connection
*/
fun onSocketError(t: Throwable, response: Response?) {
fun onSocketError(
t: Throwable,
response: Response?
) {
Timber.w("Socket error:", t, response)
}

Expand All @@ -38,7 +44,10 @@ interface JellyfishClientListener {
/**
* Emitted when local user is connected to jellyfish.
*/
fun onJoined(peerID: String, peersInRoom: List<Peer>)
fun onJoined(
peerID: String,
peersInRoom: List<Peer>
)

/**
* Emitted when there was an error while connecting to the jellyfish.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,20 @@ class JellyfishTrackContext(private val trackContext: TrackContext) {
}

fun setOnEncodingChangedListener(listener: JellyfishOnEncodingChangedListener) {
val rtcListener = OnEncodingChangedListener { trackContext -> listener.onEncodingChangedListener(JellyfishTrackContext(trackContext)) }
val rtcListener =
OnEncodingChangedListener {
trackContext ->
listener.onEncodingChangedListener(JellyfishTrackContext(trackContext))
}
trackContext.setOnEncodingChangedListener(rtcListener)
}

fun setOnVoiceActivityChangedListener(listener: JellyfishOnVoiceActivityChangedListener) {
val rtcListener = OnVoiceActivityChangedListener { trackContext -> listener.onVoiceActivityChanged(JellyfishTrackContext(trackContext)) }
val rtcListener =
OnVoiceActivityChangedListener {
trackContext ->
listener.onVoiceActivityChanged(JellyfishTrackContext(trackContext))
}
trackContext.setOnVoiceActivityChangedListener(rtcListener)
}
}
Loading
Loading