---
url: https://docs.moqtail.dev/ts/api/player/classes/SourceElement.md
---
# Abstract Class: SourceElement

Writes to its source pads from anywhere, and emits `nomorepads` once every expected pad exists.

## Extends

* [`BaseElement`](BaseElement.md)

## Extended by

* [`CatalogElement`](../interfaces/CatalogElement.md)
* [`SstsSource`](SstsSource.md)

## Constructors

### Constructor

> **new SourceElement**(`context`): `SourceElement`

Calls `context.attach(this)`, so the player hears everything the instance emits.

#### Parameters

##### context

[`ElementContext`](../interfaces/ElementContext.md)

#### Returns

`SourceElement`

#### Inherited from

[`BaseElement`](BaseElement.md).[`constructor`](BaseElement.md#constructor)

## Properties

### context

> `protected` `readonly` **context**: [`ElementContext`](../interfaces/ElementContext.md)

#### Inherited from

[`BaseElement`](BaseElement.md).[`context`](BaseElement.md#context)

***

### definition

> `readonly` **definition**: [`ElementDefinition`](../interfaces/ElementDefinition.md)

Set by `defineElement` once `init` resolves, so it can't be used from a constructor.

#### Inherited from

[`BaseElement`](BaseElement.md).[`definition`](BaseElement.md#definition)

***

### pads

> `readonly` **pads**: [`Pad`](Pad.md)\[] = `[]`

#### Inherited from

[`BaseElement`](BaseElement.md).[`pads`](BaseElement.md#pads)

## Methods

### createPad()

> `protected` **createPad**(`direction`, `capabilities`): [`Pad`](Pad.md)

Creates a pad and emits `padadded`.

#### Parameters

##### direction

`"sink"` | `"src"`

##### capabilities

[`Capabilities`](../type-aliases/Capabilities.md)

#### Returns

[`Pad`](Pad.md)

#### Inherited from

[`BaseElement`](BaseElement.md).[`createPad`](BaseElement.md#createpad)

***

### destroy()

> **destroy**(): `Promise`<`void`>

Removes the element's pads. The runtime aborts `context.signal` before and releases the
elements this one loaded after. Override for your own cleanup and call `super.destroy()`.

#### Returns

`Promise`<`void`>

#### Inherited from

[`BaseElement`](BaseElement.md).[`destroy`](BaseElement.md#destroy)

***

### emit()

> **emit**<`K`>(`event`, ...`args`): `void`

Calls every listener of `event` with `args`. Allocates nothing when there are none.

#### Type Parameters

##### K

`K` *extends* `"ready"` | `"padadded"` | `"padremoved"` | `"nomorepads"`

#### Parameters

##### event

`K`

##### args

...`Parameters`<[`ElementEvents`](../interfaces/ElementEvents.md)\[`K`]>

#### Returns

`void`

#### Inherited from

[`BaseElement`](BaseElement.md).[`emit`](BaseElement.md#emit)

***

### matchesCapabilities()

> `protected` **matchesCapabilities**(`pad`): `boolean`

True if the pad matches one of the definition's `in` capability bundles.

#### Parameters

##### pad

[`Pad`](Pad.md)

#### Returns

`boolean`

#### Inherited from

[`BaseElement`](BaseElement.md).[`matchesCapabilities`](BaseElement.md#matchescapabilities)

***

### negotiate()?

> `optional` **negotiate**(`pad`): `boolean`

Optional: whether to take a source pad of an element this one loaded. A taken pad
connects to a new sink pad here instead of reaching the sinks, and its items arrive
through `receive()`.

#### Parameters

##### pad

[`Pad`](Pad.md)

#### Returns

`boolean`

***

### off()

> **off**<`K`>(`event`, `listener`): `void`

Removes `listener`, the same function given to `on()`, from `event`.

#### Type Parameters

##### K

`K` *extends* `"ready"` | `"padadded"` | `"padremoved"` | `"nomorepads"`

#### Parameters

##### event

`K`

##### listener

[`ElementEvents`](../interfaces/ElementEvents.md)\[`K`]

#### Returns

`void`

#### Inherited from

[`BaseElement`](BaseElement.md).[`off`](BaseElement.md#off)

***

### on()

> **on**<`K`>(`event`, `listener`): `void`

Adds `listener` for `event`. Adding the same function twice has no effect.

#### Type Parameters

##### K

`K` *extends* `"ready"` | `"padadded"` | `"padremoved"` | `"nomorepads"`

#### Parameters

##### event

`K`

##### listener

[`ElementEvents`](../interfaces/ElementEvents.md)\[`K`]

#### Returns

`void`

#### Inherited from

[`BaseElement`](BaseElement.md).[`on`](BaseElement.md#on)

***

### receive()?

> `optional` **receive**(`pad`, `item`): `void` | `Promise`<`void`>

Called once per item on a taken pad; the pad's next item waits for the returned promise.

#### Parameters

##### pad

[`Pad`](Pad.md)

##### item

[`PadItem`](../type-aliases/PadItem.md)

#### Returns

`void` | `Promise`<`void`>

***

### removePad()

> `protected` **removePad**(`pad`, `failed?`): `void`

Removes a pad and emits `padremoved`. Pass `failed` when a failure, not a catalog update, lost it.

#### Parameters

##### pad

[`Pad`](Pad.md)

##### failed?

`boolean` = `false`

#### Returns

`void`

#### Inherited from

[`BaseElement`](BaseElement.md).[`removePad`](BaseElement.md#removepad)
