openSession method

Future<RemoteSession> openSession({
  1. required String nodeId,
  2. SessionMode mode = SessionMode.exec,
  3. String? command,
  4. List<String> args = const [],
  5. Map<String, String> env = const {},
  6. String? cwd,
  7. PtySpec? pty,
  8. String? resumeSessionId,
})

Opens a session on nodeId.

Completes once the node confirms the session, or throws SessionRejectedException if it is refused.

Implementation

Future<RemoteSession> openSession({
  required String nodeId,
  SessionMode mode = SessionMode.exec,
  String? command,
  List<String> args = const [],
  Map<String, String> env = const {},
  String? cwd,
  PtySpec? pty,
  String? resumeSessionId,
}) async {
  _ensureConnected();
  final Channel channel = _mux!.open();
  final session = RemoteSession(channel, mode);
  _connection!.send(
    ControlFrame(
      SessionOpen(
        channel: channel.id,
        nodeId: nodeId,
        mode: mode,
        command: command,
        args: args,
        env: env,
        cwd: cwd,
        pty: pty,
        resumeSessionId: resumeSessionId,
      ),
    ),
  );
  try {
    await session.opened;
  } on Object {
    await _mux!.closeChannel(channel.id);
    rethrow;
  }
  return session;
}