ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
125 stars 111 forks source link

Undefined is not an object(evaluating this.auth.createSession) #127

Closed GuleriaAshish closed 3 years ago

GuleriaAshish commented 3 years ago

I am using connectycube library for implementing video call functionality in my app. While creating a session i am getting this error "Undefined is not an object(evaluating this.auth.createSession)".

Code details:=> ReactNative: 0.63.2 Connectycube: 3.7.2

Code:=> 1) Methods decleration: import ConnectyCube from 'react-native-connectycube'; import {credentials} from "../config";

export default class AuthService{

init = () => ConnectyCube.init(credentials);

login = user => {
    return new Promise((resolve, reject) => {
        ConnectyCube.createSession(user)
            .then(() =>
                ConnectyCube.chat.connect({
                    userId: user.id,
                    password: user.password,
                }),
            )
            .then(resolve)
            .catch(reject);
    });
};

logout = () => {
    ConnectyCube.chat.disconnect();
    ConnectyCube.destroySession();
};

}

2) Usage: let user = { id: socialResponse.data.user_data.id, password: socialResponse.data.user_data.email }

                    const _onSuccessLogin = (success) => {
                        console.warn("success", success)
                    };

                    const _onErrorLogin = (error) => {
                        console.warn("error", error)
                    }

                    ConnectycubeAuthServices.login(user)
                        .then(_onSuccessLogin)
                        .catch(_onErrorLogin)

Please suggest me where i am doing wrong.

ccvlad commented 3 years ago

Hi @GuleriaAshish

Please check that you have called your ConnectycubeAuthServices.init() before ConnectycubeAuthServices.login(user). Means you should do ConnectyCube.init(credentials) to initialize ConnectyCube's construtors (e.g. this.auth).

GuleriaAshish commented 3 years ago

Thanks for the quick reply @ccvlad .Yes i have added this. See above code of AuthServices class under declaration.

ccvlad commented 3 years ago

In the code above I see that you announced class AuthService that exists methods init, login, logout. But next you are just calling ConnectycubeAuthServices.login(user). That all that I am able to see in your previous message

GuleriaAshish commented 3 years ago

Okay i got your point, let me check it.

GuleriaAshish commented 3 years ago

@ccvlad , previous error is gone now but a new one arises. "undefined is not an object (evaluating key.sigbytes)", have any idea about it ?

DaveLomber commented 3 years ago

@GuleriaAshish please show how you use 'init' method and what values you pass there

GuleriaAshish commented 3 years ago

@DaveLomber, I figured it out yesterday. Actually i was send an array rather than objects in init() method.

I need to ask you that what basic steps should i follow to implement video calling functionality in my existing app. Steps that i follow till now: 1) I have a react native app. 2) I have added it to the connectycube portal and generated APP Id . authSecret and authKey 3) call init method with above generated params 4) Now i need to create a session for video calling and i want to use my apps login credentials.

Now i am stuck at point 4 as createSession returns "unauthorised" error.

Please suggest!!

ccvlad commented 3 years ago
  1. Init the ConnectyCube - https://developers.connectycube.com/js/?id=initialize
  2. Create the ConnectyCube session - https://developers.connectycube.com/js/authentication-and-users?id=create-session-token
  3. If you need to create a new user and login(sign-up) - https://developers.connectycube.com/js/authentication-and-users?id=user-signup
  4. If you already have an user (login with user, will upgrade an empty session to the session with user) - https://developers.connectycube.com/js/authentication-and-users?id=upgrade-session-token-user-login
  5. Connect to chat (need for signaling) - https://developers.connectycube.com/js/messaging?id=connect-to-chat
  6. Read the doc how to use the Video Calling - https://developers.connectycube.com/js/videocalling.

The React Native Video Calling doc - https://developers.connectycube.com/reactnative/videocalling The React Native Video Calling sample (demo) - https://github.com/ConnectyCube/connectycube-reactnative-samples/tree/master/RNVideoChat

I close the issue, cause the error "Undefined is not an object(evaluating this.auth.createSession)" was resolved. Please create a new issue for other question/problem.