datso / react-native-pjsip

A PJSIP module for React Native.
http://datso.github.io/react-native-pjsip
GNU General Public License v3.0
273 stars 229 forks source link

Getting error 'cannot read 'getid' of null, and application crashes when I try to make call. #176

Open uchepercynnoch opened 5 years ago

uchepercynnoch commented 5 years ago

Hi Datso,

Please I need your help. I can initialize pjsip and register a SIP peer with the createAccount method. However, when I try to make call, my App crashes. Here is some part of my code:

ACTION: export const initSip = () => async dispatch => { try { const endpoint = new Endpoint(); const state = await endpoint.start({ service: { ua: Platform.select({ios: "RN iOS", android: "RN Android"}) }, network: { useWifi: true, useOtherNetworks: true } }); dispatch(initialized(endpoint)); } catch (e) { dispatch(initError(e)) } };

export const createSipAccount = configuration => async (dispatch, getState) => { dispatch(creatingAccount()); try { const {endpoint} = getState().sipReducer; const contactUriParams = Platform.select({ ios: [ ";app-id=com.carusto.mobile.app", ], android: ;im-type=sip, });

    await endpoint.createAccount({
        ...configuration,
        transport: configuration.transport ? configuration.transport : "UDP",
        contactUriParams
    }).then(account => {
        endpoint.registerAccount(account, true)
            .then(dispatch(accountCreated(account)))
    }).catch(error => console.log(error));
} catch (e) {
    dispatch(createError(e))
}

};

REDUCER const initialState = { endpoint: null, account: null, };

const sipReducer = (state = initialState, action) => { switch (action.type) { case INIT: return { ...state, endpoint: action.payload }; case ACCOUNT_CREATED: return { ...state, account: action.payload }; default: return state; } };

COMPONENT state = { endpoint: null, account: null };

configuration = {
    "name": "102",
    "username": "102",
    "domain": "192.168.0.110",
    "password": "102",
    "proxy": null,
    "transport": "UDP",
    "regServer": "asterisk",
    "regTimeout": "300",
    "regOnAdd": false
};

constructor(props) {
    super(props);
    this.props.initSip();
}

static getDerivedStateFromProps(nextProps, prevState) {
    if (prevState.endpoint !== nextProps.endpoint) {
        return {
            endpoint: nextProps.endpoint
        }
    }
    if (prevState.account !== nextProps.account) {
        return {
            account: nextProps.account
        }
    }
    return null;
}

handleCreate = () => {
    this.props.createSipAccount(this.configuration);
};

handleCall = async dest => {
    const {endpoint, account} = this.state;
    console.log(account);
    endpoint.makeCall(account, `sip:${dest}@192.168.0.110`)
};

render() {
    const {endpoint} = this.state;
    if (endpoint) {
        return (
            <View>
                <Text>HOME</Text>
                <Button title='CREATE' onPress={this.handleCreate}/>
                <Button title='CALL' onPress={() => this.handleCall('101')}/>
            </View>
        );
    }
    else return null;

}

}

const mapStateToProps = getState => ({ endpoint: getState.sipReducer.endpoint, account: getState.sipReducer.account, });

When I logged 'account' object i got this:

Account {_data: {…}, _registration: AccountRegistration} _data: contactUriParams: ";im-type=sip" domain: "192.168.0.110" id: 0 name: "102" password: "102" regOnAdd: false regServer: "asterisk" regTimeout: "300" registration: {active: false, statusText: "In Progress", status: "PJSIP_SC_TRYING"} transport: "UDP" uri: "102 sip:102@192.168.0.110" username: "102" proto: Object _registration: AccountRegistration _active: false _reason: undefined _status: "PJSIP_SC_TRYING" _statusText: "In Progress" proto: Object proto: Object

I use the following versions for my app development: REACT NATIVE VERSION: 0.59.2 REACT: 16.8.3 ANDROID SDK: 28 JAVA VERSION:1.8 PJSIP VERSION:2.8.0

uchepercynnoch commented 5 years ago

Please somebody help. Anybody please

Yousefjb commented 5 years ago

this works for me

let options = {
            headers: {
                "P-Assserted-Identity": "Header example",
                "X-UA": "CCP Mobile"
            }
        }
        await endpoint.makeCall(account, "8189", options)
uchepercynnoch commented 5 years ago

Thanks Yousefjb, have not tried this. Trying now...

uchepercynnoch commented 5 years ago

Hello Yousefjb, my App still crashes when I try to make call. Please I have ran out of ideas, my account registers fine on asterisk, but the response from pjsip still says this: proto: Object _registration: AccountRegistration _active: false _reason: undefined _status: "PJSIP_SC_TRYING" _statusText: "In Progress" I have a hunch, this is where my problem lies. Any ideas please?

uchepercynnoch commented 5 years ago

Hi Yousefjb I was able to solve my problem. Silly me totally goofed on android permission for SDK 28. Thanks for your helping.

raultang commented 5 years ago

@uchepercynnoch Which permission you added to resolve this issue on SDK 28?

uchepercynnoch commented 5 years ago

@Raul, audio recording.

On Fri, Apr 12, 2019, 8:11 AM raul notifications@github.com wrote:

@uchepercynnoch https://github.com/uchepercynnoch Which permission you added to resolve this issue on SDK 28?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/datso/react-native-pjsip/issues/176#issuecomment-482464390, or mute the thread https://github.com/notifications/unsubscribe-auth/AuxHSKME2VkykMROK8TWWL3QGLm3On4Hks5vgDGLgaJpZM4cX6C1 .

sonalip2 commented 3 years ago

@uchepercynnoch Which permission you added to resolve this issue on SDK 28? Please help us, we are also stuck in same situation.

ReactNDev commented 2 years ago

@sonalip2 have you find out the solution ?? Thanks in advance!