feat: GeViScope SDK integration with C# Bridge and Flutter app

- Add GeViScope Bridge (C# .NET 8.0) on port 7720
  - Full SDK wrapper for camera control, PTZ, actions/events
  - 17 REST API endpoints for GeViScope server interaction
  - Support for MCS (Media Channel Simulator) with 16 test channels
  - Real-time action/event streaming via PLC callbacks

- Add GeViServer Bridge (C# .NET 8.0) on port 7710
  - Integration with GeViSoft orchestration layer
  - Input/output control and event management

- Update Python API with new routers
  - /api/geviscope/* - Proxy to GeViScope Bridge
  - /api/geviserver/* - Proxy to GeViServer Bridge
  - /api/excel/* - Excel import functionality

- Add Flutter app GeViScope integration
  - GeViScopeRemoteDataSource with 17 API methods
  - GeViScopeBloc for state management
  - GeViScopeScreen with PTZ controls
  - App drawer navigation to GeViScope

- Add SDK documentation (extracted from PDFs)
  - GeViScope SDK docs (7 parts + action reference)
  - GeViSoft SDK docs (12 chunks)

- Add .mcp.json for Claude Code MCP server config

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Administrator
2026-01-19 08:14:17 +01:00
parent c9e83e4277
commit a92b909539
76 changed files with 62101 additions and 176 deletions

View File

@@ -0,0 +1,499 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../data/data_sources/remote/geviscope_remote_data_source.dart';
import 'geviscope_event.dart';
import 'geviscope_state.dart';
class GeViScopeBloc extends Bloc<GeViScopeEvent, GeViScopeState> {
final GeViScopeRemoteDataSource remoteDataSource;
GeViScopeBloc({required this.remoteDataSource})
: super(const GeViScopeState()) {
on<ConnectGeViScopeEvent>(_onConnect);
on<DisconnectGeViScopeEvent>(_onDisconnect);
on<CheckGeViScopeStatusEvent>(_onCheckStatus);
on<LoadChannelsEvent>(_onLoadChannels);
on<RefreshChannelsEvent>(_onRefreshChannels);
on<SendGeViScopeCrossSwitchEvent>(_onSendCrossSwitch);
on<CameraPanEvent>(_onCameraPan);
on<CameraTiltEvent>(_onCameraTilt);
on<CameraZoomEvent>(_onCameraZoom);
on<CameraStopEvent>(_onCameraStop);
on<CameraPresetEvent>(_onCameraPreset);
on<GeViScopeCloseContactEvent>(_onCloseContact);
on<GeViScopeOpenContactEvent>(_onOpenContact);
on<SendGeViScopeCustomActionEvent>(_onSendCustomAction);
on<SendGeViScopeActionEvent>(_onSendAction);
on<ClearGeViScopeActionResultEvent>(_onClearActionResult);
}
Future<void> _onConnect(
ConnectGeViScopeEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(
connectionStatus: GeViScopeConnectionStatus.connecting,
isLoading: true,
clearErrorMessage: true,
));
try {
final result = await remoteDataSource.connect(
address: event.address,
username: event.username,
password: event.password,
);
if (result['success'] == true) {
emit(state.copyWith(
connectionStatus: GeViScopeConnectionStatus.connected,
serverAddress: event.address,
username: event.username,
channelCount: result['channelCount'] ?? 0,
connectedAt: DateTime.now(),
isLoading: false,
lastActionResult: 'Connected to GeViScope at ${event.address}',
lastActionSuccess: true,
));
// Auto-load channels after connection
add(const LoadChannelsEvent());
} else {
emit(state.copyWith(
connectionStatus: GeViScopeConnectionStatus.error,
isLoading: false,
errorMessage: result['message'] ?? result['error'] ?? 'Connection failed',
lastActionResult: result['message'] ?? result['error'] ?? 'Connection failed',
lastActionSuccess: false,
));
}
} catch (e) {
emit(state.copyWith(
connectionStatus: GeViScopeConnectionStatus.error,
isLoading: false,
errorMessage: e.toString(),
lastActionResult: 'Connection error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onDisconnect(
DisconnectGeViScopeEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
await remoteDataSource.disconnect();
emit(state.copyWith(
connectionStatus: GeViScopeConnectionStatus.disconnected,
isLoading: false,
channelCount: 0,
channels: const [],
clearServerAddress: true,
clearUsername: true,
clearConnectedAt: true,
lastActionResult: 'Disconnected from GeViScope',
lastActionSuccess: true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
errorMessage: e.toString(),
lastActionResult: 'Disconnect error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onCheckStatus(
CheckGeViScopeStatusEvent event,
Emitter<GeViScopeState> emit,
) async {
try {
final result = await remoteDataSource.getStatus();
final isConnected = result['is_connected'] == true;
emit(state.copyWith(
connectionStatus: isConnected
? GeViScopeConnectionStatus.connected
: GeViScopeConnectionStatus.disconnected,
serverAddress: result['address']?.toString(),
username: result['username']?.toString(),
channelCount: result['channel_count'] ?? 0,
));
} catch (e) {
emit(state.copyWith(
connectionStatus: GeViScopeConnectionStatus.error,
errorMessage: e.toString(),
));
}
}
Future<void> _onLoadChannels(
LoadChannelsEvent event,
Emitter<GeViScopeState> emit,
) async {
try {
final result = await remoteDataSource.getChannels();
if (result['channels'] != null) {
final channelsList = (result['channels'] as List)
.map((c) => MediaChannel.fromJson(c as Map<String, dynamic>))
.toList();
emit(state.copyWith(
channels: channelsList,
channelCount: result['count'] ?? channelsList.length,
));
}
} catch (e) {
emit(state.copyWith(
lastActionResult: 'Load channels error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onRefreshChannels(
RefreshChannelsEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
await remoteDataSource.refreshChannels();
add(const LoadChannelsEvent());
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Channels refreshed',
lastActionSuccess: true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Refresh channels error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onSendCrossSwitch(
SendGeViScopeCrossSwitchEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.crossSwitch(
videoInput: event.videoInput,
videoOutput: event.videoOutput,
switchMode: event.switchMode,
);
final message = 'CrossSwitch(${event.videoInput}, ${event.videoOutput}, ${event.switchMode})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'CrossSwitch sent successfully'
: result['message'] ?? 'CrossSwitch failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'CrossSwitch error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onCameraPan(
CameraPanEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.cameraPan(
camera: event.camera,
direction: event.direction,
speed: event.speed,
);
final message = 'CameraPan(${event.camera}, ${event.direction}, ${event.speed})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'Camera pan ${event.direction}'
: result['message'] ?? 'Camera pan failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Camera pan error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onCameraTilt(
CameraTiltEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.cameraTilt(
camera: event.camera,
direction: event.direction,
speed: event.speed,
);
final message = 'CameraTilt(${event.camera}, ${event.direction}, ${event.speed})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'Camera tilt ${event.direction}'
: result['message'] ?? 'Camera tilt failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Camera tilt error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onCameraZoom(
CameraZoomEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.cameraZoom(
camera: event.camera,
direction: event.direction,
speed: event.speed,
);
final message = 'CameraZoom(${event.camera}, ${event.direction}, ${event.speed})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'Camera zoom ${event.direction}'
: result['message'] ?? 'Camera zoom failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Camera zoom error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onCameraStop(
CameraStopEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.cameraStop(camera: event.camera);
final message = 'CameraStop(${event.camera})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'Camera stopped'
: result['message'] ?? 'Camera stop failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Camera stop error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onCameraPreset(
CameraPresetEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.cameraPreset(
camera: event.camera,
preset: event.preset,
);
final message = 'CameraPreset(${event.camera}, ${event.preset})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'Camera moved to preset ${event.preset}'
: result['message'] ?? 'Camera preset failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Camera preset error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onCloseContact(
GeViScopeCloseContactEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.digitalIoClose(contactId: event.contactId);
final message = 'DigitalIO_Close(${event.contactId})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'Digital output ${event.contactId} closed'
: result['message'] ?? 'Close contact failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Close contact error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onOpenContact(
GeViScopeOpenContactEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.digitalIoOpen(contactId: event.contactId);
final message = 'DigitalIO_Open(${event.contactId})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'Digital output ${event.contactId} opened'
: result['message'] ?? 'Open contact failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Open contact error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onSendCustomAction(
SendGeViScopeCustomActionEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.sendCustomAction(
typeId: event.typeId,
text: event.text,
);
final message = 'CustomAction(${event.typeId}, "${event.text}")';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'CustomAction sent'
: result['message'] ?? 'CustomAction failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'CustomAction error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onSendAction(
SendGeViScopeActionEvent event,
Emitter<GeViScopeState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.sendAction(event.action);
_addToLog(emit, event.action);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'Action sent'
: result['message'] ?? 'Action failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Send action error: $e',
lastActionSuccess: false,
));
}
}
void _onClearActionResult(
ClearGeViScopeActionResultEvent event,
Emitter<GeViScopeState> emit,
) {
emit(state.copyWith(clearLastActionResult: true, clearErrorMessage: true));
}
void _addToLog(Emitter<GeViScopeState> emit, String message) {
final timestamp = DateTime.now().toIso8601String().substring(11, 19);
final logEntry = '[$timestamp] $message';
final newLog = [...state.messageLog, logEntry];
// Keep only last 100 messages
if (newLog.length > 100) {
newLog.removeRange(0, newLog.length - 100);
}
emit(state.copyWith(messageLog: newLog));
}
}

View File

@@ -0,0 +1,181 @@
import 'package:equatable/equatable.dart';
abstract class GeViScopeEvent extends Equatable {
const GeViScopeEvent();
@override
List<Object?> get props => [];
}
/// Connect to GeViScope Camera Server
class ConnectGeViScopeEvent extends GeViScopeEvent {
final String address;
final String username;
final String password;
const ConnectGeViScopeEvent({
required this.address,
required this.username,
required this.password,
});
@override
List<Object?> get props => [address, username, password];
}
/// Disconnect from GeViScope
class DisconnectGeViScopeEvent extends GeViScopeEvent {
const DisconnectGeViScopeEvent();
}
/// Check connection status
class CheckGeViScopeStatusEvent extends GeViScopeEvent {
const CheckGeViScopeStatusEvent();
}
/// Load media channels
class LoadChannelsEvent extends GeViScopeEvent {
const LoadChannelsEvent();
}
/// Refresh media channels
class RefreshChannelsEvent extends GeViScopeEvent {
const RefreshChannelsEvent();
}
/// Send CrossSwitch command
class SendGeViScopeCrossSwitchEvent extends GeViScopeEvent {
final int videoInput;
final int videoOutput;
final int switchMode;
const SendGeViScopeCrossSwitchEvent({
required this.videoInput,
required this.videoOutput,
this.switchMode = 0,
});
@override
List<Object?> get props => [videoInput, videoOutput, switchMode];
}
/// PTZ Camera Pan
class CameraPanEvent extends GeViScopeEvent {
final int camera;
final String direction;
final int speed;
const CameraPanEvent({
required this.camera,
required this.direction,
this.speed = 50,
});
@override
List<Object?> get props => [camera, direction, speed];
}
/// PTZ Camera Tilt
class CameraTiltEvent extends GeViScopeEvent {
final int camera;
final String direction;
final int speed;
const CameraTiltEvent({
required this.camera,
required this.direction,
this.speed = 50,
});
@override
List<Object?> get props => [camera, direction, speed];
}
/// PTZ Camera Zoom
class CameraZoomEvent extends GeViScopeEvent {
final int camera;
final String direction;
final int speed;
const CameraZoomEvent({
required this.camera,
required this.direction,
this.speed = 50,
});
@override
List<Object?> get props => [camera, direction, speed];
}
/// PTZ Camera Stop
class CameraStopEvent extends GeViScopeEvent {
final int camera;
const CameraStopEvent({required this.camera});
@override
List<Object?> get props => [camera];
}
/// PTZ Camera Preset
class CameraPresetEvent extends GeViScopeEvent {
final int camera;
final int preset;
const CameraPresetEvent({
required this.camera,
required this.preset,
});
@override
List<Object?> get props => [camera, preset];
}
/// Close digital contact
class GeViScopeCloseContactEvent extends GeViScopeEvent {
final int contactId;
const GeViScopeCloseContactEvent({required this.contactId});
@override
List<Object?> get props => [contactId];
}
/// Open digital contact
class GeViScopeOpenContactEvent extends GeViScopeEvent {
final int contactId;
const GeViScopeOpenContactEvent({required this.contactId});
@override
List<Object?> get props => [contactId];
}
/// Send custom action
class SendGeViScopeCustomActionEvent extends GeViScopeEvent {
final int typeId;
final String text;
const SendGeViScopeCustomActionEvent({
required this.typeId,
this.text = '',
});
@override
List<Object?> get props => [typeId, text];
}
/// Send raw action
class SendGeViScopeActionEvent extends GeViScopeEvent {
final String action;
const SendGeViScopeActionEvent({required this.action});
@override
List<Object?> get props => [action];
}
/// Clear last action result
class ClearGeViScopeActionResultEvent extends GeViScopeEvent {
const ClearGeViScopeActionResultEvent();
}

View File

@@ -0,0 +1,112 @@
import 'package:equatable/equatable.dart';
enum GeViScopeConnectionStatus {
disconnected,
connecting,
connected,
error,
}
class MediaChannel {
final int channelId;
final int globalNumber;
final String name;
final String description;
final bool isActive;
const MediaChannel({
required this.channelId,
required this.globalNumber,
required this.name,
required this.description,
required this.isActive,
});
factory MediaChannel.fromJson(Map<String, dynamic> json) {
return MediaChannel(
channelId: json['channelID'] ?? json['channelId'] ?? 0,
globalNumber: json['globalNumber'] ?? 0,
name: json['name'] ?? '',
description: json['description'] ?? '',
isActive: json['isActive'] ?? false,
);
}
}
class GeViScopeState extends Equatable {
final GeViScopeConnectionStatus connectionStatus;
final String? serverAddress;
final String? username;
final int channelCount;
final List<MediaChannel> channels;
final DateTime? connectedAt;
final bool isLoading;
final String? lastActionResult;
final bool lastActionSuccess;
final String? errorMessage;
final List<String> messageLog;
const GeViScopeState({
this.connectionStatus = GeViScopeConnectionStatus.disconnected,
this.serverAddress,
this.username,
this.channelCount = 0,
this.channels = const [],
this.connectedAt,
this.isLoading = false,
this.lastActionResult,
this.lastActionSuccess = false,
this.errorMessage,
this.messageLog = const [],
});
bool get isConnected => connectionStatus == GeViScopeConnectionStatus.connected;
GeViScopeState copyWith({
GeViScopeConnectionStatus? connectionStatus,
String? serverAddress,
String? username,
int? channelCount,
List<MediaChannel>? channels,
DateTime? connectedAt,
bool? isLoading,
String? lastActionResult,
bool? lastActionSuccess,
String? errorMessage,
List<String>? messageLog,
bool clearServerAddress = false,
bool clearUsername = false,
bool clearConnectedAt = false,
bool clearErrorMessage = false,
bool clearLastActionResult = false,
}) {
return GeViScopeState(
connectionStatus: connectionStatus ?? this.connectionStatus,
serverAddress: clearServerAddress ? null : (serverAddress ?? this.serverAddress),
username: clearUsername ? null : (username ?? this.username),
channelCount: channelCount ?? this.channelCount,
channels: channels ?? this.channels,
connectedAt: clearConnectedAt ? null : (connectedAt ?? this.connectedAt),
isLoading: isLoading ?? this.isLoading,
lastActionResult: clearLastActionResult ? null : (lastActionResult ?? this.lastActionResult),
lastActionSuccess: lastActionSuccess ?? this.lastActionSuccess,
errorMessage: clearErrorMessage ? null : (errorMessage ?? this.errorMessage),
messageLog: messageLog ?? this.messageLog,
);
}
@override
List<Object?> get props => [
connectionStatus,
serverAddress,
username,
channelCount,
channels,
connectedAt,
isLoading,
lastActionResult,
lastActionSuccess,
errorMessage,
messageLog,
];
}

View File

@@ -0,0 +1,381 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../data/data_sources/remote/geviserver_remote_data_source.dart';
import 'geviserver_event.dart';
import 'geviserver_state.dart';
class GeViServerBloc extends Bloc<GeViServerEvent, GeViServerState> {
final GeViServerRemoteDataSource remoteDataSource;
GeViServerBloc({required this.remoteDataSource})
: super(const GeViServerState()) {
on<ConnectGeViServerEvent>(_onConnect);
on<DisconnectGeViServerEvent>(_onDisconnect);
on<CheckStatusEvent>(_onCheckStatus);
on<SendCrossSwitchEvent>(_onSendCrossSwitch);
on<ClearVideoOutputEvent>(_onClearVideoOutput);
on<CloseContactEvent>(_onCloseContact);
on<OpenContactEvent>(_onOpenContact);
on<SendCustomActionEvent>(_onSendCustomAction);
on<SendMessageEvent>(_onSendMessage);
on<StartTimerEvent>(_onStartTimer);
on<StopTimerEvent>(_onStopTimer);
on<ClearActionResultEvent>(_onClearActionResult);
}
Future<void> _onConnect(
ConnectGeViServerEvent event,
Emitter<GeViServerState> emit,
) async {
emit(state.copyWith(
connectionStatus: ConnectionStatus.connecting,
isLoading: true,
clearErrorMessage: true,
));
try {
final result = await remoteDataSource.connect(
address: event.address,
username: event.username,
password: event.password,
);
if (result['success'] == true) {
emit(state.copyWith(
connectionStatus: ConnectionStatus.connected,
serverAddress: event.address,
username: event.username,
connectedAt: DateTime.now(),
isLoading: false,
lastActionResult: 'Connected to ${event.address}',
lastActionSuccess: true,
));
} else {
emit(state.copyWith(
connectionStatus: ConnectionStatus.error,
isLoading: false,
errorMessage: result['message'] ?? 'Connection failed',
lastActionResult: result['message'] ?? 'Connection failed',
lastActionSuccess: false,
));
}
} catch (e) {
emit(state.copyWith(
connectionStatus: ConnectionStatus.error,
isLoading: false,
errorMessage: e.toString(),
lastActionResult: 'Connection error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onDisconnect(
DisconnectGeViServerEvent event,
Emitter<GeViServerState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
await remoteDataSource.disconnect();
emit(state.copyWith(
connectionStatus: ConnectionStatus.disconnected,
isLoading: false,
clearServerAddress: true,
clearUsername: true,
clearConnectedAt: true,
lastActionResult: 'Disconnected',
lastActionSuccess: true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
errorMessage: e.toString(),
lastActionResult: 'Disconnect error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onCheckStatus(
CheckStatusEvent event,
Emitter<GeViServerState> emit,
) async {
try {
final result = await remoteDataSource.getStatus();
final isConnected = result['is_connected'] == true;
emit(state.copyWith(
connectionStatus: isConnected
? ConnectionStatus.connected
: ConnectionStatus.disconnected,
serverAddress: result['address']?.toString(),
username: result['username']?.toString(),
));
} catch (e) {
emit(state.copyWith(
connectionStatus: ConnectionStatus.error,
errorMessage: e.toString(),
));
}
}
Future<void> _onSendCrossSwitch(
SendCrossSwitchEvent event,
Emitter<GeViServerState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.crossSwitch(
videoInput: event.videoInput,
videoOutput: event.videoOutput,
switchMode: event.switchMode,
);
final message = 'CrossSwitch(${event.videoInput}, ${event.videoOutput}, ${event.switchMode})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'CrossSwitch sent successfully'
: result['message'] ?? 'CrossSwitch failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'CrossSwitch error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onClearVideoOutput(
ClearVideoOutputEvent event,
Emitter<GeViServerState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.clearOutput(
videoOutput: event.videoOutput,
);
final message = 'ClearVideoOutput(${event.videoOutput})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'ClearOutput sent successfully'
: result['message'] ?? 'ClearOutput failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'ClearOutput error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onCloseContact(
CloseContactEvent event,
Emitter<GeViServerState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.closeContact(
contactId: event.contactId,
);
final message = 'CloseContact(${event.contactId})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'CloseContact sent successfully'
: result['message'] ?? 'CloseContact failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'CloseContact error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onOpenContact(
OpenContactEvent event,
Emitter<GeViServerState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.openContact(
contactId: event.contactId,
);
final message = 'OpenContact(${event.contactId})';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'OpenContact sent successfully'
: result['message'] ?? 'OpenContact failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'OpenContact error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onSendCustomAction(
SendCustomActionEvent event,
Emitter<GeViServerState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.sendCustomAction(
typeId: event.typeId,
text: event.text,
);
final message = 'CustomAction(${event.typeId}, "${event.text}")';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'CustomAction sent successfully'
: result['message'] ?? 'CustomAction failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'CustomAction error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onSendMessage(
SendMessageEvent event,
Emitter<GeViServerState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.sendMessage(event.message);
_addToLog(emit, event.message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'Message sent successfully'
: result['message'] ?? 'Send message failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'Send message error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onStartTimer(
StartTimerEvent event,
Emitter<GeViServerState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.startTimer(
timerId: event.timerId,
timerName: event.timerName,
);
final message = 'StartTimer(${event.timerId}, "${event.timerName}")';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'StartTimer sent successfully'
: result['message'] ?? 'StartTimer failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'StartTimer error: $e',
lastActionSuccess: false,
));
}
}
Future<void> _onStopTimer(
StopTimerEvent event,
Emitter<GeViServerState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final result = await remoteDataSource.stopTimer(
timerId: event.timerId,
timerName: event.timerName,
);
final message = 'StopTimer(${event.timerId}, "${event.timerName}")';
_addToLog(emit, message);
emit(state.copyWith(
isLoading: false,
lastActionResult: result['success'] == true
? 'StopTimer sent successfully'
: result['message'] ?? 'StopTimer failed',
lastActionSuccess: result['success'] == true,
));
} catch (e) {
emit(state.copyWith(
isLoading: false,
lastActionResult: 'StopTimer error: $e',
lastActionSuccess: false,
));
}
}
void _onClearActionResult(
ClearActionResultEvent event,
Emitter<GeViServerState> emit,
) {
emit(state.copyWith(clearLastActionResult: true, clearErrorMessage: true));
}
void _addToLog(Emitter<GeViServerState> emit, String message) {
final timestamp = DateTime.now().toIso8601String().substring(11, 19);
final logEntry = '[$timestamp] $message';
final newLog = [...state.messageLog, logEntry];
// Keep only last 100 messages
if (newLog.length > 100) {
newLog.removeRange(0, newLog.length - 100);
}
emit(state.copyWith(messageLog: newLog));
}
}

View File

@@ -0,0 +1,137 @@
import 'package:equatable/equatable.dart';
abstract class GeViServerEvent extends Equatable {
const GeViServerEvent();
@override
List<Object?> get props => [];
}
/// Connect to GeViServer
class ConnectGeViServerEvent extends GeViServerEvent {
final String address;
final String username;
final String password;
const ConnectGeViServerEvent({
required this.address,
required this.username,
required this.password,
});
@override
List<Object?> get props => [address, username, password];
}
/// Disconnect from GeViServer
class DisconnectGeViServerEvent extends GeViServerEvent {
const DisconnectGeViServerEvent();
}
/// Check connection status
class CheckStatusEvent extends GeViServerEvent {
const CheckStatusEvent();
}
/// Send CrossSwitch command
class SendCrossSwitchEvent extends GeViServerEvent {
final int videoInput;
final int videoOutput;
final int switchMode;
const SendCrossSwitchEvent({
required this.videoInput,
required this.videoOutput,
this.switchMode = 0,
});
@override
List<Object?> get props => [videoInput, videoOutput, switchMode];
}
/// Clear video output
class ClearVideoOutputEvent extends GeViServerEvent {
final int videoOutput;
const ClearVideoOutputEvent({required this.videoOutput});
@override
List<Object?> get props => [videoOutput];
}
/// Close digital contact
class CloseContactEvent extends GeViServerEvent {
final int contactId;
const CloseContactEvent({required this.contactId});
@override
List<Object?> get props => [contactId];
}
/// Open digital contact
class OpenContactEvent extends GeViServerEvent {
final int contactId;
const OpenContactEvent({required this.contactId});
@override
List<Object?> get props => [contactId];
}
/// Send custom action
class SendCustomActionEvent extends GeViServerEvent {
final int typeId;
final String text;
const SendCustomActionEvent({
required this.typeId,
this.text = '',
});
@override
List<Object?> get props => [typeId, text];
}
/// Send raw message
class SendMessageEvent extends GeViServerEvent {
final String message;
const SendMessageEvent({required this.message});
@override
List<Object?> get props => [message];
}
/// Start timer
class StartTimerEvent extends GeViServerEvent {
final int timerId;
final String timerName;
const StartTimerEvent({
this.timerId = 0,
this.timerName = '',
});
@override
List<Object?> get props => [timerId, timerName];
}
/// Stop timer
class StopTimerEvent extends GeViServerEvent {
final int timerId;
final String timerName;
const StopTimerEvent({
this.timerId = 0,
this.timerName = '',
});
@override
List<Object?> get props => [timerId, timerName];
}
/// Clear last action result (to dismiss success/error messages)
class ClearActionResultEvent extends GeViServerEvent {
const ClearActionResultEvent();
}

View File

@@ -0,0 +1,76 @@
import 'package:equatable/equatable.dart';
enum ConnectionStatus {
disconnected,
connecting,
connected,
error,
}
class GeViServerState extends Equatable {
final ConnectionStatus connectionStatus;
final String? serverAddress;
final String? username;
final DateTime? connectedAt;
final bool isLoading;
final String? lastActionResult;
final bool lastActionSuccess;
final String? errorMessage;
final List<String> messageLog;
const GeViServerState({
this.connectionStatus = ConnectionStatus.disconnected,
this.serverAddress,
this.username,
this.connectedAt,
this.isLoading = false,
this.lastActionResult,
this.lastActionSuccess = false,
this.errorMessage,
this.messageLog = const [],
});
bool get isConnected => connectionStatus == ConnectionStatus.connected;
GeViServerState copyWith({
ConnectionStatus? connectionStatus,
String? serverAddress,
String? username,
DateTime? connectedAt,
bool? isLoading,
String? lastActionResult,
bool? lastActionSuccess,
String? errorMessage,
List<String>? messageLog,
bool clearServerAddress = false,
bool clearUsername = false,
bool clearConnectedAt = false,
bool clearErrorMessage = false,
bool clearLastActionResult = false,
}) {
return GeViServerState(
connectionStatus: connectionStatus ?? this.connectionStatus,
serverAddress: clearServerAddress ? null : (serverAddress ?? this.serverAddress),
username: clearUsername ? null : (username ?? this.username),
connectedAt: clearConnectedAt ? null : (connectedAt ?? this.connectedAt),
isLoading: isLoading ?? this.isLoading,
lastActionResult: clearLastActionResult ? null : (lastActionResult ?? this.lastActionResult),
lastActionSuccess: lastActionSuccess ?? this.lastActionSuccess,
errorMessage: clearErrorMessage ? null : (errorMessage ?? this.errorMessage),
messageLog: messageLog ?? this.messageLog,
);
}
@override
List<Object?> get props => [
connectionStatus,
serverAddress,
username,
connectedAt,
isLoading,
lastActionResult,
lastActionSuccess,
errorMessage,
messageLog,
];
}