使用JSSIP在From标头中传递PSTN的呼叫者ID

huangapple go评论55阅读模式
英文:

Passing CallerID for PSTN in From Header using JSSIP

问题

I'll provide a translation of the code portion you've provided:

我正在使用 JsSIP 连接到 FreeSwitch然后连接到 PSTN我想在 From 头部传递呼叫者 ID我的代码大致设置如下

var TheCallerIDTest = '+33...以 E164 格式的号码';
var TheSipClient = new JsSIP.UA({....}); //工作正常

var TheHandlers = {
   
    'sending': function (e) {

        var TheSipURI = new JsSIP.URI('sip', TheCallerIDTest, 'MyFreeswitchServerUrl', 5060, null, null);
        var TheHeader = new JsSIP.NameAddrHeader(TheSipURI, '', null);

        //显示正确的 From 头部
        console.log(TheHeader);

        //这里是我想要修改 INVITE 请求的地方
        e.from = TheHeader; 
    },
}

var TheCallOptions = {

    'eventHandlers': TheHandlers,
    'mediaConstraints': { 'audio': true, 'video': false }
};

function TestCall() {

    TheSipClient.start();

    TheSipClient.call("+33...E164 号码", TheCallOptions);
}

Please note that I've translated the code portion as requested, excluding the non-code content and the request for translation assistance. If you have any specific questions or need further assistance with this code, please let me know.

英文:

I'm using JsSIP to connect to FreeSwitch and then to the PSTN. I'm looking to pass the callerID in the From header. I have my code set up somewhat like this:

var TheCallerIDTest = '+33...number in E164 format';
var TheSipClient = new JsSIP.UA({....}); //works fine

var TheHandlers = {
   
	'sending': function (e) {

	    var TheSipURI = new JsSIP.URI('sip', TheCallerIDTest, 'MyFreeswitchServerUrl', 5060, null, null);
		var TheHeader = new JsSIP.NameAddrHeader(TheSipURI, '', null);

        //displays the correct From header just fine
        console.log(TheHeader);

        //here's where I want to modify the INVITE request
		e.from = TheHeader; 
	},
}

var TheCallOptions = {

	'eventHandlers': TheHandlers,
	'mediaConstraints': { 'audio': true, 'video': false }
};

function TestCall() {

	TheSipClient.start();

	TheSipClient.call("+33...E164 number", TheCallOptions);
}

Looking at the documentation, https://jssip.net/documentation/3.3.x/api/session/#event_sending, I'm hoping the add a JsSIP.NameAddrHeader to the 'from' header of the JsSIP.OutgoingRequest INVITE request. The console output logs the correct From header I want to add.

However, when I look at the JsSIP:RTCSession emit "sending" [request:InitialOutgoingInviteRequest console log, it's not showing the header I want to add, and the From header that's received on the server is not the one I want to send.

What do I need to change in my code to make it work?

答案1

得分: 1

你需要这样做:

e.request.headers.From[0] = TheHeader;

也可能有必要移除一些你不想发送的其他标头。

英文:

You need to do like this:

e.request.headers.From[0] = TheHeader;

Also probably this make sense to remove some other headers you do not want to send.

答案2

得分: 0

Latest version 3.10.x of JsSIP supports setting from and display name in the ua call options itself.

ua.call('sip:bob@example.com', {fromUserName:"<caller id>"});

英文:

Latest version 3.10.x of JsSIP supports setting from and display name in the ua call options itself.

ua.call('sip:bob@example.com', {fromUserName:"<caller id>"});

huangapple
  • 本文由 发表于 2020年1月6日 17:31:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609612.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定