GameBridgeSession constructor

GameBridgeSession({
  1. required GameBridge bridge,
  2. required String initJson(),
  3. required GameAsyncRunner async,
  4. required Future<GameHttpOutcome> httpCall(
    1. String method,
    2. String path,
    3. Map<String, dynamic>? body
    ),
  5. required GameSkinStorage? storage,
  6. required String storageNamespace,
  7. required void haptics(
    1. String style
    ),
  8. required GameMotionSource sensors,
  9. required void onLog(
    1. String level,
    2. String message
    ),
  10. required void onCloseRequest(
    1. String style
    ),
  11. void onCta(
    1. String op
    )?,
  12. void onHttpAnswer(
    1. String path,
    2. Map<String, dynamic>? requestBody,
    3. Map<String, dynamic>? responseBody
    )?,
  13. GameHealthContext health = GameHealthContext.empty,
  14. void onHealth(
    1. EngageAnalyticsEvent event
    )?,
  15. required void send(
    1. String style
    ),
  16. Future<void> runActionSteps(
    1. List<EngageAction> actions
    )?,
  17. EngageActionParser actionParser = const EngageActionParser(),
  18. void onHttpTimeout(
    1. String path,
    2. int durationMs
    )?,
  19. GameWatchdogSchedule? watchdogSchedule,
  20. GameWatchdogCancel? watchdogCancel,
})

Implementation

GameBridgeSession({
  required GameBridge bridge,
  required String Function() initJson,
  required GameAsyncRunner async,
  required Future<GameHttpOutcome> Function(
          String method, String path, Map<String, dynamic>? body)
      httpCall,
  required GameSkinStorage? storage,
  required String storageNamespace,
  required void Function(String style) haptics,
  required GameMotionSource sensors,
  required void Function(String level, String message) onLog,
  required void Function(String reason) onCloseRequest,
  void Function(String op)? onCta,
  void Function(String path, Map<String, dynamic>? requestBody,
          Map<String, dynamic>? responseBody)?
      onHttpAnswer,
  GameHealthContext health = GameHealthContext.empty,
  void Function(EngageAnalyticsEvent event)? onHealth,
  required void Function(String messageJson) send,
  Future<void> Function(List<EngageAction> actions)? runActionSteps,
  EngageActionParser actionParser = const EngageActionParser(),
  void Function(String path, int durationMs)? onHttpTimeout,
  GameWatchdogSchedule? watchdogSchedule,
  GameWatchdogCancel? watchdogCancel,
})  : _bridge = bridge,
      _initJson = initJson,
      _async = async,
      _httpCall = httpCall,
      _storage = storage,
      _storageNamespace = storageNamespace,
      _haptics = haptics,
      _sensors = sensors,
      _onLog = onLog,
      _onCloseRequest = onCloseRequest,
      _onCta = onCta,
      _onHttpAnswer = onHttpAnswer,
      _health = health,
      _onHealth = onHealth,
      _send = send,
      _runActionSteps = runActionSteps,
      _actionParser = actionParser,
      _onHttpTimeout = onHttpTimeout,
      _watchdogSchedule =
          watchdogSchedule ?? ((delay, fire) => Timer(delay, fire)),
      _watchdogCancel = watchdogCancel ??
          ((handle) {
            if (handle is Timer) handle.cancel();
          }) {
  _sensors.onSample = (sensor, x, y, z, t) {
    if (_closed) return;
    _sendSafe(jsonEncode({
      'type': 'motionSample',
      'payload': {
        't': t,
        sensor: {'x': x, 'y': y, 'z': z},
      },
    }));
  };
}