Skip to content

Commit

Permalink
fix: Fix use incorrect length value in RtmClientImplOverride.publish/…
Browse files Browse the repository at this point in the history
…StreamChannelImpl.publishTopicMessage
  • Loading branch information
littleGnAl committed Oct 14, 2024
1 parent 985c67a commit bcf0a38
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 29 deletions.
5 changes: 3 additions & 2 deletions lib/src/bindings/agora_rtm_client_impl_override.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,11 @@ class RtmClientImplOverride extends rtmc_binding.RtmClientImpl {
required String message,
required int length,
required PublishOptions option}) async {
final messageUint8List = Uint8List.fromList(utf8.encode(message));
return publishBinaryMessage(
channelName: channelName,
message: Uint8List.fromList(utf8.encode(message)),
length: length,
message: messageUint8List,
length: messageUint8List.length,
option: option);
}
}
10 changes: 6 additions & 4 deletions lib/src/bindings/agora_stream_channel_impl_override.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ class StreamChannelImpl extends sci_binding.StreamChannelImpl
required String message,
required int length,
required TopicMessageOptions option}) async {
final messageUint8List = Uint8List.fromList(utf8.encode(message));
return publishBinaryMessage(
topic: topic,
message: Uint8List.fromList(utf8.encode(message)),
length: length,
message: messageUint8List,
length: messageUint8List.length,
option: option);
}

Expand All @@ -57,10 +58,11 @@ class StreamChannelImpl extends sci_binding.StreamChannelImpl
required String message,
required int length,
required TopicMessageOptions option}) {
final messageUint8List = Uint8List.fromList(utf8.encode(message));
return publishBinaryMessage(
topic: topic,
message: Uint8List.fromList(utf8.encode(message)),
length: length,
message: messageUint8List,
length: messageUint8List.length,
option: option);
}
}
22 changes: 0 additions & 22 deletions lib/src/impl/agora_rtm_client_impl_override.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,6 @@ class RtmClientImplOverride extends rtm_client_impl.RtmClientImpl {
String channelName, String message,
{RtmChannelType channelType = RtmChannelType.message,
String? customType}) async {
// final option = PublishOptions(
// channelType: channelType,
// messageType: RtmMessageType.string,
// customType: customType);
// final requestId = await nativeBindingRtmClientImpl.publish(
// channelName: channelName,
// message: message,
// length: message.length,
// option: option);
// return rtmResultHandler.request(requestId);

final option = PublishOptions(
channelType: channelType,
messageType: RtmMessageType.string,
Expand Down Expand Up @@ -260,17 +249,6 @@ class RtmClientImplOverride extends rtm_client_impl.RtmClientImpl {
String channelName, Uint8List message,
{RtmChannelType channelType = RtmChannelType.message,
String? customType}) async {
// final option = PublishOptions(
// channelType: channelType,
// messageType: RtmMessageType.binary,
// customType: customType);
// final requestId = await nativeBindingRtmClientImpl.publishBinaryMessage(
// channelName: channelName,
// message: message,
// length: message.length,
// option: option);
// return rtmResultHandler.request(requestId);

final option = PublishOptions(
channelType: channelType,
messageType: RtmMessageType.binary,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'dart:convert';
import 'dart:typed_data' show Uint8List;

import 'package:agora_rtm/agora_rtm.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:agora_rtm/src/bindings/agora_rtm_client_impl_override.dart'
as agora_rtm_client_impl;

import 'fake_iris_method_channel.dart';

void main() {
test('RtmClientImplOverride.publish', () {
FakeIrisMethodChannel irisMethodChannel = FakeIrisMethodChannel();
agora_rtm_client_impl.RtmClientImplOverride rtmClientImplOverride =
agora_rtm_client_impl.RtmClientImplOverride.create(irisMethodChannel);
const message = 'hello';
final messageUint8List = Uint8List.fromList(utf8.encode(message));

rtmClientImplOverride.publish(
channelName: '123',
message: message,
length: 5,
option: const PublishOptions());

final methodCall = irisMethodChannel.methodCallQueue[0];
final paramsMap = jsonDecode(methodCall.params);
expect(paramsMap['length'], messageUint8List.length);
expect(methodCall.buffers![0], messageUint8List);
});

test('RtmClientImplOverride.publishBinaryMessage', () {
FakeIrisMethodChannel irisMethodChannel = FakeIrisMethodChannel();
agora_rtm_client_impl.RtmClientImplOverride rtmClientImplOverride =
agora_rtm_client_impl.RtmClientImplOverride.create(irisMethodChannel);
const message = 'hello';
final messageUint8List = Uint8List.fromList(utf8.encode(message));

rtmClientImplOverride.publishBinaryMessage(
channelName: '123',
message: messageUint8List,
length: messageUint8List.length,
option: const PublishOptions());

final methodCall = irisMethodChannel.methodCallQueue[0];
final paramsMap = jsonDecode(methodCall.params);
expect(paramsMap['length'], messageUint8List.length);
expect(methodCall.buffers![0], messageUint8List);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'dart:convert';
import 'dart:typed_data' show Uint8List;

import 'package:agora_rtm/agora_rtm.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:agora_rtm/src/bindings/agora_stream_channel_impl_override.dart'
as agora_stream_channel_impl;

import 'fake_iris_method_channel.dart';

void main() {
test('StreamChannelImpl.publishTopicMessage', () {
FakeIrisMethodChannel irisMethodChannel = FakeIrisMethodChannel();
agora_stream_channel_impl.StreamChannelImpl streamChannelImpl =
agora_stream_channel_impl.StreamChannelImpl(irisMethodChannel, '123');
const message = 'hello';
final messageUint8List = Uint8List.fromList(utf8.encode(message));

streamChannelImpl.publishTopicMessage(
topic: '123',
message: message,
length: 5,
option: const TopicMessageOptions());

final methodCall = irisMethodChannel.methodCallQueue[0];
final paramsMap = jsonDecode(methodCall.params);
expect(paramsMap['length'], messageUint8List.length);
expect(methodCall.buffers![0], messageUint8List);
});

test('StreamChannelImpl.publishBinaryMessage', () {
FakeIrisMethodChannel irisMethodChannel = FakeIrisMethodChannel();
agora_stream_channel_impl.StreamChannelImpl streamChannelImpl =
agora_stream_channel_impl.StreamChannelImpl(irisMethodChannel, '123');
const message = 'hello';
final messageUint8List = Uint8List.fromList(utf8.encode(message));

streamChannelImpl.publishBinaryMessage(
topic: '123',
message: messageUint8List,
length: messageUint8List.length,
option: const TopicMessageOptions());

final methodCall = irisMethodChannel.methodCallQueue[0];
final paramsMap = jsonDecode(methodCall.params);
expect(paramsMap['length'], messageUint8List.length);
expect(methodCall.buffers![0], messageUint8List);
});
}
4 changes: 3 additions & 1 deletion test_shard/integration_test_app/test/all_mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import 'package:agora_rtm/src/bindings/gen/agora_stream_channel_impl.dart'

import 'package:agora_rtm/src/impl/rtm_result_handler_impl.dart';

import 'package:iris_method_channel/iris_method_channel.dart';

@GenerateNiceMocks([
MockSpec<rtm_client_impl_native_binding.RtmClientImplOverride>(),
MockSpec<rtm_lock_impl_native_binding.RtmLockImpl>(),
MockSpec<rtm_presence_impl_native_binding.RtmPresenceImpl>(),
MockSpec<rtm_storage_impl_native_binding.RtmStorageImpl>(),
MockSpec<stream_channel_impl_native_binding.StreamChannelImpl>(),
// RtmResultHandlerImpl
MockSpec<RtmResultHandlerImpl>(),
MockSpec<IrisMethodChannel>(),
])
// ignore: unused_import
import 'all_mocks.mocks.dart';
Loading

0 comments on commit bcf0a38

Please sign in to comment.