@@ -204,7 +204,30 @@ export default defineComponent({
let localStream: any;
let statie = true;
let userSing = '';
- function pingmu(){
+ let type = false;
+ async function qiehuan(){
+ // 1 屏幕分享 2 摄像头
+ client.unpublish(localStream)
+ localStream = type ? TRTC.createStream({ userid: 10, audio: true, screen: true }) : TRTC.createStream({ userId: 10, audio: true, video: true });
+ type = !type;
+ localStream.initialize().then(()=>{
+ client
+ .publish(localStream)
+ .catch((error: string) => {
+ console.error('本地流发布失败 ' + error);
+ })
+ .then(() => {
+ const el = document.querySelector("#local_stream");
+ if(el){
+ el.innerHTML = ""
+ }
+ localStream.play('local_stream');
+ console.log('本地流发布成功');
+ });
+ });
+
+ }
+ function pingmu(){
localStream = TRTC.createStream({ userid: 10, audio: true, screen: true });
localStream
@@ -255,7 +278,19 @@ export default defineComponent({
mode: 'rtc',
sdkAppId: '1400400340',
userId: 10,
- userSig: userSig
+ userSig: 'eJw1zMsKwjAUBNB-yVrqzatowaU7UcQgGNxEG5tLUGNSxQf*u7FWmM2cgXkRNVsVNxtJRVgBZNB1rO2pxQN2TP*aam9CwJpUVADkcAG-xd4DRptdSskAem3x*LUSOOdjoL0mbPLpvtx5rRbb4RIla86XBxNGKTePI391T64N6jQFgRu3ThPy-gBYczBk'
+ });
+ client.on('stream-added', (event: { stream: any }) => {
+ const remoteStream = event.stream;
+ console.log('远端流增加: ' + remoteStream.getId());
+ //订阅远端流
+ client.subscribe(remoteStream);
+ });
+ client.on('stream-subscribed', (event: { stream: any }) => {
+ const remoteStream = event.stream;
+ console.log('远端流订阅成功:' + remoteStream.getId());
+ // 播放远端流
+ remoteStream.play('s-' + remoteStream.getId());
});
client
.join({ roomId: 11 })
@@ -293,7 +328,8 @@ export default defineComponent({
})
return{
- fenxiang
+ fenxiang,
+ qiehuan
}
},
});