-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathLocalDataTrack.ts
More file actions
53 lines (44 loc) · 1.48 KB
/
LocalDataTrack.ts
File metadata and controls
53 lines (44 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import type { DataTrackFrame } from './frame';
import type OutgoingDataTrackManager from './outgoing/OutgoingDataTrackManager';
import {
DataTrackSymbol,
type IDataTrack,
type ILocalTrack,
TrackSymbol,
} from './track-interfaces';
import type { DataTrackInfo } from './types';
export default class LocalDataTrack implements ILocalTrack, IDataTrack {
readonly trackSymbol = TrackSymbol;
readonly isLocal = true;
readonly typeSymbol = DataTrackSymbol;
info: DataTrackInfo;
protected manager: OutgoingDataTrackManager;
/** @internal */
constructor(info: DataTrackInfo, manager: OutgoingDataTrackManager) {
this.info = info;
this.manager = manager;
}
/** The raw descriptor from the manager containing the internal state for this local track. */
protected get descriptor() {
return this.manager.getDescriptor(this.info.pubHandle);
}
isPublished() {
return this.descriptor?.type === 'active';
}
/** Try pushing a frame to subscribers of the track.
*
* Pushing a frame can fail for several reasons:
*
* - The track has been unpublished by the local participant or SFU
* - The room is no longer connected
*/
tryPush(payload: DataTrackFrame['payload']) {
try {
return this.manager.tryProcessAndSend(this.info.pubHandle, payload);
} catch (err) {
// NOTE: wrapping in the bare try/catch like this means that the Throws<...> type doesn't
// propegate upwards into the public interface.
throw err;
}
}
}