Skip to content

Commit

Permalink
FLUT-144/Fix-datetime-formatting (#1630)
Browse files Browse the repository at this point in the history
* updated parsing

* Added date time handling for android

* Fixed datetime bug

* Update HMSPeer object

* Added suggested changes

---------

Co-authored-by: Yogesh Singh <[email protected]>
  • Loading branch information
Decoder07 and ygit authored Nov 8, 2023
1 parent 020ad13 commit f2b1db7
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 94 deletions.
9 changes: 4 additions & 5 deletions packages/hms_room_kit/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,10 @@ packages:
hmssdk_flutter:
dependency: transitive
description:
name: hmssdk_flutter
sha256: "370556fc44ccb950508f9ec67a47285fd901fc2ecce7d0008f0a25e8bbd08389"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
path: "../../hmssdk_flutter"
relative: true
source: path
version: "1.9.2"
http:
dependency: transitive
description:
Expand Down
9 changes: 4 additions & 5 deletions packages/hms_room_kit/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,10 @@ packages:
hmssdk_flutter:
dependency: "direct main"
description:
name: hmssdk_flutter
sha256: "370556fc44ccb950508f9ec67a47285fd901fc2ecce7d0008f0a25e8bbd08389"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
path: "../hmssdk_flutter"
relative: true
source: path
version: "1.9.2"
http:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion packages/hms_room_kit/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ dependencies:
flutter:
sdk: flutter

hmssdk_flutter: ^1.9.1
hmssdk_flutter:
path: ../hmssdk_flutter
intl: ^0.18.1
permission_handler: ^11.0.0
provider: ^6.0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class HMSPeerExtension {
args["audio_track"] = HMSTrackExtension.toDictionary(peer.audioTrack)
args["video_track"] = HMSTrackExtension.toDictionary(peer.videoTrack)
args["network_quality"] = HMSNetworkQualityExtension.toDictionary(peer.networkQuality)
args["joined_at"] = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(peer.joinedAt).toString()
args["joined_at"] = peer.joinedAt

val auxTrackList = ArrayList<Any>()
peer.auxiliaryTracks.forEach {
Expand Down
10 changes: 5 additions & 5 deletions packages/hmssdk_flutter/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ PODS:
- HMSBroadcastExtensionSDK (0.0.9)
- HMSHLSPlayerSDK (0.0.2):
- HMSAnalyticsSDK (= 0.0.2)
- HMSSDK (1.1.0):
- HMSSDK (1.2.0):
- HMSAnalyticsSDK (= 0.0.2)
- HMSWebRTC (= 1.0.5116)
- hmssdk_flutter (1.9.1):
- hmssdk_flutter (1.9.2):
- Flutter
- HMSBroadcastExtensionSDK (= 0.0.9)
- HMSHLSPlayerSDK (= 0.0.2)
- HMSSDK (= 1.1.0)
- HMSSDK (= 1.2.0)
- HMSWebRTC (1.0.5116)
- MTBBarcodeScanner (5.0.11)
- nanopb (2.30909.1):
Expand Down Expand Up @@ -235,8 +235,8 @@ SPEC CHECKSUMS:
HMSAnalyticsSDK: 4d2a88a729b1eb42f3d25f217c28937ec318a5b7
HMSBroadcastExtensionSDK: d80fe325f6c928bd8e5176290b5a4b7ae15d6fbb
HMSHLSPlayerSDK: 6a54ad4d12f3dc2270d1ecd24019d71282a4f6a3
HMSSDK: 49e3ac665ceb8904d41787ddf99742e8d7d6529a
hmssdk_flutter: 6c69bfe89445350e9cd8d1c37a72808aedfbdf02
HMSSDK: 010fdd904b8d221bb297864800503132fd721d9e
hmssdk_flutter: 1d4cfbb745095ebf399eaf533b6cde0c2006d6e1
HMSWebRTC: ae54e9dd91b869051b283b43b14f57d43b7bf8e1
MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb
nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5
Expand Down
9 changes: 4 additions & 5 deletions packages/hmssdk_flutter/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,10 @@ packages:
hmssdk_flutter:
dependency: transitive
description:
name: hmssdk_flutter
sha256: "370556fc44ccb950508f9ec67a47285fd901fc2ecce7d0008f0a25e8bbd08389"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
path: ".."
relative: true
source: path
version: "1.9.2"
http:
dependency: transitive
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class HMSPeerExtension {
"is_hand_raised": peer.isHandRaised,
"customer_description": peer.metadata ?? "",
"customer_user_id": peer.customerUserID ?? "",
"joined_at": "\(peer.joinedAt)",
"updated_at": "\(peer.updatedAt)"
"joined_at": Int(peer.joinedAt.timeIntervalSince1970 * 1000),
"updated_at": Int(peer.updatedAt.timeIntervalSince1970 * 1000)
] as [String: Any]

if let metadata = peer.metadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class HMSHLSCue {

factory HMSHLSCue.fromMap(Map map) {
return HMSHLSCue(
startDate: HMSDateExtension.convertDate(map["start_date"]),
startDate: HMSDateExtension.convertDateFromString(map["start_date"]),
endDate: map["end_date"] == null
? null
: HMSDateExtension.convertDate(map["end_date"]),
: HMSDateExtension.convertDateFromString(map["end_date"]),
id: map["id"],
payload: map["payload"]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HMSBrowserRecordingState {
error: map["error"] != null ? HMSException.fromMap(map) : null,
running: map['running'],
startedAt: map['started_at'] != null
? HMSDateExtension.convertDate(map['started_at'])
? HMSDateExtension.convertDateFromString(map['started_at'])
: null,
initialising: map['initialising']);
}
Expand Down
19 changes: 18 additions & 1 deletion packages/hmssdk_flutter/lib/src/model/hms_date_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@
///
///[HMSDateExtension] is used to convert android and ios native time format to DateTime type
///in local time zone format.
///Dart imports
import 'dart:developer';

class HMSDateExtension {
static DateTime convertDate(String date) {
///Returns DateTime object from String
static DateTime convertDateFromString(String date) {
DateTime _dateTime = DateTime.parse(date).toLocal();
return _dateTime;
}

///Returns optional DateTime object from epoch in milliseconds
static DateTime? convertDateFromEpoch(int date) {
try {
DateTime _dateTime =
DateTime.fromMillisecondsSinceEpoch(date, isUtc: false);
return _dateTime;
} catch (e) {
log(e.toString());
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HMSHLSRecordingState {
: null,
running: map['running'],
startedAt: map['started_at'] != null
? HMSDateExtension.convertDate(map['started_at'])
? HMSDateExtension.convertDateFromString(map['started_at'])
: null);
}
}
2 changes: 1 addition & 1 deletion packages/hmssdk_flutter/lib/src/model/hms_hls_variant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class HMSHLSVariant {
meetingUrl: map['meeting_url'] as String?,
metadata: map['metadata'] as String?,
startedAt: map['started_at'] != null
? HMSDateExtension.convertDate(map['started_at'])
? HMSDateExtension.convertDateFromString(map['started_at'])
: null,
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/hmssdk_flutter/lib/src/model/hms_local_peer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class HMSLocalPeer extends HMSPeer {
? HMSNetworkQuality.fromMap(map["network_quality"])
: null,
joinedAt: map.containsKey("joined_at")
? HMSDateExtension.convertDate(map["joined_at"])
? HMSDateExtension.convertDateFromEpoch(map["joined_at"])
: null,
updatedAt: map.containsKey("updated_at")
? HMSDateExtension.convertDate(map["updated_at"])
? HMSDateExtension.convertDateFromEpoch(map["updated_at"])
: null,
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hmssdk_flutter/lib/src/model/hms_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HMSMessage {
sender: sender,
message: messageMap['message'] as String,
type: messageMap['type'] as String,
time: HMSDateExtension.convertDate(messageMap['time']),
time: HMSDateExtension.convertDateFromString(messageMap['time']),
hmsMessageRecipient: recipient);
}

Expand Down
59 changes: 3 additions & 56 deletions packages/hmssdk_flutter/lib/src/model/hms_peer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Project imports:
import 'package:hmssdk_flutter/hmssdk_flutter.dart';
import 'package:hmssdk_flutter/src/model/hms_date_extension.dart';
import 'package:hmssdk_flutter/src/service/platform_service.dart';

///100ms HMSPeer.
Expand Down Expand Up @@ -80,61 +79,9 @@ class HMSPeer {
int get hashCode => peerId.hashCode;

factory HMSPeer.fromMap(Map map) {
HMSRole role = HMSRole.fromMap(map['role']);

// TODO: add auxiliary tracks

HMSPeer peer = (map['is_local'] == true)
? HMSLocalPeer(
peerId: map['peer_id'],
name: map['name'],
isLocal: map['is_local'],
isHandRaised: map['is_hand_raised'],
role: role,
metadata: map['metadata'],
customerUserId: map['customer_user_id'],
networkQuality: map['network_quality'] == null
? null
: HMSNetworkQuality.fromMap(
map['network_quality'],
),
joinedAt: map.containsKey("joined_at")
? HMSDateExtension.convertDate(map["joined_at"])
: null,
updatedAt: map.containsKey("updated_at")
? HMSDateExtension.convertDate(map["updated_at"])
: null,
)
: HMSRemotePeer(
peerId: map['peer_id'],
name: map['name'],
isLocal: map['is_local'],
isHandRaised: map['is_hand_raised'],
role: role,
metadata: map['metadata'],
customerUserId: map['customer_user_id'],
networkQuality: map['network_quality'] == null
? null
: HMSNetworkQuality.fromMap(map['network_quality']),
joinedAt: map.containsKey("joined_at")
? HMSDateExtension.convertDate(map["joined_at"])
: null,
updatedAt: map.containsKey("updated_at")
? HMSDateExtension.convertDate(map["updated_at"])
: null,
);

if (map['audio_track'] != null) {
peer.audioTrack = HMSAudioTrack.fromMap(
map: map['audio_track']!, isLocal: peer.isLocal);
}

if (map['video_track'] != null) {
peer.videoTrack = HMSVideoTrack.fromMap(
map: map['video_track']!, isLocal: peer.isLocal);
}

return peer;
return (map['is_local'] == true)
? HMSLocalPeer.fromMap(map)
: HMSRemotePeer.fromMap(map);
}

@override
Expand Down
5 changes: 2 additions & 3 deletions packages/hmssdk_flutter/lib/src/model/hms_remote_peer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class HMSRemotePeer extends HMSPeer {

factory HMSRemotePeer.fromMap(Map map) {
HMSRole role = HMSRole.fromMap(map['role']);
// TODO: add auxiliary tracks
HMSRemotePeer peer = HMSRemotePeer(
peerId: map['peer_id'],
name: map['name'],
Expand All @@ -76,10 +75,10 @@ class HMSRemotePeer extends HMSPeer {
? HMSNetworkQuality.fromMap(map["network_quality"])
: null,
joinedAt: map.containsKey("joined_at")
? HMSDateExtension.convertDate(map["joined_at"])
? HMSDateExtension.convertDateFromEpoch(map["joined_at"])
: null,
updatedAt: map.containsKey("updated_at")
? HMSDateExtension.convertDate(map["updated_at"])
? HMSDateExtension.convertDateFromEpoch(map["updated_at"])
: null,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class HMSRtmpStreamingState {
error: map["error"] != null ? HMSException.fromMap(map) : null,
running: map['running'],
startedAt: map['started_at'] != null
? HMSDateExtension.convertDate(map['started_at'])
? HMSDateExtension.convertDateFromString(map['started_at'])
: null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HMSServerRecordingState {
error: map["error"] != null ? HMSException.fromMap(map) : null,
running: map['running'],
startedAt: map['started_at'] != null
? HMSDateExtension.convertDate(map['started_at'])
? HMSDateExtension.convertDateFromString(map['started_at'])
: null);
}
}

0 comments on commit f2b1db7

Please sign in to comment.