# Struct VoiceSession

> One stay in a voice channel. Dropping it leaves the channel.

`zaun_client::VoiceSession` · Struct

```rust
pub struct VoiceSession { … }
```

One stay in a voice channel. Dropping it leaves the channel.

## Methods

### `community`

```rust
pub const fn community(&self) -> CommunityId
```

The community.

### `channel`

```rust
pub const fn channel(&self) -> ChannelId
```

The voice channel.

### `voice_session`

```rust
pub const fn voice_session(&self) -> VoiceSessionId
```

This stay's voice session, as the host named it.

### `send_audio`

```rust
pub fn send_audio(&self, frame: &[u8])
```

Sends one Opus packet to every connected participant, sealed, now: the caller keeps
the time (one packet per 20 ms for 20 ms packets). Its duration comes from its TOC
byte. Frames are dropped while this member is muted (by itself or a moderator) or may
not speak. To play files or streams in real time, `subscribe` to an
`AudioPlayer` instead.

### `subscribe`

```rust
pub fn subscribe(&self, player: &AudioPlayer)
```

Sends what `player` plays (discord.js's `connection.subscribe(player)`), instead of
any player subscribed before. The player does not keep this session alive.

### `unsubscribe`

```rust
pub fn unsubscribe(&self, player: &AudioPlayer)
```

Stops sending what `player` plays.

### `frames_refused`

```rust
pub fn frames_refused(&self) -> u64
```

How many frames arrived from participants and did not open (a wrong key, a damaged
frame, one that was never sealed, or one sealed under an epoch this stay never had or
no longer keeps, around joins and leaves); none are played.

### `can_send`

```rust
pub fn can_send(&self) -> bool
```

Whether frames given to `send_audio` are sent now.

### `next_event`

```rust
pub fn next_event(&self, timeout: Duration) -> Option<VoiceEvent>
```

The next event, or `None` when none arrives within `timeout` or the session ended.

### `events`

```rust
pub fn events(&self) -> impl Iterator<Item = VoiceEvent> + Send + 'static
```

The events, blocking; ends with the session.

### `set_self`

```rust
pub fn set_self(&self, mute: Option<bool>, deaf: Option<bool>) -> Result<()>
```

Mutes or deafens this member (`voice.update`); deafened, incoming audio is dropped.

# Errors
The host refused or did not answer.

### `leave`

```rust
pub fn leave(self) -> Result<()>
```

Leaves the channel (`voice.leave`) and closes every media connection.

# Errors
The host refused or did not answer; the media is closed either way.

## Trait implementations

`Drop`

[Full rustdoc page](/docs/api/rust/zaun-client/zaun_client/voice/struct.VoiceSession.html)
