Skip to content

Commit 3946c0c

Browse files
committed
Merge branch 'master' into prod
2 parents aac2e06 + 52bd1b5 commit 3946c0c

File tree

7 files changed

+54
-19
lines changed

7 files changed

+54
-19
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.0.4
2+
3+
* Add `strictMode` to `CKConfiguration`
4+
* Fix(web): Instance duplication on getting singleton in web implementation.
5+
* update docs
6+
17
## 0.0.3+1
28

39
* BREAKING CHANGE: Use `WebCallKitWeb` instead of `WebCallKit`.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ The following described scenarios are valid DisconnectResponses for specific cal
123123
| disconnecting | local, remote, unknown, error, |
124124
| disconnected | local, remote, unknown, error, |
125125

126+
if `strictMode` is enabled, the following valid `DisconnectResponse`s will be considered, else it will be rejected (and potentially thrown) in a future update.
127+
126128
#### Notification Integration
127129

128130
t.b.c.

lib/src/managers/calls/call_manager.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,12 @@ class CallManager {
125125
tag: tag);
126126
return;
127127
}
128+
final c = call.copyWith(
129+
state: CKCallState.disconnected,
130+
);
131+
_calls[uuid] = c;
128132

129-
final event = DisconnectCallEvent.reason(call, response: response);
133+
final event = DisconnectCallEvent.reason(c, response: response);
130134
_addEvent(event);
131135
}
132136

lib/src/models/config/ck_configuration.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class CKConfiguration {
1111
final Set<CKCallAttributes> attributes;
1212
final CKTimer timer;
1313
final bool notifyOnCallEnd;
14+
final bool notifyOnMissedCall;
1415
final Map<CKCallAction, String> icons;
16+
final bool strictMode;
1517
// final bool repostOnClick;
1618

1719
const CKConfiguration({
@@ -20,13 +22,15 @@ class CKConfiguration {
2022
this.attributes = const {},
2123
this.timer = const CKTimer(),
2224
this.notifyOnCallEnd = true,
25+
this.notifyOnMissedCall = true,
2326
this.icons = const {},
27+
this.strictMode = true,
2428
// this.repostOnClick = true,
2529
});
2630

2731
@override
2832
String toString() {
2933
// return 'CKConfiguration{sounds: $sounds, capabilities: $capabilities, attributes: $attributes, timer: $timer, notifyOnCallEnd: $notifyOnCallEnd, repostOnClick: $repostOnClick}';
30-
return 'CKConfiguration{sounds: $sounds, capabilities: $capabilities, attributes: $attributes, timer: $timer, notifyOnCallEnd: $notifyOnCallEnd, icons: $icons}';
34+
return 'CKConfiguration{sounds: $sounds, capabilities: $capabilities, attributes: $attributes, timer: $timer, notifyOnCallEnd: $notifyOnCallEnd, icons: $icons, strictMode: $strictMode, notifyOnMissedCall: $notifyOnMissedCall}';
3135
}
3236
}

lib/web_callkit_web.dart

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class WebCallkitWeb extends WebCallkitPlatform {
4141
static WebCallkitWeb get instance => _instance;
4242

4343
static void registerWith(Registrar registrar) {
44-
WebCallkitPlatform.instance = WebCallkitWeb._internal();
44+
WebCallkitPlatform.instance = _instance;
4545
}
4646

4747
final Map<String, CallTimer> _timers = {};
@@ -222,10 +222,14 @@ class WebCallkitWeb extends WebCallkitPlatform {
222222
printDebug("Call with uuid: $uuid not found.", tag: tag);
223223
return;
224224
}
225-
final validResponses = validCallStateDisconnectResponses[call.state] ?? CKDisconnectResponse.values;
226-
if (!validResponses.contains(response)) {
227-
printWarning("Invalid response for call state: ${call.state}", tag: tag);
228-
return;
225+
if (_configuration.strictMode) {
226+
final validResponses = validCallStateDisconnectResponses[call.state] ?? CKDisconnectResponse.values;
227+
if (!validResponses.contains(response)) {
228+
printWarning("Invalid response for call state: ${call.state}", tag: tag);
229+
return;
230+
}
231+
} else {
232+
printDebug("Strict mode disabled. Ignoring valid disconnect call state check.", tag: tag);
229233
}
230234
_callManager.removeCall(uuid, response: response);
231235
}
@@ -602,6 +606,17 @@ class WebCallkitWeb extends WebCallkitPlatform {
602606
if (event is DisconnectCallEvent) {
603607
_onDisconnectListener?.call(event.uuid, event.response, CKActionSource.api);
604608
}
609+
bool isMissedCall = event is DisconnectCallEvent ? event.response == CKDisconnectResponse.missed : false;
610+
if(_configuration.notifyOnCallEnd && !isMissedCall) {
611+
final notification = _notificationManager.getNotification(event.uuid);
612+
final n = _generateNotification(call: call, capabilities: call.capabilities, metadata: notification?.metadata, requireInteraction: false);
613+
await _notificationManager.add(n, flags: {});
614+
}
615+
if(_configuration.notifyOnMissedCall && isMissedCall) {
616+
final notification = _notificationManager.getNotification(event.uuid);
617+
final n = _generateNotification(call: call, capabilities: call.capabilities, metadata: notification?.metadata, description: "Missed Call", requireInteraction: false);
618+
await _notificationManager.add(n, flags: {});
619+
}
605620
_stopCallTimer(id);
606621
break;
607622
}
@@ -708,9 +723,11 @@ class WebCallkitWeb extends WebCallkitPlatform {
708723
//ignore: unused_element
709724
Duration? offset,
710725
bool? silent,
726+
String? description,
727+
bool? requireInteraction,
711728
}) {
712729
final title = _getTitle(call);
713-
final body = _getDescription(call);
730+
final body = description ?? _getDescription(call);
714731
final actions = _getActions(call);
715732
final icon = _getIcon(call);
716733

@@ -722,7 +739,7 @@ class WebCallkitWeb extends WebCallkitPlatform {
722739
actions: actions,
723740
icon: icon,
724741
silent: silent,
725-
requireInteraction: true,
742+
requireInteraction: requireInteraction ?? true,
726743
renotify: true,
727744
data: call.data,
728745
timestamp: currentTime.millisecondsSinceEpoch,

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dev_dependencies:
3131
sdk: flutter
3232
flutter_lints: ^3.0.0
3333
test: ^1.25.2
34+
matcher: ^0.12.17
3435

3536
# For information on the generic Dart part of this file, see the
3637
# following page: https://dart.dev/tools/pub/pubspec

test/web_callkit_method_channel_test.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:web_callkit/src/core/enums/ck_call_state.dart';
55
import 'package:web_callkit/src/core/enums/ck_call_type.dart';
66
import 'package:web_callkit/src/method_channel/web_callkit_method_channel.dart';
77
import 'package:web_callkit/src/models/call/ck_call.dart';
8+
import 'package:matcher/matcher.dart' as matcher;
89

910
void main() {
1011
TestWidgetsFlutterBinding.ensureInitialized();
@@ -34,11 +35,11 @@ void main() {
3435
final call = CKCall.init(uuid: id, localizedName: name);
3536
expect(call.uuid, id, reason: 'Call uuid should be $id');
3637
expect(call.localizedName, name, reason: 'Call name should be $name');
37-
expect(call.dateStarted, isNotNull,
38+
expect(call.dateStarted, matcher.isNotNull,
3839
reason: 'Call dateStarted should not be null');
39-
expect(call.dateUpdated, isNotNull,
40+
expect(call.dateUpdated, matcher.isNotNull,
4041
reason: 'Call dateUpdated should not be null');
41-
expect(call.attributes, isNotNull,
42+
expect(call.attributes, matcher.isNotNull,
4243
reason: 'Call attributes should not be null');
4344
expect(call.callType, CKCallType.audio,
4445
reason: 'Call callType should be audio');
@@ -71,7 +72,7 @@ void main() {
7172
final dateStarted = call.dateStarted;
7273
final copyWith = call.copyWith(dateStarted: DateTime.now());
7374
final newDateStarted = copyWith.dateStarted;
74-
expect(dateStarted, isNot(newDateStarted),
75+
expect(dateStarted, matcher.isNot(newDateStarted),
7576
reason: 'Call dateStarted should not be equal to new dateStarted');
7677
});
7778

@@ -151,7 +152,7 @@ void main() {
151152
await platform
152153
.updateCallAttributes('123', attributes: {CKCallAttributes.hold});
153154
final call = platform.getCall('123');
154-
expect(call, isNull, reason: 'Call should be null');
155+
expect(call, matcher.isNull, reason: 'Call should be null');
155156
});
156157

157158
test('updateCallAttributes: perform hold toggle', () async {
@@ -166,7 +167,7 @@ void main() {
166167
await platform.updateCallAttributes(id, attributes: {});
167168
final notholding = platform.getCall(id);
168169

169-
expect(call, isNotNull, reason: 'Call should not be null');
170+
expect(call, matcher.isNotNull, reason: 'Call should not be null');
170171
expect(call!.isHolding, false, reason: 'Call should not be holding');
171172
expect(holding!.isHolding, true, reason: 'Call should be holding');
172173
expect(notholding!.isHolding, true,
@@ -180,7 +181,7 @@ void main() {
180181
test('updateCallStatus: does not exist', () async {
181182
await platform.updateCallStatus('123', callStatus: CKCallState.active);
182183
final call = platform.getCall('123');
183-
expect(call, isNull, reason: 'Call should be null');
184+
expect(call, matcher.isNull, reason: 'Call should be null');
184185
});
185186

186187
test('updateCallStatus: ringing to active to ended', () async {
@@ -194,16 +195,16 @@ void main() {
194195
await platform.updateCallStatus(id, callStatus: CKCallState.disconnected);
195196
final disconnected = platform.getCall(id);
196197

197-
expect(call, isNotNull, reason: 'Call should not be null');
198+
expect(call, matcher.isNotNull, reason: 'Call should not be null');
198199
expect(call!.uuid, '123', reason: 'Call uuid should be "123"');
199200
expect(call.localizedName, "handle",
200201
reason: 'Call handle should be "handle"');
201202

202-
expect(active, isNotNull, reason: 'Call active should not be null');
203+
expect(active, matcher.isNotNull, reason: 'Call active should not be null');
203204
expect(active!.state, CKCallState.active,
204205
reason: 'Call state should be active');
205206

206-
expect(disconnected, isNotNull,
207+
expect(disconnected, matcher.isNotNull,
207208
reason: 'Call disconnected should not be null');
208209
expect(disconnected!.state, CKCallState.disconnected,
209210
reason: 'Call state should be disconnected');

0 commit comments

Comments
 (0)