#Hey so I m coming back to this library

1 messages · Page 1 of 1 (latest)

ionic cave
#
//whole disconnect method
      /**
     * Disconnects the VoiceConnection, allowing the possibility of rejoining later on.
     *
     * @returns `true` if the connection was successfully disconnected
     */
    public disconnect() {
        if (
            this.state.status === VoiceConnectionStatus.Destroyed ||
            this.state.status === VoiceConnectionStatus.Signalling
        ) {
            return false;
        }

        this.joinConfig.channelId = null;
        if (!this.state.adapter.sendPayload(createJoinVoiceChannelPayload(this.joinConfig))) {
            this.state = {
                adapter: this.state.adapter,
                subscription: this.state.subscription,
                status: VoiceConnectionStatus.Disconnected,
                reason: VoiceConnectionDisconnectReason.AdapterUnavailable,
            };
            return false;
        }

        this.state = {
            adapter: this.state.adapter,
            reason: VoiceConnectionDisconnectReason.Manual,
            status: VoiceConnectionStatus.Disconnected,
        };
        return true;
    }
#
//whole rejoin method
/**
     * Attempts to rejoin (better explanation soon:tm:)
     *
     * @remarks
     * Calling this method successfully will automatically increment the `rejoinAttempts` counter,
     * which you can use to inform whether or not you'd like to keep attempting to reconnect your
     * voice connection.
     *
     * A state transition from Disconnected to Signalling will be observed when this is called.
     */
    public rejoin(joinConfig?: Omit<JoinConfig, 'group' | 'guildId'>) {
        if (this.state.status === VoiceConnectionStatus.Destroyed) {
            return false;
        }

        const notReady = this.state.status !== VoiceConnectionStatus.Ready;

        if (notReady) this.rejoinAttempts++;
        Object.assign(this.joinConfig, joinConfig);
        if (this.state.adapter.sendPayload(createJoinVoiceChannelPayload(this.joinConfig))) {
            if (notReady) {
                this.state = {
                    ...this.state,
                    status: VoiceConnectionStatus.Signalling,
                };
            }

            return true;
        }

        this.state = {
            adapter: this.state.adapter,
            subscription: this.state.subscription,
            status: VoiceConnectionStatus.Disconnected,
            reason: VoiceConnectionDisconnectReason.AdapterUnavailable,
        };
        return false;
    }