webSocket接口修改;

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

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

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

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

@ -7,10 +7,12 @@ part of 'fire_model.dart';
// **************************************************************************
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?,
alarmType: json['alarmType'] as String?,
deviceName: json['deviceName'] as String?,
deviceNo: json['deviceNo'] as String?,
deviceName: json['deviceName'] 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';
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 {
CONNECTED, //
BREAKOFF, //
@ -27,6 +29,8 @@ class WebSocketUtil {
///
String _user = 'admin';
String _communityCode = 'communityCode';
String _nickName = 'nickName';
///
SOCKETSTATUS _socketStatus = SOCKETSTATUS.CLOSED;
@ -86,12 +90,18 @@ class WebSocketUtil {
void setUser(String user) {
this._user = user;
}
void setCommunityCode(String communityCode) {
this._communityCode = communityCode;
}
void setNickName(String nickName) {
this._nickName = nickName;
}
///websocket
void startWebSocket() {
closeWebSocket();
try {
_webSocket = IOWebSocketChannel.connect(Uri.parse('$baseUri/$_user'));
_webSocket = IOWebSocketChannel.connect(Uri.parse('$baseUri/$_communityCode/$_nickName'));
print('webSocket已连接服务器$baseUri/$_user');
_socketStatus = SOCKETSTATUS.CONNECTED;
endReconnect();

Loading…
Cancel
Save