Skip to content

Commit

Permalink
[RSDK-6863] webrtc message size (#182)
Browse files Browse the repository at this point in the history
* Update dial functions so that mdns works with api keys

* Loop over long messages and send them over webrtc data channel
  • Loading branch information
njooma authored Mar 8, 2024
1 parent 5ebf1cc commit 516f4ef
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 30 deletions.
2 changes: 1 addition & 1 deletion example/viam_robot_example_app/macos/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :osx, '10.14'
platform :osx, '10.15'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
15242523DB1FCDEE32F203C2 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = "<group>"; };
335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = "<group>"; };
33CC10ED2044A3C60003C045 /* viam_example_app.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = viam_example_app.app; sourceTree = BUILT_PRODUCTS_DIR; };
33CC10ED2044A3C60003C045 /* Viam Example App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Viam Example App.app"; sourceTree = BUILT_PRODUCTS_DIR; };
33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = "<group>"; };
33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -112,7 +112,7 @@
33CC10EE2044A3C60003C045 /* Products */ = {
isa = PBXGroup;
children = (
33CC10ED2044A3C60003C045 /* viam_example_app.app */,
33CC10ED2044A3C60003C045 /* Viam Example App.app */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -159,7 +159,6 @@
670B361EC221A983BEC9B00C /* Pods-Runner.release.xcconfig */,
CD7EFC0D75004BBCC6F28023 /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -193,7 +192,7 @@
);
name = Runner;
productName = Runner;
productReference = 33CC10ED2044A3C60003C045 /* viam_example_app.app */;
productReference = 33CC10ED2044A3C60003C045 /* Viam Example App.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
Expand All @@ -203,7 +202,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down Expand Up @@ -405,7 +404,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand All @@ -427,6 +426,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
};
Expand Down Expand Up @@ -484,7 +484,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -531,7 +531,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand All @@ -553,6 +553,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -573,6 +574,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "viam_example_app.app"
BuildableName = "Viam Example App.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
Expand All @@ -31,7 +31,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "viam_example_app.app"
BuildableName = "Viam Example App.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
Expand All @@ -54,7 +54,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "viam_example_app.app"
BuildableName = "Viam Example App.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
Expand All @@ -71,7 +71,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "viam_example_app.app"
BuildableName = "Viam Example App.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
Expand Down
11 changes: 5 additions & 6 deletions lib/src/rpc/dial.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ Future<ClientChannelBase> dial(String address, DialOptions? options, String Func
// when determining if we want to use the external auth credentials for the signaling
// in cases where the external signaling is the same as the external auth. For mdns
// this isn't the case.
final dialOptsCopy = opts
.._usingMdns = true
..authEntity = address;
return await _dialWebRtc(mdnsUri, dialOptsCopy, sessionCallback);
final dialOptsCopy = opts.._usingMdns = true;
dialOptsCopy.webRtcOptions ??= DialWebRtcOptions();
dialOptsCopy.webRtcOptions?.signalingServerAddress = mdnsUri;
return await _dialWebRtc(address, dialOptsCopy, sessionCallback);
} on NotLocalAddressException catch (e) {
_logger.d(e.toString());
} catch (e) {
Expand Down Expand Up @@ -204,8 +204,7 @@ Future<ClientChannelBase> _dialWebRtc(String address, DialOptions options, Strin
_logger.d('Connecting to signaling server: $signalingServer');
final signalingChannel = await _dialDirectGrpc(signalingServer, options, sessionCallback);
_logger.d('Connected to signaling server: $signalingServer');
final signalingClient = SignalingServiceClient(signalingChannel,
options: CallOptions(metadata: {'rpc-host': ((options._usingMdns) ? options.authEntity : address)!}));
final signalingClient = SignalingServiceClient(signalingChannel, options: CallOptions(metadata: {'rpc-host': address}));
WebRTCConfig config;
try {
config = (await signalingClient.optionalWebRTCConfig(OptionalWebRTCConfigRequest())).config;
Expand Down
37 changes: 27 additions & 10 deletions lib/src/rpc/web_rtc/web_rtc_transport_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ class WebRtcTransportStream extends GrpcTransportStream {

void _listenToOutgoingMessages() {
_outgoingMessages.stream.listen((List<int> data) {
final payloadRequest = grpc.Request()
..stream = headersRequest.stream
..message = (grpc.RequestMessage()
..hasMessage = true
..eos = true
..packetMessage = (grpc.PacketMessage()
..data = data
..eom = true));

final connectionState = webRtcClientChannel.rtcPeerConnection.connectionState;

if (connectionState == RTCPeerConnectionState.RTCPeerConnectionStateFailed ||
Expand All @@ -73,7 +64,33 @@ class WebRtcTransportStream extends GrpcTransportStream {
headersSent = true;
webRtcClientChannel.dataChannel.send(RTCDataChannelMessage.fromBinary(headersRequest.writeToBuffer()));
}
webRtcClientChannel.dataChannel.send(RTCDataChannelMessage.fromBinary(payloadRequest.writeToBuffer()));
const maxMessageLength = 32 * 1024;
final chunks = data.slices(maxMessageLength).toList();
Iterable<grpc.Request> requests;
if (chunks.isEmpty) {
requests = [
grpc.Request()
..stream = headersRequest.stream
..message = (grpc.RequestMessage()
..hasMessage = true
..eos = false
..packetMessage = (grpc.PacketMessage()
..data = data
..eom = true))
];
} else {
requests = chunks.mapIndexed((index, chunk) => grpc.Request()
..stream = headersRequest.stream
..message = (grpc.RequestMessage()
..hasMessage = true
..eos = false
..packetMessage = (grpc.PacketMessage()
..data = chunk
..eom = index == chunks.length - 1)));
}
requests.forEach((payloadRequest) {
webRtcClientChannel.dataChannel.send(RTCDataChannelMessage.fromBinary(payloadRequest.writeToBuffer()));
});
});
}

Expand Down

0 comments on commit 516f4ef

Please sign in to comment.