ERROR Failed to make a call: logger.debug is not a function (it is undefined) using sip.js with React-Native-WebRTC

I am using sip.js with React-Native-WebRTC for audio calling feature in react native app but getting this error when trying to make outgoing call with Inviter.invite()

here my simplest code is

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { RTCPeerConnection, mediaDevices } from 'react-native-webrtc';
import { UserAgent, Registerer, URI, Inviter } from 'sip.js';
import SipKeys from '../utils/SipKeys';
import customSessionDescriptionHandlerFactory from './customSessionDescriptionHandlerFactory';
import InCallManager from 'react-native-incall-manager';
import { logger } from './logger'
const configuration = {
iceServers: [
{ urls: SipKeys.stunUri, username: SipKeys.username, credential: SipKeys.password },
{ urls: SipKeys.turnUri, username: SipKeys.username, credential: SipKeys.password },
{ urls: SipKeys.gStunUri, username: SipKeys.username, credential: SipKeys.password }
],
iceTransportPolicy: 'all',
bundlePolicy: 'balanced',
rtcpMuxPolicy: 'require',
};
const createMockMediaStream = async () => {
try {
const stream = await mediaDevices.getUserMedia({ audio: true, video: false });
console.debug('Stream created');
return stream;
} catch (error) {
console.error('Error creating media stream', error);
throw error;
}
};
const createPeerConnection = async () => {
console.debug('Initializing PeerConnection...');
const peerConnection = new RTCPeerConnection(configuration);
console.debug('PeerConnection initialized');
peerConnection.onicecandidate = (iceEvent) => {
if (iceEvent.candidate) {
console.debug('ICE Candidate found');
}
};
peerConnection.onsignalingstatechange = () => {
console.debug(`Signaling State: ${peerConnection.signalingState}`);
};
peerConnection.onnegotiationneeded = async () => {
console.debug('Negotiation needed');
};
peerConnection.ontrack = (event) => {
console.debug('Track event');
};
peerConnection.onremovetrack = (event) => {
console.debug('Remove track event');
};
const localStream = await createMockMediaStream();
console.debug('Local stream obtained');
localStream.getTracks().forEach(track => {
console.debug('Adding track');
peerConnection.addTrack(track, localStream);
});
const offer = await peerConnection.createOffer();
await peerConnection.setLocalDescription(offer);
console.debug('Offer created');
return peerConnection;
};
const connectToSIP = async () => {
try {
const uri = new URI('sip', SipKeys.username, SipKeys.uri);
const userAgentOptions = {
uri,
transportOptions: {
server: SipKeys.wsServers
},
authorizationUsername: SipKeys.username,
authorizationPassword: SipKeys.password,
sessionDescriptionHandlerFactoryOptions: {
peerConnectionOptions: { rtcConfiguration: configuration }
},
sessionDescriptionHandlerFactory: customSessionDescriptionHandlerFactory,
sipExtension100rel: 'REQUIRED',
viaHost: SipKeys.uri,
autostart: true, // Autostart the UserAgent
};
const loggerObj = {
logBuiltinEnabled: true, // Disable built-in logging if needed
logLevel: 'debug', // Set desired log level
logConnector: logger, // Use the custom logger
}
// Log the configuration to ensure logger is correctly passed
console.log('UserAgent configuration:', userAgentOptions);
const userAgent = new UserAgent(userAgentOptions, loggerObj);
userAgent.delegate = {
onConnect: () => console.debug('SIP Connected'),
onDisconnect: () => console.debug('SIP Disconnected'),
};
userAgent.transport.onConnect = () => console.debug('Transport Connected');
userAgent.transport.onDisconnect = (error) => console.error('Transport Disconnected', error);
const registerer = new Registerer(userAgent);
registerer.stateChange = (newState) => {
if (newState === 'Unregistered' || newState === 'Terminated') {
console.error('SIP Registration state changed:', newState);
}
};
await userAgent.start();
const registererOptions = {
requestDelegate: {
onAccept: (response) => console.debug('SIP Registered successfully!', response),
onReject: (response) => console.error('SIP Registration failed', response),
}
};
registerer.register(registererOptions);
InCallManager.start({ media: 'audio' });
setTimeout(() => {
initiateOutgoingCall(userAgent);
}, 1500);
return { userAgent, registerer, configuration };
} catch (error) {
console.error('Failed to connect to SIP', error);
}
};
const initiateOutgoingCall = async (userAgent) => {
try {
const target = new URI('sip', SipKeys.targetUri, SipKeys.uri);
const inviter = new Inviter(userAgent, target, {
earlyMedia: true,
allowEarlyMedia: true,
inviteWithoutSdp: false,
sessionDescriptionHandlerOptions: {
constraints: { audio: true, video: false },
peerConnectionOptions: { rtcConfiguration: configuration },
iceGatheringTimeout: 200,
},
});
inviter.delegate = {
onInvite: () => console.debug('Invite event triggered'),
onAccepted: () => console.debug('Call accepted'),
onProgress: response => console.debug('Call in progress', response),
onTerminated: (message, cause) => console.error(`Call terminated: ${cause}`)
};
console.debug('Inviting...');
await inviter.invite();
} catch (error) {
console.error(`Failed to make a call: ${error.message}`);
}
};
</code>
<code>import { RTCPeerConnection, mediaDevices } from 'react-native-webrtc'; import { UserAgent, Registerer, URI, Inviter } from 'sip.js'; import SipKeys from '../utils/SipKeys'; import customSessionDescriptionHandlerFactory from './customSessionDescriptionHandlerFactory'; import InCallManager from 'react-native-incall-manager'; import { logger } from './logger' const configuration = { iceServers: [ { urls: SipKeys.stunUri, username: SipKeys.username, credential: SipKeys.password }, { urls: SipKeys.turnUri, username: SipKeys.username, credential: SipKeys.password }, { urls: SipKeys.gStunUri, username: SipKeys.username, credential: SipKeys.password } ], iceTransportPolicy: 'all', bundlePolicy: 'balanced', rtcpMuxPolicy: 'require', }; const createMockMediaStream = async () => { try { const stream = await mediaDevices.getUserMedia({ audio: true, video: false }); console.debug('Stream created'); return stream; } catch (error) { console.error('Error creating media stream', error); throw error; } }; const createPeerConnection = async () => { console.debug('Initializing PeerConnection...'); const peerConnection = new RTCPeerConnection(configuration); console.debug('PeerConnection initialized'); peerConnection.onicecandidate = (iceEvent) => { if (iceEvent.candidate) { console.debug('ICE Candidate found'); } }; peerConnection.onsignalingstatechange = () => { console.debug(`Signaling State: ${peerConnection.signalingState}`); }; peerConnection.onnegotiationneeded = async () => { console.debug('Negotiation needed'); }; peerConnection.ontrack = (event) => { console.debug('Track event'); }; peerConnection.onremovetrack = (event) => { console.debug('Remove track event'); }; const localStream = await createMockMediaStream(); console.debug('Local stream obtained'); localStream.getTracks().forEach(track => { console.debug('Adding track'); peerConnection.addTrack(track, localStream); }); const offer = await peerConnection.createOffer(); await peerConnection.setLocalDescription(offer); console.debug('Offer created'); return peerConnection; }; const connectToSIP = async () => { try { const uri = new URI('sip', SipKeys.username, SipKeys.uri); const userAgentOptions = { uri, transportOptions: { server: SipKeys.wsServers }, authorizationUsername: SipKeys.username, authorizationPassword: SipKeys.password, sessionDescriptionHandlerFactoryOptions: { peerConnectionOptions: { rtcConfiguration: configuration } }, sessionDescriptionHandlerFactory: customSessionDescriptionHandlerFactory, sipExtension100rel: 'REQUIRED', viaHost: SipKeys.uri, autostart: true, // Autostart the UserAgent }; const loggerObj = { logBuiltinEnabled: true, // Disable built-in logging if needed logLevel: 'debug', // Set desired log level logConnector: logger, // Use the custom logger } // Log the configuration to ensure logger is correctly passed console.log('UserAgent configuration:', userAgentOptions); const userAgent = new UserAgent(userAgentOptions, loggerObj); userAgent.delegate = { onConnect: () => console.debug('SIP Connected'), onDisconnect: () => console.debug('SIP Disconnected'), }; userAgent.transport.onConnect = () => console.debug('Transport Connected'); userAgent.transport.onDisconnect = (error) => console.error('Transport Disconnected', error); const registerer = new Registerer(userAgent); registerer.stateChange = (newState) => { if (newState === 'Unregistered' || newState === 'Terminated') { console.error('SIP Registration state changed:', newState); } }; await userAgent.start(); const registererOptions = { requestDelegate: { onAccept: (response) => console.debug('SIP Registered successfully!', response), onReject: (response) => console.error('SIP Registration failed', response), } }; registerer.register(registererOptions); InCallManager.start({ media: 'audio' }); setTimeout(() => { initiateOutgoingCall(userAgent); }, 1500); return { userAgent, registerer, configuration }; } catch (error) { console.error('Failed to connect to SIP', error); } }; const initiateOutgoingCall = async (userAgent) => { try { const target = new URI('sip', SipKeys.targetUri, SipKeys.uri); const inviter = new Inviter(userAgent, target, { earlyMedia: true, allowEarlyMedia: true, inviteWithoutSdp: false, sessionDescriptionHandlerOptions: { constraints: { audio: true, video: false }, peerConnectionOptions: { rtcConfiguration: configuration }, iceGatheringTimeout: 200, }, }); inviter.delegate = { onInvite: () => console.debug('Invite event triggered'), onAccepted: () => console.debug('Call accepted'), onProgress: response => console.debug('Call in progress', response), onTerminated: (message, cause) => console.error(`Call terminated: ${cause}`) }; console.debug('Inviting...'); await inviter.invite(); } catch (error) { console.error(`Failed to make a call: ${error.message}`); } }; </code>
import { RTCPeerConnection, mediaDevices } from 'react-native-webrtc';
import { UserAgent, Registerer, URI, Inviter } from 'sip.js';
import SipKeys from '../utils/SipKeys';
import customSessionDescriptionHandlerFactory from './customSessionDescriptionHandlerFactory';
import InCallManager from 'react-native-incall-manager';
import { logger } from './logger'

const configuration = {
  iceServers: [
    { urls: SipKeys.stunUri, username: SipKeys.username, credential: SipKeys.password },
    { urls: SipKeys.turnUri, username: SipKeys.username, credential: SipKeys.password },
    { urls: SipKeys.gStunUri, username: SipKeys.username, credential: SipKeys.password }
  ],
  iceTransportPolicy: 'all',
  bundlePolicy: 'balanced',
  rtcpMuxPolicy: 'require',
};

const createMockMediaStream = async () => {
  try {
    const stream = await mediaDevices.getUserMedia({ audio: true, video: false });
    console.debug('Stream created');
    return stream;
  } catch (error) {
    console.error('Error creating media stream', error);
    throw error;
  }
};

const createPeerConnection = async () => {
  console.debug('Initializing PeerConnection...');
  const peerConnection = new RTCPeerConnection(configuration);
  console.debug('PeerConnection initialized');

  peerConnection.onicecandidate = (iceEvent) => {
    if (iceEvent.candidate) {
      console.debug('ICE Candidate found');
    }
  };

  peerConnection.onsignalingstatechange = () => {
    console.debug(`Signaling State: ${peerConnection.signalingState}`);
  };

  peerConnection.onnegotiationneeded = async () => {
    console.debug('Negotiation needed');
  };

  peerConnection.ontrack = (event) => {
    console.debug('Track event');
  };

  peerConnection.onremovetrack = (event) => {
    console.debug('Remove track event');
  };

  const localStream = await createMockMediaStream();
  console.debug('Local stream obtained');

  localStream.getTracks().forEach(track => {
    console.debug('Adding track');
    peerConnection.addTrack(track, localStream);
  });

  const offer = await peerConnection.createOffer();
  await peerConnection.setLocalDescription(offer);
  console.debug('Offer created');

  return peerConnection;
};

const connectToSIP = async () => {
  try {
    const uri = new URI('sip', SipKeys.username, SipKeys.uri);

    const userAgentOptions = {
      uri,
      transportOptions: {
        server: SipKeys.wsServers
      },
      authorizationUsername: SipKeys.username,
      authorizationPassword: SipKeys.password,
      sessionDescriptionHandlerFactoryOptions: {
        peerConnectionOptions: { rtcConfiguration: configuration }
      },
      sessionDescriptionHandlerFactory: customSessionDescriptionHandlerFactory,
      sipExtension100rel: 'REQUIRED',
      viaHost: SipKeys.uri,
      autostart: true, // Autostart the UserAgent
    };
    const loggerObj = {
      logBuiltinEnabled: true, // Disable built-in logging if needed
      logLevel: 'debug', // Set desired log level
      logConnector: logger, // Use the custom logger
    }
    // Log the configuration to ensure logger is correctly passed
    console.log('UserAgent configuration:', userAgentOptions);

    const userAgent = new UserAgent(userAgentOptions, loggerObj);

    userAgent.delegate = {
      onConnect: () => console.debug('SIP Connected'),
      onDisconnect: () => console.debug('SIP Disconnected'),
    };

    userAgent.transport.onConnect = () => console.debug('Transport Connected');
    userAgent.transport.onDisconnect = (error) => console.error('Transport Disconnected', error);

    const registerer = new Registerer(userAgent);

    registerer.stateChange = (newState) => {
      if (newState === 'Unregistered' || newState === 'Terminated') {
        console.error('SIP Registration state changed:', newState);
      }
    };

    await userAgent.start();

    const registererOptions = {
      requestDelegate: {
        onAccept: (response) => console.debug('SIP Registered successfully!', response),
        onReject: (response) => console.error('SIP Registration failed', response),
      }
    };

    registerer.register(registererOptions);

    InCallManager.start({ media: 'audio' });

    setTimeout(() => {
      initiateOutgoingCall(userAgent);
    }, 1500);

    return { userAgent, registerer, configuration };
  } catch (error) {
    console.error('Failed to connect to SIP', error);
  }
};

const initiateOutgoingCall = async (userAgent) => {
  try {
    const target = new URI('sip', SipKeys.targetUri, SipKeys.uri);
    const inviter = new Inviter(userAgent, target, {
      earlyMedia: true,
      allowEarlyMedia: true,
      inviteWithoutSdp: false,
      sessionDescriptionHandlerOptions: {
        constraints: { audio: true, video: false },
        peerConnectionOptions: { rtcConfiguration: configuration },
        iceGatheringTimeout: 200,
      },
    });

    inviter.delegate = {
      onInvite: () => console.debug('Invite event triggered'),
      onAccepted: () => console.debug('Call accepted'),
      onProgress: response => console.debug('Call in progress', response),
      onTerminated: (message, cause) => console.error(`Call terminated: ${cause}`)
    };

    console.debug('Inviting...');
    await inviter.invite();
  } catch (error) {
    console.error(`Failed to make a call: ${error.message}`);
  }
};

I am trying to make outgoing call using sip.js with React-Native-WebRTC but stuck with this error

ERROR Failed to make a call: logger.debug is not a function (it is undefined)

getting this error on Inviter.invite();

New contributor

Gurpreet Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật