webSocket接口修改;

pull/1/head
戴余标 3 years ago
parent 57734c42fe
commit 74c973a662

@ -31,6 +31,8 @@ class UserProvider extends ChangeNotifier {
if (isLogin) { if (isLogin) {
await updateUserInfo(); await updateUserInfo();
WebSocketUtil().setUser(userInfoModel!.id.toString()); WebSocketUtil().setUser(userInfoModel!.id.toString());
WebSocketUtil().setCommunityCode(userInfoModel!.communityCode);
WebSocketUtil().setNickName(userInfoModel!.nickName!);
WebSocketUtil().startWebSocket(); WebSocketUtil().startWebSocket();
await updateMyHouseInfo(); await updateMyHouseInfo();

@ -169,7 +169,7 @@ int getNum(DateTime dateTime) {
hour = dateTime.hour; hour = dateTime.hour;
minute = dateTime.minute; minute = dateTime.minute;
if (minute > 0) { if (minute > 0) {
return hour * 2; return hour * 2+1;
} }
return hour * 2 + 1; return hour * 2;
} }

@ -1,25 +1,42 @@
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:equatable/equatable.dart';
part 'fire_model.g.dart'; part 'fire_model.g.dart';
@JsonSerializable() @JsonSerializable()
class FireModel { class FireModel extends Equatable {
String? alarmNo; final String? model;
String? alarmType; final String? communityCode;
String? deviceName; final int? alarmType;
String? deviceNo; final String? alarmNo;
String? time; final String? deviceNo;
int? type; final String? deviceName;
final String? time;
final String? alarmContent;
factory FireModel.fromJson(Map<String, dynamic> json) => factory FireModel.fromJson(Map<String, dynamic> json) =>
_$FireModelFromJson(json); _$FireModelFromJson(json);
@override
List<Object?> get props => [
model,
communityCode,
alarmType,
alarmNo,
deviceNo,
deviceName,
time,
alarmContent,
];
FireModel({ FireModel({
this.alarmNo, this.model,
this.communityCode,
this.alarmType, this.alarmType,
this.deviceName, this.alarmNo,
this.deviceNo, this.deviceNo,
this.deviceName,
this.time, this.time,
this.type, this.alarmContent,
}); });
} }

@ -7,10 +7,12 @@ part of 'fire_model.dart';
// ************************************************************************** // **************************************************************************
FireModel _$FireModelFromJson(Map<String, dynamic> json) => FireModel( FireModel _$FireModelFromJson(Map<String, dynamic> json) => FireModel(
model: json['model'] as String?,
communityCode: json['communityCode'] as String?,
alarmType: json['alarmType'] as int?,
alarmNo: json['alarmNo'] as String?, alarmNo: json['alarmNo'] as String?,
alarmType: json['alarmType'] as String?,
deviceName: json['deviceName'] as String?,
deviceNo: json['deviceNo'] as String?, deviceNo: json['deviceNo'] as String?,
deviceName: json['deviceName'] as String?,
time: json['time'] as String?, time: json['time'] as String?,
type: json['type'] as int?, alarmContent: json['alarmContent'] as String?,
); );

@ -7,7 +7,9 @@ import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:aku_new_community/widget/others/user_tool.dart'; import 'package:aku_new_community/widget/others/user_tool.dart';
const String baseUri = 'wss://shop.kaidalai.cn/websocket/app'; // const String baseUri = 'wss://shop.kaidalai.cn/websocket/app';
const String baseUri = 'wss://saas.kaidalai.cn/websocket/app';
enum SOCKETSTATUS { enum SOCKETSTATUS {
CONNECTED, // CONNECTED, //
BREAKOFF, // BREAKOFF, //
@ -27,6 +29,8 @@ class WebSocketUtil {
/// ///
String _user = 'admin'; String _user = 'admin';
String _communityCode = 'communityCode';
String _nickName = 'nickName';
/// ///
SOCKETSTATUS _socketStatus = SOCKETSTATUS.CLOSED; SOCKETSTATUS _socketStatus = SOCKETSTATUS.CLOSED;
@ -86,12 +90,18 @@ class WebSocketUtil {
void setUser(String user) { void setUser(String user) {
this._user = user; this._user = user;
} }
void setCommunityCode(String communityCode) {
this._communityCode = communityCode;
}
void setNickName(String nickName) {
this._nickName = nickName;
}
///websocket ///websocket
void startWebSocket() { void startWebSocket() {
closeWebSocket(); closeWebSocket();
try { try {
_webSocket = IOWebSocketChannel.connect(Uri.parse('$baseUri/$_user')); _webSocket = IOWebSocketChannel.connect(Uri.parse('$baseUri/$_communityCode/$_nickName'));
print('webSocket已连接服务器$baseUri/$_user'); print('webSocket已连接服务器$baseUri/$_user');
_socketStatus = SOCKETSTATUS.CONNECTED; _socketStatus = SOCKETSTATUS.CONNECTED;
endReconnect(); endReconnect();

Loading…
Cancel
Save