start_ function

Future<SpaceData?> start_({
  1. String? accountAddress,
  2. Signer? signer,
  3. String? pgpPrivateKey,
  4. required String spaceId,
  5. required dynamic progressHook(
    1. ProgressHookType
    ),
  6. required dynamic updateRoom(
    1. Room?
    ),
})

Implementation

Future<SpaceData?> start_({
  String? accountAddress,
  Signer? signer,
  String? pgpPrivateKey,
  required String spaceId,
  required Function(ProgressHookType) progressHook,
  required Function(Room?) updateRoom,
}) async {
  try {
    accountAddress ??= getCachedWallet()?.address;
    signer ??= getCachedWallet()?.signer;

    final space = await getSpaceById(spaceId: spaceId);

    if (space.status != ChatStatus.PENDING) {
      throw Exception(
          'Unable to start the space as it is not in the pending state');
    }

    final convertedMembers =
        getSpacesMembersList(space.members, space.pendingMembers);
    final convertedAdmins =
        getSpaceAdminsList(space.members, space.pendingMembers);

    ////Create Stream
    final stream = await createStreamService(spaceName: space.spaceName);

    ///Create room
    final roomId = await createLivePeerRoom();

    ///add local user as participant
    final room = await addSpeakingParticipant(
      roomId: roomId,
      participantName: accountAddress ?? signer!.getAddress(),
    );
    updateRoom(room);

    ///connect room to stream
    await startLiveStream(roomId: roomId, streamId: stream.streamId!);

    final group = await updateGroup(
      chatId: spaceId,
      groupName: space.spaceName,
      groupImage: space.spaceImage,
      groupDescription: space.spaceDescription!,
      members: convertedMembers,
      admins: convertedAdmins,
      signer: signer,
      meta: jsonEncode({
        "playbackId": stream.playbackId,
        "roomId": roomId,
        "streamId": stream.streamId!
      }),
      scheduleAt: space.scheduleAt,
      scheduleEnd: space.scheduleEnd,
      status: ChatStatus.ACTIVE,
      isPublic: space.isPublic,
      pgpPrivateKey: pgpPrivateKey,
    );

    if (group != null) {
      final space = groupDtoToSpaceDto(group);

      final liveSpaceData = LiveSpaceData(
        host: AdminPeer(
          address: accountAddress ?? signer!.getAddress(),
          audio: false,
          emojiReactions: EmojiReaction(),
        ),
        speakers: [],
        listeners: [],
      );

      String metaMessageContent = CHAT.META_SPACE_START;

      sendLiveSpaceData(
        messageType: MessageType.META,
        updatedLiveSpaceData: liveSpaceData,
        content: metaMessageContent,
        affectedAddresses: [accountAddress ?? signer!.getAddress()],
        spaceId: spaceId,
      );

      final result = SpaceData.fromSpaceDTO(space, liveSpaceData);

      return result;
    } else {
      throw Exception('Error while updating Space : $spaceId');
    }
  } catch (e) {
    print('[Push SDK] - API  - Error - API update -:  $e');
    rethrow;
  }
}