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

Expand Control API with tariffication callbacks #160

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions e2e-demo/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ async function createRoom(roomId, memberId) {
credentials: { plain: 'test' },
pipeline: pipeline,
on_join: 'grpc://127.0.0.1:9099',
on_leave: 'grpc://127.0.0.1:9099'
on_leave: 'grpc://127.0.0.1:9099',
on_start: 'grpc://127.0.0.1:9099',
on_stop: 'grpc://127.0.0.1:9099'
}
}
}
Expand Down Expand Up @@ -139,7 +141,9 @@ async function createMember(roomId, memberId) {
credentials: { plain: 'test' },
pipeline: pipeline,
on_join: 'grpc://127.0.0.1:9099',
on_leave: 'grpc://127.0.0.1:9099'
on_leave: 'grpc://127.0.0.1:9099',
on_start: 'grpc://127.0.0.1:9099',
on_stop: 'grpc://127.0.0.1:9099'
}
});
} else {
Expand All @@ -154,7 +158,9 @@ async function createMember(roomId, memberId) {
credentials: { plain: 'test' },
pipeline: pipeline,
on_join: 'grpc://127.0.0.1:9099',
on_leave: 'grpc://127.0.0.1:9099'
on_leave: 'grpc://127.0.0.1:9099',
on_start: 'grpc://127.0.0.1:9099',
on_stop: 'grpc://127.0.0.1:9099'
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions e2e/tests/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ impl World {
)),
on_join: Some("grpc://127.0.0.1:9099".to_owned()),
on_leave: Some("grpc://127.0.0.1:9099".to_owned()),
on_start: Some("grpc://127.0.0.1:9099".to_owned()),
on_stop: Some("grpc://127.0.0.1:9099".to_owned()),
idle_timeout: None,
reconnect_timeout: None,
ping_interval: None,
Expand Down
18 changes: 15 additions & 3 deletions flutter/example/lib/call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,14 @@ class Call {
var resp = await client.create(
roomId,
Room(roomId, {
memberId: Member(memberId, pipeline, Plain('test'),
'grpc://127.0.0.1:9099', 'grpc://127.0.0.1:9099')
memberId: Member(
memberId,
pipeline,
Plain('test'),
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099')
}));
return jsonDecode(resp.body)['sids'][memberId];
}
Expand Down Expand Up @@ -273,7 +279,13 @@ class Call {

var resp = await client.create(
'$roomId/$memberId',
Member(memberId, pipeline, Plain('test'), 'grpc://127.0.0.1:9099',
Member(
memberId,
pipeline,
Plain('test'),
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099'));

if (isPublish) {
Expand Down
10 changes: 8 additions & 2 deletions flutter/example/lib/call_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,14 @@ Future controlApiCreateMemberDialog(BuildContext context, Call call) {
const SizedBox(height: 10),
TextButton(
onPressed: () async {
var member = Member(memberId, {}, Plain(credentials),
'grpc://127.0.0.1:9099', 'grpc://127.0.0.1:9099');
var member = Member(
memberId,
{},
Plain(credentials),
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099');

member.idle_timeout = idle;
member.reconnect_timeout = reconnectTimeout;
Expand Down
11 changes: 10 additions & 1 deletion flutter/example/lib/control_api/entities/member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ class Member {
@JsonKey(includeIfNull: false)
String? on_leave;

/// URL to which [OnStart] Control API callback will be sent.
@JsonKey(includeIfNull: false)
String? on_start;

/// URL to which [OnStop] Control API callback will be sent.
@JsonKey(includeIfNull: false)
String? on_stop;

/// Timeout of receiving heartbeat messages from this [Member] via Client API.
///
/// Once reached, this [Member] is considered being idle.
Expand All @@ -99,7 +107,8 @@ class Member {
/// API.
String? ping_interval;

Member(this.id, this.pipeline, this.credentials, this.on_join, this.on_leave);
Member(this.id, this.pipeline, this.credentials, this.on_join, this.on_leave,
this.on_start, this.on_stop);

factory Member.fromJson(Map<String, dynamic> json) {
json.remove('kind');
Expand Down
4 changes: 4 additions & 0 deletions flutter/example/lib/control_api/entities/member.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions flutter/lib/src/native/ffi/jason_api.g.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ part of 'jason_api.g.dart';
T _$identity<T>(T value) => value;

final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');

/// @nodoc
mixin _$ApiConstrainFacingMode {
Expand Down Expand Up @@ -146,7 +146,7 @@ class _$ApiConstrainFacingMode_ExactImpl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ApiConstrainFacingMode_ExactImpl &&
Expand Down Expand Up @@ -291,7 +291,7 @@ class _$ApiConstrainFacingMode_IdealImpl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ApiConstrainFacingMode_IdealImpl &&
Expand Down Expand Up @@ -518,7 +518,7 @@ class _$ConstrainU32_ExactImpl implements ConstrainU32_Exact {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ConstrainU32_ExactImpl &&
Expand Down Expand Up @@ -662,7 +662,7 @@ class _$ConstrainU32_IdealImpl implements ConstrainU32_Ideal {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ConstrainU32_IdealImpl &&
Expand Down Expand Up @@ -813,7 +813,7 @@ class _$ConstrainU32_RangeImpl implements ConstrainU32_Range {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ConstrainU32_RangeImpl &&
Expand Down
11 changes: 10 additions & 1 deletion flutter/test/e2e/api/member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ class Member {
@JsonKey(includeIfNull: false)
String? on_leave;

/// URL to which [OnStart] Control API callback will be sent.
@JsonKey(includeIfNull: false)
String? on_start;

/// URL to which [OnStop] Control API callback will be sent.
@JsonKey(includeIfNull: false)
String? on_stop;

/// Timeout of receiving heartbeat messages from this [Member] via Client API.
///
/// Once reached, this [Member] is considered being idle.
Expand All @@ -99,7 +107,8 @@ class Member {
/// API.
String? ping_interval;

Member(this.id, this.pipeline, this.credentials, this.on_join, this.on_leave);
Member(this.id, this.pipeline, this.credentials, this.on_join, this.on_leave,
this.on_start, this.on_stop);

factory Member.fromJson(Map<String, dynamic> json) {
json.remove('kind');
Expand Down
10 changes: 8 additions & 2 deletions flutter/test/e2e/world/custom_world.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ class CustomWorld extends FlutterWidgetTesterWorld {
});
}

var createMember = api.Member(builderId, pipeline, api.Plain('test'),
'grpc://127.0.0.1:9099', 'grpc://127.0.0.1:9099');
var createMember = api.Member(
builderId,
pipeline,
api.Plain('test'),
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099',
'grpc://127.0.0.1:9099');
await controlClient.create('$roomId/$builderId', createMember);

if (builder.isSend) {
Expand Down
12 changes: 12 additions & 0 deletions mock/control-api/src/api/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ pub struct Member {
#[serde(skip_serializing_if = "Option::is_none")]
pub on_leave: Option<String>,

/// URL to which `OnStart` Control API callback will be sent.
#[serde(skip_serializing_if = "Option::is_none")]
pub on_start: Option<String>,

/// URL to which `OnStop` Control API callback will be sent.
#[serde(skip_serializing_if = "Option::is_none")]
pub on_stop: Option<String>,

/// Timeout of receiving heartbeat messages from this [`Member`] via Client
/// API. Once reached, the [`Member`] is considered being idle.
#[serde(default, with = "humantime_serde")]
Expand Down Expand Up @@ -69,6 +77,8 @@ impl Member {
credentials: self.credentials.map(Into::into),
on_join: self.on_join.unwrap_or_default(),
on_leave: self.on_leave.unwrap_or_default(),
on_start: self.on_start.unwrap_or_default(),
on_stop: self.on_stop.unwrap_or_default(),
idle_timeout: self.idle_timeout.map(|d| d.try_into().unwrap()),
reconnect_timeout: self
.reconnect_timeout
Expand Down Expand Up @@ -100,6 +110,8 @@ impl From<proto::Member> for Member {
credentials: proto.credentials.map(Into::into),
on_join: Some(proto.on_join).filter(|s| !s.is_empty()),
on_leave: Some(proto.on_leave).filter(|s| !s.is_empty()),
on_start: Some(proto.on_start).filter(|s| !s.is_empty()),
on_stop: Some(proto.on_stop).filter(|s| !s.is_empty()),
idle_timeout: proto.idle_timeout.map(|dur| dur.try_into().unwrap()),
reconnect_timeout: proto
.reconnect_timeout
Expand Down
Loading
Loading