Skip to content

Commit

Permalink
FCE-820: Fix peer and server metadata (#225)
Browse files Browse the repository at this point in the history
## Description

- Temporary fix for metadata, should be changed to only use metadata
from RTC Engine after https://linear.app/swmansion/issue/FCE-834 is
merged

## Motivation and Context

- Mobile app was sending wrong metadata.

## How has this been tested?

- Run and tested Android + iOS

## Types of changes

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to
      not work as expected)

## Checklist:

- [ ] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
  • Loading branch information
MiloszFilimowski authored Nov 12, 2024
1 parent 99f080d commit a3e7f00
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ function PreviewScreen({
route.params.fishjamUrl,
route.params.peerToken,
{
peer: {
displayName: route.params.userName,
},
server: {},
displayName: route.params.userName,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ internal class FishjamClientInternal(
coroutineScope.launch {
commandsQueue.addCommand(
Command(CommandName.JOIN, ClientState.JOINED) {
localEndpoint = localEndpoint.copy(metadata = connectConfig?.peerMetadata)
// TODO: Remove after FCE-834
localEndpoint = localEndpoint.copy(metadata = mapOf("peer" to connectConfig?.peerMetadata, "server" to mapOf()))
rtcEngineCommunication.connect(connectConfig?.peerMetadata ?: emptyMap())
}
)
Expand Down Expand Up @@ -464,8 +465,9 @@ internal class FishjamClientInternal(

fun updatePeerMetadata(peerMetadata: Metadata) {
coroutineScope.launch {
// TODO: Remove after FCE-834
rtcEngineCommunication.updatePeerMetadata(peerMetadata)
localEndpoint = localEndpoint.copy(metadata = peerMetadata)
localEndpoint = localEndpoint.copy(metadata = mapOf("peer" to connectConfig?.peerMetadata, "server" to mapOf()))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ class FishjamClientInternal {
func join() {
commandsQueue.addCommand(
Command(commandName: .JOIN, clientStateAfterCommand: .JOINED) {
self.localEndpoint = self.localEndpoint.copyWith(metadata: self.config?.peerMetadata)
self.rtcEngineCommunication.connect(metadata: self.localEndpoint.metadata)
self.localEndpoint = self.localEndpoint.copyWith(
metadata: [
"peer": self.config?.peerMetadata.toDict() as Any, // TODO: Remove after FCE-834
"server": [:],
].toMetadata())
self.rtcEngineCommunication.connect(metadata: self.config?.peerMetadata ?? [:].toMetadata())
})
}

Expand Down Expand Up @@ -290,7 +294,11 @@ class FishjamClientInternal {

func updatePeerMetadata(metadata: Metadata) {
rtcEngineCommunication.updateEndpointMetadata(metadata: metadata)
localEndpoint = localEndpoint.copyWith(metadata: metadata)
localEndpoint = localEndpoint.copyWith(
metadata: [
"peer": self.config?.peerMetadata.toDict() as Any, // TODO: Remove after FCE-834
"server": [:],
].toMetadata())
}

func updateTrackMetadata(trackId: String, metadata: Metadata) {
Expand Down
20 changes: 20 additions & 0 deletions packages/ios-client/Sources/FishjamClient/utils/types.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
public typealias Metadata = AnyJson
public typealias Payload = AnyJson
public typealias SerializedMediaEvent = String

extension [String: Any] {
public func toMetadata() -> Metadata {
var res: Metadata = .init()
self.forEach { entry in
res[entry.key] = entry.value
}
return res
}
}

extension AnyJson {
public func toDict() -> [String: Any] {
var res: [String: Any] = [:]
self.keys.forEach { key in
res[key] = self[key]
}
return res
}
}
2 changes: 0 additions & 2 deletions packages/react-native-client/ios/RNFishjamClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class RNFishjamClient: FishjamClientListener {
var connectPromise: Promise? = nil

var videoSimulcastConfig: SimulcastConfig = SimulcastConfig()
var localUserMetadata: Metadata = .init()

var screenShareSimulcastConfig: SimulcastConfig = SimulcastConfig()
var screenShareMaxBandwidth: TrackBandwidthLimit = .BandwidthLimit(0)
Expand Down Expand Up @@ -207,7 +206,6 @@ class RNFishjamClient: FishjamClientListener {
) {
peerStatus = .connecting
connectPromise = promise
localUserMetadata = ["server": [:], "peer": peerMetadata].toMetadata()

let reconnectConfig = FishjamCloudClient.ReconnectConfig(
maxAttempts: config.reconnectConfig.maxAttempts, initialDelayMs: config.reconnectConfig.initialDelayMs,
Expand Down
20 changes: 0 additions & 20 deletions packages/react-native-client/ios/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,3 @@ let log = OSLog(subsystem: "com.fishjamcloud.react-native-client", category: "Er
}
}
#endif

extension [String: Any] {
public func toMetadata() -> Metadata {
var res: Metadata = .init()
self.forEach { entry in
res[entry.key] = entry.value
}
return res
}
}

extension AnyJson {
public func toDict() -> [String: Any] {
var res: [String: Any] = [:]
self.keys.forEach { key in
res[key] = self[key]
}
return res
}
}
4 changes: 1 addition & 3 deletions packages/react-native-client/src/common/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GenericMetadata } from '../types';
import RNFishjamClientModule from '../RNFishjamClientModule';
import { PeerTrackMetadata } from '../hooks/usePeers';

export type ConnectionConfig = {
/**
Expand All @@ -27,11 +26,10 @@ export type ConnectionConfig = {
*/
export async function joinRoom<
PeerMetadata extends GenericMetadata = GenericMetadata,
ServerMetadata extends GenericMetadata = GenericMetadata,
>(
url: string,
peerToken: string,
peerMetadata?: PeerTrackMetadata<PeerMetadata, ServerMetadata>,
peerMetadata?: PeerMetadata,
config?: ConnectionConfig,
) {
await RNFishjamClientModule.joinRoom(
Expand Down

0 comments on commit a3e7f00

Please sign in to comment.