Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MiloszFilimowski committed Nov 22, 2024
1 parent ace8f22 commit f2abce9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function ConnectScreen({ navigation }: Props) {
try {
setConnectionError(null);
setLoading(true);
const roomManagerUrl = 'http://192.168.82.240:8080/api/rooms';
const roomManagerUrl = 'http://192.168.83.155:8080/api/rooms';

saveStorageData({ videoRoomEnv: videoRoomEnv, roomName, userName });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ internal class FishjamClientInternal(
) {
localEndpoint = localEndpoint.copy(id = endpointID)

otherEndpoints.forEach lit@{
otherEndpoints.forEach {
if (it.endpointId == endpointID) {
this.localEndpoint = this.localEndpoint.copy(metadata = it.metadata.json.serializeToMap())
this.localEndpoint = this.localEndpoint.copy( metadata = it.metadata.json.serializeToMap())
} else {
var endpoint = Endpoint(it.endpointId, it.metadata.json.serializeToMap())

Expand Down Expand Up @@ -541,8 +541,6 @@ internal class FishjamClientInternal(
fun createVideoViewRenderer(): VideoTextureViewRenderer = peerConnectionFactoryWrapper.createVideoViewRenderer()

private fun sendEvent(peerMessage: PeerNotifications.PeerMessage) {
Log.i("RTCMessage", peerMessage.toString())

webSocket?.send(peerMessage.toByteArray().toByteString())
}

Expand All @@ -551,8 +549,6 @@ internal class FishjamClientInternal(
}

override fun onSendMediaEvent(event: fishjam.media_events.peer.Peer.MediaEvent) {
Log.i("MediaEvent", event.toString())

val mediaEvent =
PeerNotifications.PeerMessage
.newBuilder()
Expand All @@ -565,9 +561,7 @@ internal class FishjamClientInternal(
endpointId: String,
metadata: Metadata?
) {
if (endpointId == this.localEndpoint.id) {
return
}
if (endpointId == this.localEndpoint.id) { return }

val endpoint = Endpoint(endpointId, metadata)

Expand Down Expand Up @@ -599,6 +593,8 @@ internal class FishjamClientInternal(
endpointMetadata: Metadata?
) {
if (endpointId == this.localEndpoint.id) {
localEndpoint = this.localEndpoint.copy(metadata = endpointMetadata)
listener.onPeerUpdated(localEndpoint)
return
}

Expand Down Expand Up @@ -678,7 +674,7 @@ internal class FishjamClientInternal(
endpointId: String,
tracks: List<Server.MediaEvent.Track>
) {
if (localEndpoint.id == endpointId) return
if (localEndpoint.id == endpointId) { return }

val endpoint =
remoteEndpoints.remove(endpointId) ?: run {
Expand Down Expand Up @@ -792,12 +788,12 @@ internal class FishjamClientInternal(
return
}

val trackId = track.id()

if (track.endpointId == this.localEndpoint.id) {
return
}

val trackId = track.id()

track =
when (webrtcTrack) {
is VideoTrack ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal val gson = GsonBuilder().create()

internal fun String.serializeToMap(): Map<String, Any?> =
try {
gson.fromJson(this, Map::class.java) as? Map<String, Any?> ?: emptyMap()
gson.fromJson(this, Map::class.java) as Map<String, Any?>
} catch (e: JsonParseException) {
Timber.e(e, "Failed to parse JSON string to map")
emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,7 @@ internal class RTCEngineCommunication {
trackId: String,
encoding: TrackEncoding
) {
// val mediaEvent = fishjam.media_events.peer.Peer.MediaEvent.newBuilder()
// .sett(
// fishjam.media_events.peer.Peer.MediaEvent.SelectEncoding.newBuilder()
// .setTrackId(trackId)
// .setRid(encoding.rid)
// .build()
// )
// .build()
//
// sendEvent(mediaEvent)
//TODO: This will be useful after simulcast is enabled
}

fun renegotiateTracks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ extension FishjamClientInternal: PeerConnectionListener {
sdkLogger.error("Invalid rtcEngineId in onAddTrack: \(trackId)")
return
}

guard track.endpointId != localEndpoint.id else { return }

let trackId = track.id
let endpointId = track.endpointId
let rtcEngineId = track.rtcEngineId
Expand Down Expand Up @@ -550,10 +553,6 @@ extension FishjamClientInternal: RTCEngineListener {
return
}

print("********* EVENT START *********")
print(Mirror(reflecting: event).children.first)
print("********* EVENT END *********")

let mediaEvent =
Fishjam_PeerMessage.with({

Expand Down Expand Up @@ -628,9 +627,8 @@ extension FishjamClientInternal: RTCEngineListener {
}

func onEndpointAdded(endpointId: String, metadata: Metadata?) {
if endpointId == localEndpoint.id {
return
}
guard endpointId != localEndpoint.id else { return }

let endpoint = Endpoint(id: endpointId, metadata: metadata ?? Metadata())

remoteEndpointsMap[endpoint.id] = endpoint
Expand All @@ -639,10 +637,11 @@ extension FishjamClientInternal: RTCEngineListener {
}

func onEndpointRemoved(endpointId: String) {
if endpointId == localEndpoint.id {
guard endpointId != localEndpoint.id else {
listener.onDisconnected()
return
}

guard let endpoint = remoteEndpointsMap.removeValue(forKey: endpointId) else {
sdkLogger.error("Failed to process EndpointLeft event: Endpoint not found: \(endpointId)")
return
Expand All @@ -656,13 +655,18 @@ extension FishjamClientInternal: RTCEngineListener {
}

func onEndpointUpdated(endpointId: String, metadata: Metadata?) {
guard endpointId != localEndpoint.id else {
localEndpoint = localEndpoint.copyWith(metadata: metadata)
listener.onPeerUpdated(endpoint: localEndpoint)
return
}

guard let endpoint = remoteEndpointsMap[endpointId] else {
sdkLogger.error("Failed to process EndpointUpdated event: Endpoint not found: $endpointId")
return
}

remoteEndpointsMap[endpoint.id] = endpoint.copyWith(metadata: metadata)

listener.onPeerUpdated(endpoint: endpoint)
}

Expand Down Expand Up @@ -737,7 +741,7 @@ extension FishjamClientInternal: RTCEngineListener {
}

func onTracksAdded(endpointId: String, tracks: [Fishjam_MediaEvents_Server_MediaEvent.Track]) {
if localEndpoint.id == endpointId { return }
guard localEndpoint.id != endpointId else { return }

guard let endpoint = remoteEndpointsMap[endpointId] else {
sdkLogger.error("Failed to process TracksAdded event: Endpoint not found: \(endpointId)")
Expand Down Expand Up @@ -768,7 +772,7 @@ extension FishjamClientInternal: RTCEngineListener {
}

func onTracksRemoved(endpointId: String, trackIds: [String]) {
if localEndpoint.id == endpointId { return }
guard localEndpoint.id != endpointId else { return }

guard var endpoint = remoteEndpointsMap[endpointId] else {
sdkLogger.error("Failed to process onTracksRemoved event: Endpoint not found: \(endpointId)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class RTCEngineCommunication {
}

func setTargetTrackEncoding(trackId: String, encoding: TrackEncoding) {
// sendEvent(event: SelectEncodingEvent(trackId: trackId, encoding: encoding.description))
//TODO: This will be useful after simulcast is enabled
}

func renegotiateTracks() {
Expand Down

0 comments on commit f2abce9

Please sign in to comment.