|
|
@@ -1,6 +1,7 @@
|
|
|
import 'dart:async';
|
|
|
import 'dart:convert';
|
|
|
|
|
|
+import 'package:flutter_map/src/entity/map_location.dart';
|
|
|
import 'package:injectable/injectable.dart';
|
|
|
import 'package:location/data/repositories/friends_repository.dart';
|
|
|
import 'package:location/di/get_it.dart';
|
|
|
@@ -14,6 +15,7 @@ import '../data/bean/location_info.dart';
|
|
|
import '../data/repositories/account_repository.dart';
|
|
|
import '../data/repositories/contact_repository.dart';
|
|
|
import '../data/repositories/message_repository.dart';
|
|
|
+import 'location_message.dart';
|
|
|
|
|
|
typedef OnLocationChangeListener = void Function(List<LocationInfo> data);
|
|
|
|
|
|
@@ -28,13 +30,7 @@ class AtmobLocationClient {
|
|
|
bool _isConnecting = false;
|
|
|
CancelableFuture? cancelableFuture;
|
|
|
|
|
|
- FriendsRepository friendsRepository;
|
|
|
- MessageRepository messageRepository;
|
|
|
- ContactRepository contactRepository;
|
|
|
- AccountRepository accountRepository;
|
|
|
-
|
|
|
- AtmobLocationClient(this.friendsRepository, this.messageRepository,
|
|
|
- this.contactRepository, this.accountRepository) {
|
|
|
+ AtmobLocationClient() {
|
|
|
startWebsocketInternal();
|
|
|
}
|
|
|
|
|
|
@@ -123,19 +119,19 @@ class AtmobLocationClient {
|
|
|
}
|
|
|
switch (message.cmd) {
|
|
|
case SocketConstants.refreshFriendList:
|
|
|
- friendsRepository.refreshFriends();
|
|
|
+ FriendsRepository.getInstance().refreshFriends();
|
|
|
break;
|
|
|
case SocketConstants.refreshFriendRequest:
|
|
|
- friendsRepository.refreshFriendRequestList();
|
|
|
+ FriendsRepository.getInstance().refreshFriendRequestList();
|
|
|
break;
|
|
|
case SocketConstants.refreshFriendMessage:
|
|
|
- messageRepository.requestMessageList();
|
|
|
+ MessageRepository.getInstance().requestMessageList();
|
|
|
break;
|
|
|
case SocketConstants.refreshContact:
|
|
|
- messageRepository.refreshContactList();
|
|
|
+ ContactRepository.getInstance().refreshContactList();
|
|
|
break;
|
|
|
case SocketConstants.refreshMember:
|
|
|
- accountRepository.refreshMemberStatus();
|
|
|
+ AccountRepository.getInstance().refreshMemberStatus();
|
|
|
break;
|
|
|
}
|
|
|
return SocketConstants.receiveFriendBatchLocation == message.cmd;
|
|
|
@@ -203,4 +199,20 @@ class AtmobLocationClient {
|
|
|
static void removeLocationListener(OnLocationChangeListener listener) {
|
|
|
_locationListeners.remove(listener);
|
|
|
}
|
|
|
+
|
|
|
+ void _sendMessage(String msg) {
|
|
|
+ if (_webSocket == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ _webSocket!.sink.add(msg);
|
|
|
+ AtmobLog.d(tag, 'send location: $msg');
|
|
|
+ }
|
|
|
+
|
|
|
+ void uploadLocation(MapLocation location) {
|
|
|
+ if (_webSocket == null ||
|
|
|
+ location.latitude == 0 && location.longitude == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ _sendMessage(LocationMessage.obtainMessage(location));
|
|
|
+ }
|
|
|
}
|