Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue3 + opentok #369

Open
kobrynovych opened this issue Feb 9, 2024 · 0 comments
Open

vue3 + opentok #369

kobrynovych opened this issue Feb 9, 2024 · 0 comments

Comments

@kobrynovych
Copy link

I get an error when trying to migrate a project from vue2 to vue3.

In vue3 this line of code throws an error
this.session.publish()

an example of an error:
OpenTok:SessionDispatcher:error Error occurred during processMessage +0ms TypeError: 'get' on proxy: property '_rawSessionInfo' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '#<Object>' but got '#<Object>')

I use:
"vue": "^3.4.16",
"@opentok/client": "^2.27.1",

my code:

<template>
    <div>
        <div id="publisher"></div>
    </div>
</template>

<script>
    import OT from '@opentok/client';
    import adapter from 'webrtc-adapter';

    export default {
        data() {
            return {
                session: null,
                publisher: null,
                apiKey: '',
                sessionId: '',
                token: '',
            };
        },

        mounted() {
            this.getToken();
        },

        beforeUnmount() {
            if (this.publisher) {
                this.publisher.publishVideo(false);
                this.publisher.publishAudio(false);

                if (this.publisher.session) {
                    this.session.unpublish(this.publisher);
                }

                this.publisher.destroy();
                this.publisher = null;
            }

            this.session.off();
            this.session.disconnect();
            this.session = null;
        },

        methods: {
            getToken() {
                let route = this.route('token_url');

                axios.get(route)
                    .then(({ data }) => {
                        if (data.success) {
                            this.apiKey = data.apiKey;
                            this.sessionId = data.session;
                            this.token = data.token;

                            this.initSession();
                        } else {
                            console.log('error getToken(): ');
                        }
                    })
                    .catch(err => {
                        console.log('error getting token: ', err);
                    });
            },

            initSession() {
                this.session = OT.initSession(this.apiKey, this.sessionId);
                this.publisher = OT.initPublisher('publisher');

                this.session.connect(this.token, (error) => {
                    if (error) {
                        console.error('Failed to connect', error);
                    } else {
                        this.session.publish(this.publisher, (error) => {
                            if (error) {
                                console.error('Failed to publish', error);
                            } else {
                                console.log('+ this.session.publish :');
                            }
                        });
                    }
                });
            },
        },
    };
</script>

I will be very grateful for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant