<template>
    <view>
        <view class="video">
            <RongCloud-Call-RCUniCallView style="width: 100%;height: 100%" ref="bigVideoView">
            </RongCloud-Call-RCUniCallView>
        </view>

        <button type="default" @click="accept">接听</button>
        <button type="default" @click="hangup">挂断</button>
        <button type="default" @click="toHome">回主页</button>
    </view>
</template>

<script>
    import * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index'
    export default {
        data() {
            return {
                targetId: '',
                users: []
            }
        },
        onLoad(e) {
            this.targetId = e.targetId
        },
        methods: {
            accept() {
                CallLib.accept()

                CallLib.enableCamera(true, 0)

                const currentCallSession = CallLib.getCurrentCallSession()
                console.log(currentCallSession);
                this.users = currentCallSession.users
                setTimeout(() => {
                    CallLib.setVideoView(currentCallSession.mine.userId, 'bigVideoView', 0, true)
                }, 500);
            },
            hangup() {
                CallLib.hangup()

                setTimeout(() => {
                    uni.navigateBack()
                }, 200);
            },
            toHome() {
                uni.switchTab({
                    url: '/pages/im/index'
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .video {
        width: 100vw;
        height: 100vw;
    }
</style>
