twilio / twilio-video.js

Twilio’s Programmable Video JavaScript SDK
https://www.twilio.com/docs/video/javascript
Other
571 stars 217 forks source link

Failed publish local track when two participants in room #964

Closed DaniloITC closed 4 years ago

DaniloITC commented 4 years ago

Code to reproduce the issue:

    protected createDeviceAudioTrack(device: MediaDeviceInfo, name): Promise<Track> {

        return createLocalAudioTrack({
            deviceId: device.deviceId,
            name: name
        });
    }

    protected createDeviceVideoTrack(device: MediaDeviceInfo, name): Promise<Track> {

        return createLocalVideoTrack(
            {
                deviceId: device.deviceId,
                name: name
            }
        );
    }

    protected createDeviceTrack(device: MediaDeviceInfo, name = null): Promise<Track> {

        return device.kind === "audioinput"
            ? this.createDeviceAudioTrack(this.activeDevices["audio"], name)
            : this.createDeviceVideoTrack(this.activeDevices["video"], name);
    }

    turnOn(type) {

        this.createDeviceTrack(this.activeDevices[type], `medical_${type}`)
            .then((track: Track) => {

                this.deviceTracks[type] = track;
                const trackElement = this.attachTrack(this.deviceTracks[type], this.additionalLocalMedia);
                if (this.activeDevices[type].kind === "audioinput") {
                    this.attachWaveform(trackElement);
                }

                this.share(type);
            });
    }

    share(type) {

        if (!this.canShare(type)) {

            return;
        }

        this.room
            .localParticipant
            .publishTrack(this.deviceTracks[type]);
        this.deviceTrackShared[type] = true;
    }

Expected behavior:

Local track successfull published and was displayed for participant

Actual behavior:

When I try publish additional local track I get followed error: ERROR TypeError: transceiver.sender.replaceTrack(...).then(...).finally is not a function. at PeerConnectionV2._addOrUpdateTransceiver (peerconnection.js:493) at PeerConnectionV2.addMediaTrackSender (peerconnection.js:1291) at Set.forEach () at eval (peerconnectionmanager.js:493) at Map.forEach () at applyTrackSenderChanges (peerconnectionmanager.js:489) at PeerConnectionManager.setTrackSenders (peerconnectionmanager.js:371) at eval (room.js:787) at nextTick (index.js:173) at ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:4744) at ZoneDelegate.invokeTask (zone.js:420) at Zone.runTask (zone.js:188) at ZoneTask.invokeTask (zone.js:495) at ZoneTask.invoke (zone.js:484) at timer (zone.js:2065)

When I try unpublish this track I get followed error:

ERROR Error: Uncaught (in promise): Error: The [LocalVideoTrack #5: 5b533193-b452-4431-b58d-807040aa3946] was unpublished.

And if I publish local track again it's ok.

This happened after uprade from 1.x to 2.x

logs.txt

Software versions:

makarandp0 commented 4 years ago

Hello @DaniloITC, Thank you for writing about this issue.

Since you mentioned Angular, which has a known pollyfill issue - can you verify that you are using the suggestion mentioned here: https://github.com/twilio/twilio-video.js/blob/master/COMMON_ISSUES.md#angular

let me know if that fixes this issue. Thanks, Makarand.

DaniloITC commented 4 years ago

Hello @makarandp0, Thank you so much for Your answer! Tell me please, this resolve actually for upgrade from 1.x to 2.x, because in 1.x version this works fine.

makarandp0 commented 4 years ago

@DaniloITC, This part of code exists only in 2.x.

Also since the error mentions .finally - Are you using any library that polyfills promises? I wonder if the version is missing support for .finally for promises.

DaniloITC commented 4 years ago

@makarandp0 what's version Angular do you using?

DaniloITC commented 4 years ago

@makarandp0 , I think it's not resolve my problem, because if only one local participant in room, it's work fine, tracks are published/unpublished fine. If two participants are connected in room i get this error. And if I make publish-unpublish-publish track was published successfully, but I have to repeat these steps over and over to publish an additional track

DaniloITC commented 4 years ago

So, I fixed this issue. I lost a lot of time searching for errors in the code, but I just needed to update zone.js from 0.8.x to 0.9.x. Now it's working fine!

makarandp0 commented 4 years ago

Thanks for the update @DaniloITC and am glad you found the fix. I will close this issue now.