提交工单
咨询集成、功能及报价等问题
Express SDK version 3.0.0 optimizes the internal logic of the SDK, improves the stability of the SDK, the quality of audio and video calls, and the ease of use of the API interface. ZEGOCLOUD strongly recommends that you use the SDK version 3.0.0 or above.
This article provides general instructions and precautions when you upgrade the Express SDK version to 3.0.0 or above.
The following interfaces will be officially abandoned in version 3.0.0. Please update your code logic in time to avoid affecting the normal use of your business.
method name | Description |
---|---|
createStream | Create publish data sources, including camera and microphone collection source data, screen sharing data, third-party source data, etc. You can use createZegoStream to implement the original function. |
createLocalStreamView | Create a local media stream player component instance object. You can:
|
Add, replace, and remove audio and video tracks. You can:
|
You can refer to the following sample code to change the interface.
// Create camera microphone stream by default
const stream = zg.createStream()
// Create media stream playback component
const viewer = zg.createLocalStreamView(stream);
// Play media stream
viewer.play(divElem);
// Start publishing
zg.startPublishingStream(publishID, stream);
// Create a third-party stream
const customStream = await zg.createStream({
custom: {
source: $('#customVideo')[0]
}
})
// Replace the preview video track of stream, and update the publishing streams
const videoTrack = customStream.getVideoTracks()[0]
await zg.replaceTrack(stream, videoTrack)
// Replace the preview audio track of stream, and update the publishing streams
const audioTrack1 = customStream.getAudioTracks()[0]
await zg.replaceTrack(stream, audioTrack1)
// Remobe the preview audio track of stream, and update the publishing streams
const audioTrack2 = stream.getAudioTracks()[0]
await zg.removeTrack(stream, audioTrack2)
// Add a preview video track of stream, and update the publishing streams
const stream2 = await zg.createStream({camera: {video: false, audio: true}});
const audioTrack3 = stream2.getAudioTracks()[0]
await zg.addTrack(stream2, audioTrack3)
// Create a Camera and microphone stream by default
const zegoLocalStream = await zg.createZegoStream()
// Play the newest collected video and audio
zegoLocalStream.playCaptureVideo(divElem);
zegoLocalStream.playCaptureAudio();
// Play videos and audios that are to be pushed or are already in the push stream. After the push is successful, the subsequent collection of zegoLocalStream will not be updated to the push stream synchronously. UpdatePublishingStream needs to be called for updates.
zegoLocalStream.playVideo(divElem);
zegoLocalStream.playAudio();
// Start publishing
zg.startPublishingStream(publishID, zegoLocalStream);
// Start capture a third-party video stream
const result1 = await zegoLocalStream.startCaptureCustomVideo({
source: $('#customVideo')[0]
})
// Update the push stream to the latest collected third-party video stream, 0 is the updated video stream
await zg.updatePublishingStream(zegoLocalStream, 0)
// Start capture a third-party audio stream
const result2 = await zegoLocalStream.startCaptureCustomAudio({
source: $('#externerAudio')[0]
})
// Update the push stream to the latest collected third-party audio stream, 1 is to update the audio stream
await zg.updatePublishingStream(zegoLocalStream, 1)
// Collect microphone audio stream
const result3 = await zegoLocalStream.startCaptureMicrophone()
// Update the push stream to the latest collected microphone audio stream, 1 is to update the audio stream
await zg.updatePublishingStream(zegoLocalStream, 1)
// Stop collecting videos and update the publish stream synchronously
zegoLocalStream.stopCaptureVideo();
// Stop collecting audios and update the publish stream synchronously
zegoLocalStream.stopCaptureAudio();