podchat-browser
Version:
Javascript SDK to use POD's Chat Service - Browser Only
69 lines (63 loc) • 2.38 kB
JavaScript
import CallManager from "./callManager";
import CallServerManager from "./callServerManager";
import MultiTrackCallManager from "./multitrack/callManager";
function CallsList(app) {
const config = {
list: {},
currentCallId: null
};
const publicized = {
async addItem(callId, callConfig) {
const csm = new CallServerManager(app);
csm.setServers(callConfig.kurentoAddress);
if (Object.values(config.list).filter(item => item != undefined).length) {
try {
await publicized.destroyAllCalls();
} catch (error) {
console.error({error})
}
}
config.currentCallId = callId;
if (csm.isJanus()) {
config.list[callId] = new MultiTrackCallManager({app, callId, callConfig});
} else {
config.list[callId] = new CallManager({app, callId, callConfig});
}
},
async removeItem(callId) {
if (config.list[callId]) {
await config.list[callId].destroy();
delete config.list[callId];
}
config.currentCallId = null;
},
get(id) {
return config.list[id]
},
currentCallId(){
return config.currentCallId;
},
routeCallMessage(callId, message) {
if (config.list[callId]){
config.list[callId].callMessageQueue.pushCallMessageToQueue(message);
// config.list[callId].processCallMessage(message);
} else
app.sdkParams.consoleLogging && console.warn("[SDK] Skipping call message, call not exists. uniqueId: ", {message})
},
destroyAllCalls() {
return new Promise(resolve => {
let allPromises = [];
for (let i in config.list) {
console.log("destroyAllCalls()", i);
app.call.endCall({callId: i})
allPromises.push(publicized.removeItem(i));
}
Promise.all(allPromises).then(() => {
resolve()
})
})
}
}
return publicized;
}
export default CallsList