Trying to use JitsiConference.replaceTrack() but getting an error saying cannot add second video track to conference

I am trying to switch source of video by switching between available video streaming devices external webcam and local camera. But when I switch the video source using JitsiConference.replaceTrack() method, I get the error “cannot add second video track to conference.”
This is what my function looks like -
public replaceTrack(oldTrack, newTrack): Promise {
let promise = new Promise((resolve, reject) => {
this._jitsiConference.replaceTrack(oldTrack, newTrack)
.then(()=> {
resolve(true);
})
});
return promise;
}

Can you tell me what am I doing wrong here? Do I need to remove track before replacing or how this is supposed to be done.

Following is the error I am getting -
Unhandled Promise rejection: cannot add second video track to the conference ; Zone: ; Task: Promise.then ; Value: Error: cannot add second video track to the conference
at X.addTrack (scripts.js:8)
at :6005/pinball-pinball-module.js:913
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (polyfills.js:8071)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.run (polyfills.js:7830)
at polyfills.js:8569
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:8103)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.runTask (polyfills.js:7875)
at drainMicroTaskQueue (polyfills.js:8281) Error: cannot add second video track to the conference
at X.addTrack (https://localhost:6005/scripts.js:8:286688)
at https://localhost:6005/pinball-pinball-module.js:913:48
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (https://localhost:6005/polyfills.js:8071:26)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.run (https://localhost:6005/polyfills.js:7830:43)
at https://localhost:6005/polyfills.js:8569:34
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (https://localhost:6005/polyfills.js:8103:31)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.runTask (https://localhost:6005/polyfills.js:7875:47)
at drainMicroTaskQueue (https://localhost:6005/polyfills.js:8281:35)
api.onUnhandledError @ polyfills.js:8362
scripts.js:8 [JitsiMeetJS.js] <Object.getGlobalOnErrorHandler>: UnhandledError: null Script: null Line: null Column: null StackTrace: Error: cannot add second video track to the conference
at X.addTrack (scripts.js:8)
at :6005/pinball-pinball-module.js:913
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (polyfills.js:8071)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.run (polyfills.js:7830)
at polyfills.js:8569
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:8103)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.runTask (polyfills.js:7875)
at drainMicroTaskQueue (polyfills.js:8281)
i @ scripts.js:8
polyfills.js:8071 Uncaught (in promise) Error: cannot add second video track to the conference
at X.addTrack (scripts.js:8)
at :6005/pinball-pinball-module.js:913
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (polyfills.js:8071)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.run (polyfills.js:7830)
at polyfills.js:8569
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:8103)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.runTask (polyfills.js:7875)
at drainMicroTaskQueue (polyfills.js:8281)