Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCE-748: support for protobufs #246

Open
wants to merge 51 commits into
base: main
Choose a base branch
from

Conversation

MiloszFilimowski
Copy link
Collaborator

@MiloszFilimowski MiloszFilimowski commented Nov 19, 2024

Description

  • Updated mobile SDK to support protobufs for media events.
  • This PR does not support old version of handling media events via JSON so this is a BREAKING CHANGE.

Motivation and Context

New version of fishjam added protobufs for media events.

How has this been tested?

  • Run and tested bidirectional connection between Android/iOS

Types of changes

  • 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)

Copy link

linear bot commented Nov 19, 2024

@MiloszFilimowski MiloszFilimowski force-pushed the mfilimowski/fce-837-local-peer-metadata branch from 1f26504 to f2abce9 Compare November 22, 2024 10:21
@@ -230,3 +236,13 @@ public struct AnyJson: Codable {
var stringValue: String { return key }
}
}

extension String {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are those really better than just using AnyJson(from: )? Seems a little bit like an overkill

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair point, I just thought it looks better but you're right.

}

func toAnyJson() -> AnyJson? {
return try? AnyJson(from: self)
Copy link
Collaborator

Choose a reason for hiding this comment

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

And if they are better then this could be try? toAnyJson()

extension Encodable {

public func toJsonString() throws -> String {
if let json = String(data: try JSONEncoder().encode(self), encoding: .utf8) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know it's controversial but what about guard and throw in else instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK MAN, NO PROBLEM

Copy link
Collaborator

Choose a reason for hiding this comment

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

NO SHOUTING IN THE CHAT PLEASE, PEOPLE ARE TRYING TO WORK HERE


var toJsonStringOrEmpty: String {
do {
return try self.toJsonString()
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can remove self here


extension [String: Metadata] {
public func toDictionaryJson() -> [String: String] {
return mapValues { val in
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think mapValues(\.toJsonStringOrEmpty) should work here

})),
}));
return peers.map((peer) => {
return {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove returns

@@ -69,7 +69,7 @@ compile_ios: $(PROTOC) $(PROTOC_GEN_SWIFT) sync
@echo "Compiling proto files for iOS"
@for proto in $(PROTO_FILES); do \
echo "Compiling iOS: $$proto"; \
$(PROTOC) -I=$(PROTOS_PATH) -I=$(PROTOC_BASE_PATH)/include --plugin=$(PROTOC_GEN_SWIFT) --swift_out=$(IOS_OUT) $$proto; \
$(PROTOC) -I=$(PROTOS_PATH) -I=$(PROTOC_BASE_PATH)/include --plugin=$(PROTOC_GEN_SWIFT) --swift_out=$(IOS_OUT) --swift_opt=Visibility=public $$proto; \
done
@echo "DONE for iOS"

Copy link
Collaborator

Choose a reason for hiding this comment

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

New line please

@maksg
Copy link
Collaborator

maksg commented Nov 27, 2024

I left some comments. But other than that great job! 🎉

@MiloszFilimowski MiloszFilimowski force-pushed the mfilimowski/fce-837-local-peer-metadata branch from 6c233ab to bd0c300 Compare November 28, 2024 10:08
@@ -176,11 +176,9 @@ internal class PeerConnectionManager: NSObject, RTCPeerConnectionDelegate {
config.candidateNetworkPolicy = .all
config.tcpCandidatePolicy = .disabled

// if ice servers are not empty that probably means we are using turn servers
// if ice servers are not empty that probably means we are using turn servers, which are not handled at the moment

Choose a reason for hiding this comment

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

suggestion:

We might actually start using turn servers, that will be passed in the connected message. They will be handled out of the box

Suggested change
// if ice servers are not empty that probably means we are using turn servers, which are not handled at the moment

@@ -176,11 +176,9 @@ internal class PeerConnectionManager: NSObject, RTCPeerConnectionDelegate {
config.candidateNetworkPolicy = .all
config.tcpCandidatePolicy = .disabled

// if ice servers are not empty that probably means we are using turn servers
// if ice servers are not empty that probably means we are using turn servers, which are not handled at the moment
if iceServers.count > 0 {

Choose a reason for hiding this comment

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

suggestion:
If they are empty, then we can just pass this empty list from protobuf message

Suggested change
if iceServers.count > 0 {

guard let trackId: String = transceiver.sender.track?.trackId else {
return
}
mapping[trackId] = 500 // TODO: Change with simulcast

Choose a reason for hiding this comment

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

suggestion: more appropriate value would be 1500000 as this value is in bit\s

var trackBitrates = Fishjam_MediaEvents_Peer_MediaEvent.TrackBitrates()
trackBitrates.trackID = key
var bitrate = Fishjam_MediaEvents_Peer_MediaEvent.VariantBitrate()
bitrate.variant = .unspecified // TODO: Add with simulcast

Choose a reason for hiding this comment

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

note: this will remain .unspecified for non-simulcast tracks

var candidate = Fishjam_MediaEvents_Candidate()
candidate.candidate = sdp
candidate.sdpMLineIndex = sdpMLineIndex
candidate.sdpMid = String(sdpMid)

Choose a reason for hiding this comment

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

praise: 👍🏽

Comment on lines 382 to 384
if (needsRestart) {
pc.restartIce()
}

Choose a reason for hiding this comment

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

suggestion: In web-sdk we removed this completely. We assume ice restarts are not needed during negotiation. In fact in web-sdk the restarts introduced failures. Try removing this and checking if everything works OK

Suggested change
if (needsRestart) {
pc.restartIce()
}

Copy link
Member

@mironiasty mironiasty left a comment

Choose a reason for hiding this comment

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

Two general comments:

  • can we read package version from configuration file, so releasing app will require less work with updating?
  • I would consider adding link to linear item for simulcast - it might help in future, to understand todo in code

podfileContent = podfileContent.replace(targetRegex, (match) => {
return match.replace(podToReplace, replacementPod);
});
podfileContent = podfileContent.replace(targetRegex, (match) =>
Copy link
Member

Choose a reason for hiding this comment

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

I think this new rule could be decoupled from this PR... Bet let it be as is.

@@ -162,6 +161,7 @@ internal class FishjamClientInternal(
PeerNotifications.PeerMessage.AuthRequest
.newBuilder()
.setToken(connectConfig.token)
.setSdkVersion("mobile-0.6.0")
Copy link
Member

Choose a reason for hiding this comment

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

Can we read this value from config files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tracksTypes,
localEndpoint.tracks.values.toList()
)

rtcEngineCommunication.sdpOffer(
offer.description,
localEndpoint.tracks.map { (_, track) -> track.webrtcId() to track.metadata }.toMap(),
offer.midToTrackIdMapping
offer.midToTrackIdMapping,
localEndpoint.tracks.map { (_, track) -> track.webrtcId() to 1500000 }.toMap() // TODO: Update with simulcast
Copy link
Member

Choose a reason for hiding this comment

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

WDYT about adding link to simulcast project in linear?

Suggested change
localEndpoint.tracks.map { (_, track) -> track.webrtcId() to 1500000 }.toMap() // TODO: Update with simulcast
localEndpoint.tracks.map { (_, track) -> track.webrtcId() to 1500000 }.toMap() // TODO(FCE-XXX): Update with simulcast

encoding.rid
)
)
// TODO: This will be useful after simulcast is enabled
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO: This will be useful after simulcast is enabled
// TODO(FCE-XXX): This will be useful after simulcast is enabled

@@ -0,0 +1,106 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
Copy link
Member

Choose a reason for hiding this comment

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

idea for future: would it be possible to keep this generated files in folder called generated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately it looks like it's not possible, as the package name comes from the protofile and protoc does not provide the ability to modify it. So although we could change the file location it won't work on Android as it expects certain folder structure.

We could modify the protos file, but this might destroy code generation for others...

}

func websocketDidConnect() {
let authRequest = Fishjam_PeerMessage.with({
$0.authRequest = Fishjam_PeerMessage.AuthRequest.with({
$0.token = self.config?.token ?? ""
$0.sdkVersion = "mobile-0.6.0"
Copy link
Member

Choose a reason for hiding this comment

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

Could it be read from config file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@MiloszFilimowski MiloszFilimowski force-pushed the mfilimowski/fce-837-local-peer-metadata branch 4 times, most recently from a381061 to 5083e24 Compare November 29, 2024 15:46
@MiloszFilimowski MiloszFilimowski force-pushed the mfilimowski/fce-837-local-peer-metadata branch from 5083e24 to c8579ba Compare November 29, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants