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

Commit e7d7102

Browse files
authored
[EX-483] Code cleanups required after library merge (#16)
This is follow up on comments from fishjam-dev/membrane-webrtc-android#59 and #15 I've added `ktlint` to this repository, fixed formatting issues. And also did `Code Cleanup`.
1 parent 56a3113 commit e7d7102

33 files changed

+1648
-1556
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[*.{kt,kts}]
2+
ktlint_code_style = ktlint_official
3+
ktlint_standard_no-wildcard-imports = disabled
4+
ktlint_standard_filename = disabled
5+
ktlint_standard_function-naming = disabled
6+
ktlint_standard_property-naming = disabled
7+
ij_kotlin_allow_trailing_comma = false
8+
ij_kotlin_allow_trailing_comma_on_call_site = false

.github/workflows/build_lint_test.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ jobs:
1414
java-version: 17
1515
distribution: zulu
1616

17-
- name: Lint
18-
run: ./gradlew lintKotlin
17+
- name: Download ktlint
18+
run: curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.1.1/ktlint && chmod a+x ktlint && sudo mv ktlint /usr/local/bin/
19+
20+
- name: Run linter
21+
run: ktlint **/*.kt
1922

2023
- name: Build
2124
run: ./gradlew assembleRelease

JellyfishClient/src/main/java/com/jellyfishdev/jellyfishclient/JellyfishClient.kt

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ typealias TrackContext = JellyfishTrackContext
1616

1717
data class Config(
1818
val websocketUrl: String,
19-
val token: String,
19+
val token: String
2020
)
2121

2222
class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
@@ -73,7 +73,7 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
7373
fun createVideoTrack(
7474
videoParameters: VideoParameters,
7575
metadata: Metadata,
76-
captureDeviceName: String? = null,
76+
captureDeviceName: String? = null
7777
): LocalVideoTrack {
7878
return client.webrtcClient.createVideoTrack(videoParameters, metadata, captureDeviceName)
7979
}
@@ -105,13 +105,13 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
105105
mediaProjectionPermission: Intent,
106106
videoParameters: VideoParameters,
107107
metadata: Metadata,
108-
onEnd: (() -> Unit)? = null,
109-
): LocalScreencastTrack? {
108+
onEnd: (() -> Unit)? = null
109+
): LocalScreencastTrack {
110110
return client.webrtcClient.createScreencastTrack(
111111
mediaProjectionPermission,
112112
videoParameters,
113113
metadata,
114-
onEnd,
114+
onEnd
115115
)
116116
}
117117

@@ -135,7 +135,10 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
135135
* @param trackId an id of a remote track
136136
* @param encoding an encoding to receive
137137
*/
138-
fun setTargetTrackEncoding(trackId: String, encoding: TrackEncoding) {
138+
fun setTargetTrackEncoding(
139+
trackId: String,
140+
encoding: TrackEncoding
141+
) {
139142
client.webrtcClient.setTargetTrackEncoding(trackId, encoding)
140143
}
141144

@@ -145,7 +148,10 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
145148
* @param trackId an id of a local track
146149
* @param encoding an encoding that will be enabled
147150
*/
148-
fun enableTrackEncoding(trackId: String, encoding: TrackEncoding) {
151+
fun enableTrackEncoding(
152+
trackId: String,
153+
encoding: TrackEncoding
154+
) {
149155
client.webrtcClient.enableTrackEncoding(trackId, encoding)
150156
}
151157

@@ -155,7 +161,10 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
155161
* @param trackId and id of a local track
156162
* @param encoding an encoding that will be disabled
157163
*/
158-
fun disableTrackEncoding(trackId: String, encoding: TrackEncoding) {
164+
fun disableTrackEncoding(
165+
trackId: String,
166+
encoding: TrackEncoding
167+
) {
159168
client.webrtcClient.disableTrackEncoding(trackId, encoding)
160169
}
161170

@@ -178,7 +187,10 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
178187
* If the metadata is different from what is already tracked in the room, the optional
179188
* callback `onTrackUpdated` will be triggered for other peers in the room.
180189
*/
181-
fun updateTrackMetadata(trackId: String, trackMetadata: Metadata) {
190+
fun updateTrackMetadata(
191+
trackId: String,
192+
trackMetadata: Metadata
193+
) {
182194
client.webrtcClient.updateTrackMetadata(trackId, trackMetadata)
183195
}
184196

@@ -189,7 +201,10 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
189201
* @param trackId track id of a video track
190202
* @param bandwidthLimit bandwidth in kbps
191203
*/
192-
fun setTrackBandwidth(trackId: String, bandwidthLimit: TrackBandwidthLimit.BandwidthLimit) {
204+
fun setTrackBandwidth(
205+
trackId: String,
206+
bandwidthLimit: TrackBandwidthLimit.BandwidthLimit
207+
) {
193208
client.webrtcClient.setTrackBandwidth(trackId, bandwidthLimit)
194209
}
195210

@@ -202,7 +217,7 @@ class JellyfishClient(appContext: Context, listener: JellyfishClientListener) {
202217
fun setEncodingBandwidth(
203218
trackId: String,
204219
encoding: String,
205-
bandwidthLimit: TrackBandwidthLimit.BandwidthLimit,
220+
bandwidthLimit: TrackBandwidthLimit.BandwidthLimit
206221
) {
207222
client.webrtcClient.setEncodingBandwidth(trackId, encoding, bandwidthLimit)
208223
}

JellyfishClient/src/main/java/com/jellyfishdev/jellyfishclient/JellyfishClientInternal.kt

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typealias Peer = Endpoint
2222

2323
internal class JellyfishClientInternal(
2424
appContext: Context,
25-
private val listener: JellyfishClientListener,
25+
private val listener: JellyfishClientListener
2626
) :
2727
MembraneRTCListener {
2828
private var webSocket: WebSocket? = null
@@ -36,42 +36,58 @@ internal class JellyfishClientInternal(
3636

3737
fun connect(config: Config) {
3838
val request = Request.Builder().url(config.websocketUrl).build()
39-
val webSocket = OkHttpClient().newWebSocket(
40-
request,
41-
object : WebSocketListener() {
42-
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
43-
listener.onSocketClose(code, reason)
44-
}
39+
val webSocket =
40+
OkHttpClient().newWebSocket(
41+
request,
42+
object : WebSocketListener() {
43+
override fun onClosed(
44+
webSocket: WebSocket,
45+
code: Int,
46+
reason: String
47+
) {
48+
listener.onSocketClose(code, reason)
49+
}
4550

46-
override fun onMessage(webSocket: WebSocket, bytes: ByteString) {
47-
try {
48-
val peerMessage = PeerMessage.parseFrom(bytes.toByteArray())
49-
if (peerMessage.hasAuthenticated()) {
50-
listener.onAuthSuccess()
51-
} else if (peerMessage.hasMediaEvent()) {
52-
receiveEvent(peerMessage.mediaEvent.data)
53-
} else {
54-
Timber.w("Received unexpected websocket message: $peerMessage")
51+
override fun onMessage(
52+
webSocket: WebSocket,
53+
bytes: ByteString
54+
) {
55+
try {
56+
val peerMessage = PeerMessage.parseFrom(bytes.toByteArray())
57+
if (peerMessage.hasAuthenticated()) {
58+
listener.onAuthSuccess()
59+
} else if (peerMessage.hasMediaEvent()) {
60+
receiveEvent(peerMessage.mediaEvent.data)
61+
} else {
62+
Timber.w("Received unexpected websocket message: $peerMessage")
63+
}
64+
} catch (e: Exception) {
65+
Timber.e("Received invalid websocket message", e)
5566
}
56-
} catch (e: Exception) {
57-
Timber.e("Received invalid websocket message", e)
5867
}
59-
}
6068

61-
override fun onOpen(webSocket: WebSocket, response: Response) {
62-
listener.onSocketOpen()
63-
val authRequest = PeerMessage
64-
.newBuilder()
65-
.setAuthRequest(PeerMessage.AuthRequest.newBuilder().setToken(config.token))
66-
.build()
67-
sendEvent(authRequest)
68-
}
69+
override fun onOpen(
70+
webSocket: WebSocket,
71+
response: Response
72+
) {
73+
listener.onSocketOpen()
74+
val authRequest =
75+
PeerMessage
76+
.newBuilder()
77+
.setAuthRequest(PeerMessage.AuthRequest.newBuilder().setToken(config.token))
78+
.build()
79+
sendEvent(authRequest)
80+
}
6981

70-
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
71-
listener.onSocketError(t, response)
82+
override fun onFailure(
83+
webSocket: WebSocket,
84+
t: Throwable,
85+
response: Response?
86+
) {
87+
listener.onSocketError(t, response)
88+
}
7289
}
73-
},
74-
)
90+
)
7591

7692
this.webSocket = webSocket
7793
}
@@ -108,30 +124,31 @@ internal class JellyfishClientInternal(
108124
}
109125

110126
override fun onSendMediaEvent(event: SerializedMediaEvent) {
111-
val mediaEvent = PeerMessage
112-
.newBuilder()
113-
.setMediaEvent(MediaEvent.newBuilder().setData(event))
114-
.build()
127+
val mediaEvent =
128+
PeerMessage
129+
.newBuilder()
130+
.setMediaEvent(MediaEvent.newBuilder().setData(event))
131+
.build()
115132
sendEvent(mediaEvent)
116133
}
117134

118135
override fun onTrackAdded(ctx: TrackContext) {
119-
var trackContext = TrackContext(ctx)
136+
val trackContext = TrackContext(ctx)
120137
listener.onTrackAdded(trackContext)
121138
}
122139

123140
override fun onTrackReady(ctx: TrackContext) {
124-
var trackContext = TrackContext(ctx)
141+
val trackContext = TrackContext(ctx)
125142
listener.onTrackReady(trackContext)
126143
}
127144

128145
override fun onTrackRemoved(ctx: TrackContext) {
129-
var trackContext = TrackContext(ctx)
146+
val trackContext = TrackContext(ctx)
130147
listener.onTrackRemoved(trackContext)
131148
}
132149

133150
override fun onTrackUpdated(ctx: TrackContext) {
134-
var trackContext = TrackContext(ctx)
151+
val trackContext = TrackContext(ctx)
135152
listener.onTrackUpdated(trackContext)
136153
}
137154

@@ -143,7 +160,10 @@ internal class JellyfishClientInternal(
143160
listener.onJoinError(metadata)
144161
}
145162

146-
override fun onConnected(peerID: String, peersInRoom: List<Peer>) {
163+
override fun onConnected(
164+
peerID: String,
165+
peersInRoom: List<Peer>
166+
) {
147167
listener.onJoined(peerID, peersInRoom)
148168
}
149169

JellyfishClient/src/main/java/com/jellyfishdev/jellyfishclient/JellyfishClientListener.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ interface JellyfishClientListener {
77
/**
88
* Emitted when the websocket connection is closed
99
*/
10-
fun onSocketClose(code: Int, reason: String) {
10+
fun onSocketClose(
11+
code: Int,
12+
reason: String
13+
) {
1114
Timber.i("Socket was closed with code $code reason: $reason")
1215
}
1316

1417
/**
1518
* Emitted when occurs an error in the websocket connection
1619
*/
17-
fun onSocketError(t: Throwable, response: Response?) {
20+
fun onSocketError(
21+
t: Throwable,
22+
response: Response?
23+
) {
1824
Timber.w("Socket error:", t, response)
1925
}
2026

@@ -38,7 +44,10 @@ interface JellyfishClientListener {
3844
/**
3945
* Emitted when local user is connected to jellyfish.
4046
*/
41-
fun onJoined(peerID: String, peersInRoom: List<Peer>)
47+
fun onJoined(
48+
peerID: String,
49+
peersInRoom: List<Peer>
50+
)
4251

4352
/**
4453
* Emitted when there was an error while connecting to the jellyfish.

JellyfishClient/src/main/java/com/jellyfishdev/jellyfishclient/JellyfishTrackContext.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,20 @@ class JellyfishTrackContext(private val trackContext: TrackContext) {
5454
}
5555

5656
fun setOnEncodingChangedListener(listener: JellyfishOnEncodingChangedListener) {
57-
val rtcListener = OnEncodingChangedListener { trackContext -> listener.onEncodingChangedListener(JellyfishTrackContext(trackContext)) }
57+
val rtcListener =
58+
OnEncodingChangedListener {
59+
trackContext ->
60+
listener.onEncodingChangedListener(JellyfishTrackContext(trackContext))
61+
}
5862
trackContext.setOnEncodingChangedListener(rtcListener)
5963
}
6064

6165
fun setOnVoiceActivityChangedListener(listener: JellyfishOnVoiceActivityChangedListener) {
62-
val rtcListener = OnVoiceActivityChangedListener { trackContext -> listener.onVoiceActivityChanged(JellyfishTrackContext(trackContext)) }
66+
val rtcListener =
67+
OnVoiceActivityChangedListener {
68+
trackContext ->
69+
listener.onVoiceActivityChanged(JellyfishTrackContext(trackContext))
70+
}
6371
trackContext.setOnVoiceActivityChangedListener(rtcListener)
6472
}
6573
}

0 commit comments

Comments
 (0)