Skip to content

Commit

Permalink
Fixes for new react-native-webrtc (#478)
Browse files Browse the repository at this point in the history
* Fixes for new react-native-webrtc

* Add changeset

* formatting
  • Loading branch information
davidliu authored Oct 19, 2022
1 parent a12a65f commit 676ecd3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-ears-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Fixes for latest transceiver APIs in react-native-webrtc
23 changes: 4 additions & 19 deletions src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ import type LocalVideoTrack from './track/LocalVideoTrack';
import type { SimulcastTrackInfo } from './track/LocalVideoTrack';
import type { TrackPublishOptions, VideoCodec } from './track/options';
import { Track } from './track/Track';
import {
isWeb,
sleep,
supportsAddTrack,
supportsSetCodecPreferences,
supportsTransceiver,
} from './utils';
import { sleep, supportsAddTrack, supportsSetCodecPreferences, supportsTransceiver } from './utils';

const lossyDataChannel = '_lossy';
const reliableDataChannel = '_reliable';
Expand Down Expand Up @@ -352,18 +346,9 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
}
};

if (isWeb()) {
this.subscriber.pc.ontrack = (ev: RTCTrackEvent) => {
this.emit(EngineEvent.MediaTrackAdded, ev.track, ev.streams[0], ev.receiver);
};
} else {
// TODO: react-native-webrtc doesn't have ontrack yet, replace when ready.
// @ts-ignore
this.subscriber.pc.onaddstream = (ev: { stream: MediaStream }) => {
const track = ev.stream.getTracks()[0];
this.emit(EngineEvent.MediaTrackAdded, track, ev.stream);
};
}
this.subscriber.pc.ontrack = (ev: RTCTrackEvent) => {
this.emit(EngineEvent.MediaTrackAdded, ev.track, ev.streams[0], ev.receiver);
};

this.createDataChannels();

Expand Down
2 changes: 1 addition & 1 deletion src/room/track/RemoteAudioTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default class RemoteAudioTrack extends RemoteTrack {
};

protected async getReceiverStats(): Promise<AudioReceiverStats | undefined> {
if (!this.receiver) {
if (!this.receiver || !this.receiver.getStats) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/room/track/RemoteVideoTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default class RemoteVideoTrack extends RemoteTrack {
};

private async getReceiverStats(): Promise<VideoReceiverStats | undefined> {
if (!this.receiver) {
if (!this.receiver || !this.receiver.getStats) {
return;
}

Expand Down

0 comments on commit 676ecd3

Please sign in to comment.