我在javascript中寻找TWILIO的API,我找到了像
这样的东西const { connect, createLocalTracks } = Twilio.Video;
navigator.mediaDevices.enumerateDevices().then(devices => {
var videoInput = devices.find(device => device.kind === 'videoinput');
return createLocalTracks({ audio: true, video: { deviceId: videoInput.deviceId } });
}).then(localTracks => {
return connect('my-token', { name: 'my-room-name', tracks: localTracks });
}).then(room => {
console.log('Connected to room ' + room.name);
});
我无法理解此代码的含义
const { connect, createLocalTracks } = Twilio.Video;
https://www.twilio.com/docs/api/video/configuring-audio-video-inputs-and-outputs
我在打字稿中看到过相同的东西但在核心js中看不到
答案 0 :(得分:3)
这是一项解构任务。它相当于:
const connect = Twilio.Video.connect;
const createLocalTracks = Twilio.Video.createLocalTracks;
有关详细信息,请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment,包括支持哪些浏览器。
答案 1 :(得分:2)
模式是对象解构和赋值,例如
const Twilio = { Video: { connect:1, createLocalTracks:2 } };
const { connect, createLocalTracks } = Twilio.Video;
console.log(connect, createLocalTracks); // 1, 2