Skip to content

Commit

Permalink
feat: missed calls (#694)
Browse files Browse the repository at this point in the history
* [PBE-1710] make example app Firebase friendly

* [PBE-1710] support reject.reason & show notification

* fix ios, improve setup

* support pronto-staging

* write openapi script + generate new API
  • Loading branch information
kanat committed Jun 14, 2024
1 parent 45736c3 commit e3ffefe
Show file tree
Hide file tree
Showing 49 changed files with 1,728 additions and 89 deletions.
33 changes: 33 additions & 0 deletions packages/stream_video/generate-openapi-origin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
set -euo pipefail

OPENAPI_SPEC_PATH="https://raw.githubusercontent.com/GetStream/protocol/main/openapi/video-openapi-clientside.yaml"

OUTPUT_DIR="./lib/open_api/video/coordinator"
TEMP_OUTPUT_DIR="./lib/open_api/video/coordinator_temp"

# Clean previous output
rm -rf $TEMP_OUTPUT_DIR
rm -rf $OUTPUT_DIR

# NOTE: https://openapi-generator.tech/docs/generators/dart/
# Generate the Coordinator API models
docker pull openapitools/openapi-generator-cli
docker run --rm \
-v "${TEMP_OUTPUT_DIR}:/local" openapitools/openapi-generator-cli generate \
-i "$OPENAPI_SPEC_PATH" \
-g dart \
-o /local


# Copy the generated code to the correct location
cp -r $TEMP_OUTPUT_DIR/lib $OUTPUT_DIR

# Write the API version to a file
README_FILE="$TEMP_OUTPUT_DIR/README.md"
API_VERSION=$(grep -i "API version" "$README_FILE" | awk -F ': ' '{print $2}')
OUTPUT_FILE="$OUTPUT_DIR/.api_version"
echo "$API_VERSION" > "$OUTPUT_FILE"

# Remove the generated API client, just keep the models
rm -rf $TEMP_OUTPUT_DIR
33 changes: 33 additions & 0 deletions packages/stream_video/generate-openapi-stream.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
set -euo pipefail

OPENAPI_SPEC_PATH="https://raw.githubusercontent.com/GetStream/protocol/main/openapi/video-openapi-clientside.yaml"

OUTPUT_DIR="./lib/open_api/video/coordinator"
TEMP_OUTPUT_DIR="./lib/open_api/video/coordinator_temp"

# Clean previous output
rm -rf $TEMP_OUTPUT_DIR
rm -rf $OUTPUT_DIR

# NOTE: https://openapi-generator.tech/docs/generators/dart/
# Generate the Coordinator API models
docker pull ghcr.io/getstream/openapi-generator:master
docker run --rm \
-v "${TEMP_OUTPUT_DIR}:/local" ghcr.io/getstream/openapi-generator:master generate \
-i "$OPENAPI_SPEC_PATH" \
-g dart \
-o /local


# Copy the generated code to the correct location
cp -r $TEMP_OUTPUT_DIR/lib $OUTPUT_DIR

# Write the API version to a file
README_FILE="$TEMP_OUTPUT_DIR/README.md"
API_VERSION=$(grep -i "API version" "$README_FILE" | awk -F ': ' '{print $2}')
OUTPUT_FILE="$OUTPUT_DIR/.api_version"
echo "$API_VERSION" > "$OUTPUT_FILE"

# Remove the generated API client, just keep the models
rm -rf $TEMP_OUTPUT_DIR
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v116.0.2
4 changes: 4 additions & 0 deletions packages/stream_video/lib/open_api/video/coordinator/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ part 'model/call_member_added_event.dart';
part 'model/call_member_removed_event.dart';
part 'model/call_member_updated_event.dart';
part 'model/call_member_updated_permission_event.dart';
part 'model/call_missed_event.dart';
part 'model/call_notification_event.dart';
part 'model/call_participant_response.dart';
part 'model/call_reaction_event.dart';
Expand Down Expand Up @@ -128,6 +129,8 @@ part 'model/ice_server.dart';
part 'model/join_call_request.dart';
part 'model/join_call_response.dart';
part 'model/label_thresholds.dart';
part 'model/limits_settings_request.dart';
part 'model/limits_settings_response.dart';
part 'model/list_devices_response.dart';
part 'model/list_recordings_response.dart';
part 'model/list_transcriptions_response.dart';
Expand Down Expand Up @@ -162,6 +165,7 @@ part 'model/reaction_response.dart';
part 'model/read_receipts.dart';
part 'model/record_settings_request.dart';
part 'model/record_settings_response.dart';
part 'model/reject_call_request.dart';
part 'model/reject_call_response.dart';
part 'model/request_permission_request.dart';
part 'model/request_permission_response.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1455,20 +1455,22 @@ class ProductvideoApi {
/// * [String] type (required):
///
/// * [String] id (required):
Future<Response> rejectCallWithHttpInfo(String type, String id,) async {
///
/// * [RejectCallRequest] rejectCallRequest (required):
Future<Response> rejectCallWithHttpInfo(String type, String id, RejectCallRequest rejectCallRequest,) async {
// ignore: prefer_const_declarations
final path = r'/video/call/{type}/{id}/reject'
.replaceAll('{type}', type)
.replaceAll('{id}', id);

// ignore: prefer_final_locals
Object? postBody;
Object? postBody = rejectCallRequest;

final queryParams = <QueryParam>[];
final headerParams = <String, String>{};
final formParams = <String, String>{};

const contentTypes = <String>[];
const contentTypes = <String>['application/json'];


return apiClient.invokeAPI(
Expand All @@ -1491,8 +1493,10 @@ class ProductvideoApi {
/// * [String] type (required):
///
/// * [String] id (required):
Future<RejectCallResponse?> rejectCall(String type, String id,) async {
final response = await rejectCallWithHttpInfo(type, id,);
///
/// * [RejectCallRequest] rejectCallRequest (required):
Future<RejectCallResponse?> rejectCall(String type, String id, RejectCallRequest rejectCallRequest,) async {
final response = await rejectCallWithHttpInfo(type, id, rejectCallRequest,);
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ class ApiClient {
return CallMemberUpdatedEvent.fromJson(value);
case 'CallMemberUpdatedPermissionEvent':
return CallMemberUpdatedPermissionEvent.fromJson(value);
case 'CallMissedEvent':
return CallMissedEvent.fromJson(value);
case 'CallNotificationEvent':
return CallNotificationEvent.fromJson(value);
case 'CallParticipantResponse':
Expand Down Expand Up @@ -378,6 +380,10 @@ class ApiClient {
return JoinCallResponse.fromJson(value);
case 'LabelThresholds':
return LabelThresholds.fromJson(value);
case 'LimitsSettingsRequest':
return LimitsSettingsRequest.fromJson(value);
case 'LimitsSettingsResponse':
return LimitsSettingsResponse.fromJson(value);
case 'ListDevicesResponse':
return ListDevicesResponse.fromJson(value);
case 'ListRecordingsResponse':
Expand Down Expand Up @@ -446,6 +452,8 @@ class ApiClient {
return RecordSettingsRequest.fromJson(value);
case 'RecordSettingsResponse':
return RecordSettingsResponse.fromJson(value);
case 'RejectCallRequest':
return RejectCallRequest.fromJson(value);
case 'RejectCallResponse':
return RejectCallResponse.fromJson(value);
case 'RequestPermissionRequest':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.18

// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars

part of openapi.api;

class CallMissedEvent {
/// Returns a new [CallMissedEvent] instance.
CallMissedEvent({
required this.call,
required this.callCid,
required this.createdAt,
this.members = const [],
required this.sessionId,
this.type = 'call.missed',
required this.user,
});

CallResponse call;

String callCid;

DateTime createdAt;

/// List of members who missed the call
List<MemberResponse> members;

/// Call session ID
String sessionId;

/// The type of event: \"call.notification\" in this case
String type;

UserResponse user;

@override
bool operator ==(Object other) => identical(this, other) || other is CallMissedEvent &&
other.call == call &&
other.callCid == callCid &&
other.createdAt == createdAt &&
_deepEquality.equals(other.members, members) &&
other.sessionId == sessionId &&
other.type == type &&
other.user == user;

@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(call.hashCode) +
(callCid.hashCode) +
(createdAt.hashCode) +
(members.hashCode) +
(sessionId.hashCode) +
(type.hashCode) +
(user.hashCode);

@override
String toString() => 'CallMissedEvent[call=$call, callCid=$callCid, createdAt=$createdAt, members=$members, sessionId=$sessionId, type=$type, user=$user]';

Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'call'] = this.call;
json[r'call_cid'] = this.callCid;
json[r'created_at'] = this.createdAt.toUtc().toIso8601String();
json[r'members'] = this.members;
json[r'session_id'] = this.sessionId;
json[r'type'] = this.type;
json[r'user'] = this.user;
return json;
}

/// Returns a new [CallMissedEvent] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static CallMissedEvent? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();

// Ensure that the map contains the required keys.
// Note 1: the values aren't checked for validity beyond being non-null.
// Note 2: this code is stripped in release mode!
assert(() {
requiredKeys.forEach((key) {
assert(json.containsKey(key), 'Required key "CallMissedEvent[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "CallMissedEvent[$key]" has a null value in JSON.');
});
return true;
}());

return CallMissedEvent(
call: CallResponse.fromJson(json[r'call'])!,
callCid: mapValueOfType<String>(json, r'call_cid')!,
createdAt: mapDateTime(json, r'created_at', r'')!,
members: MemberResponse.listFromJson(json[r'members']),
sessionId: mapValueOfType<String>(json, r'session_id')!,
type: mapValueOfType<String>(json, r'type')!,
user: UserResponse.fromJson(json[r'user'])!,
);
}
return null;
}

static List<CallMissedEvent> listFromJson(dynamic json, {bool growable = false,}) {
final result = <CallMissedEvent>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = CallMissedEvent.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}

static Map<String, CallMissedEvent> mapFromJson(dynamic json) {
final map = <String, CallMissedEvent>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = CallMissedEvent.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}

// maps a json object with a list of CallMissedEvent-objects as value to a dart map
static Map<String, List<CallMissedEvent>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<CallMissedEvent>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = CallMissedEvent.listFromJson(entry.value, growable: growable,);
}
}
return map;
}

/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'call',
'call_cid',
'created_at',
'members',
'session_id',
'type',
'user',
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CallRejectedEvent {
required this.call,
required this.callCid,
required this.createdAt,
this.reason,
this.type = 'call.rejected',
required this.user,
});
Expand All @@ -26,6 +27,14 @@ class CallRejectedEvent {

DateTime createdAt;

///
/// Please note: This property should have been non-nullable! Since the specification file
/// does not include a default value (using the "default:" property), however, the generated
/// source code must fall back to having a nullable type.
/// Consider adding a "default:" property in the specification file to hide this note.
///
String? reason;

/// The type of event: \"call.rejected\" in this case
String type;

Expand All @@ -36,6 +45,7 @@ class CallRejectedEvent {
other.call == call &&
other.callCid == callCid &&
other.createdAt == createdAt &&
other.reason == reason &&
other.type == type &&
other.user == user;

Expand All @@ -45,17 +55,23 @@ class CallRejectedEvent {
(call.hashCode) +
(callCid.hashCode) +
(createdAt.hashCode) +
(reason == null ? 0 : reason!.hashCode) +
(type.hashCode) +
(user.hashCode);

@override
String toString() => 'CallRejectedEvent[call=$call, callCid=$callCid, createdAt=$createdAt, type=$type, user=$user]';
String toString() => 'CallRejectedEvent[call=$call, callCid=$callCid, createdAt=$createdAt, reason=$reason, type=$type, user=$user]';

Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'call'] = this.call;
json[r'call_cid'] = this.callCid;
json[r'created_at'] = this.createdAt.toUtc().toIso8601String();
if (this.reason != null) {
json[r'reason'] = this.reason;
} else {
json[r'reason'] = null;
}
json[r'type'] = this.type;
json[r'user'] = this.user;
return json;
Expand Down Expand Up @@ -83,6 +99,7 @@ class CallRejectedEvent {
call: CallResponse.fromJson(json[r'call'])!,
callCid: mapValueOfType<String>(json, r'call_cid')!,
createdAt: mapDateTime(json, r'created_at', r'')!,
reason: mapValueOfType<String>(json, r'reason'),
type: mapValueOfType<String>(json, r'type')!,
user: UserResponse.fromJson(json[r'user'])!,
);
Expand Down
Loading

0 comments on commit e3ffefe

Please sign in to comment.