How to use Azure Communications' VideoStreamRenderer in VueJs?

Peter Mumford 1 Reputation point
2021-09-17T00:17:18.507+00:00

I am working on a video conferencing app using Azure Communications APIs and VueJs. I am having trouble rendering video streams using Vue. I can do it with vanilla JS this way:

const rendererLocal = new VideoStreamRenderer(this.localVideoStream)
const view = await rendererLocal.createView({ 'scalingMode': 'Crop' })
document.getElementById('localVideo').appendChild(view.target)

But if I am using VueJs. I want to add the video feed to the state, and render it using a component. I was thinking I could render my video stream with v-html, but this does not work. This is what I have tried:

<template>
    <div id="localVideo" v-html="localVideoStreamView.target"></div>
</template>

<script>
import { VideoStreamRenderer } from '@azure/communication-calling'
export default {
    name: 'VideoDisplay',
    data() {
        return {
            localVideoStreamView: null
        }
    },
    props: {
        localVideoStream: Object,
    },
    mounted() {
        this.displayLocalVideoStream()
    },
    methods: {
        /**
         * Display your local video stream preview in your UI
         */
        async displayLocalVideoStream() {
            try {
                const rendererLocal = new VideoStreamRenderer(this.localVideoStream)
                const view = await rendererLocal.createView({ 'scalingMode': 'Crop' })
                this.localVideoStreamView = view
            } catch (error) {
                console.error(error)
            }
        }
    }
}
</script>
Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
810 questions
{count} votes

1 answer

Sort by: Most helpful
  1. kaniartur 76 Reputation points
    2021-09-21T20:26:37.037+00:00

    Hi

    In order to render stream you have to 'createView' with from the instance of VideoStreamRenderer - I see you're already doing it,
    Next step is to attach 'view.target' to DOM , 'target' references a video container that is used to render video
    Above code snippet seems to have it - can you double check that video element is present in the rendered DOM on the page?