如何使用Sinch PSTN JS-SDK中的Web到电话来接听电话

时间:2019-03-08 10:53:35

标签: sinch

这是我遇到的问题,例如我可以使用短拨JS-SDK PSTN拨打电话。

样本,但:
1)用户拨打短号时,我无法接听电话
2)我尝试了使用回调API来获得传入呼叫的​​另一种方式,我正在获得传入呼叫,但是我无法呼叫电话号码,但是我能够使用username()方法进行呼叫意味着在网络到网络的通话中完美运行。

现在主要问题如果在sinch-app仪表板中添加回调URL ,则它不允许使用callphonenumber()方法拨打电话号码如果我从sinch仪表板中删除了回调URL < / strong>,那么它将起作用,但我不明白为什么?这是紧急问题还是什么?

如何设置回调URL以使用Sinch JS-SDK来接听来电?

请帮助我解决这个问题,我们将不胜感激!

我的代码

    constructor(private _leadService: LeadService, private el: ElementRef, private renderedOb: Renderer2, private location: Location, private _router: Router, private _userService: UserService, private route: ActivatedRoute, private fb: FormBuilder) {
        this.sinchClient = new SinchClient({
            applicationKey: 'apk key',
            capabilities: { calling: true },
            supportActiveConnection: true,
            startActiveConnection: true,
            onLogMessage: function (message) {
                console.log(message);
            },

        });
        //start sinch-client to iniatiate call

this.sinchClient.start({ username: 'prashanth@zibtek.in', password: '123456' })
            .then(function () {
                // Perform actions to do when authenticated, such as displaying user interface
            });

    }


    ngOnInit() {
        this.callForm = this.fb.group({
            To: ['', Validators.required],
            code: ['', Validators.required]
        });

        var callClient = this.sinchClient.getCallClient();
        callClient.initStream().then(function () {
        });

    }


    ngAfterViewInit() {
        this.audioProgress = document.createElement('audio');
        this.audioIncoming = document.createElement('audio');
        this.audioRingTone = document.createElement('audio');


        //Listen call events os sinch
        this.callListeners = {
            onCallProgressing: (call) => {
                this.iscallstatus = false;
                this.callingStatus = "Ringing....";
                this.audioProgress.src = 'assets/sounds/ringback.wav';
                this.audioProgress.loop = true;
                this.audioProgress.play();

            },
            onCallEstablished: (call) => {
                this.isTimer = true;
                this.StartTimer()
                this.callingStatus = "Connected ...";
                this.audioIncoming.srcObject = call.incomingStream;
                this.audioIncoming.play();
                this.audioProgress.pause();

                //Report call status
                const callDetails = call.getDetails();
                const callAnswer = (callDetails.establishedTime && new Date(callDetails.establishedTime))
                console.log('Answer at:', callAnswer)
                console.log(callDetails)
            },
            onCallEnded: (call) => {
                this.callingStatus = "Ended ...";
                this.audioProgress.pause();
                this.audioIncoming.srcObject = null;
                localStorage.removeItem('callno');
                this.isphoneCallPopup = true;
                this.iscallinput = true;



                //Report call details
                this.callDetails = call.getDetails();
                this.endedtime = new Date(this.callDetails.endedTime);
                this.callduration = this.callDetails.duration;
                this.CallEstablishedtime = new Date(this.callDetails.establishedTime);
                this.callendcause = call.getEndCause()
                this.startedtime = new Date(this.callDetails.startedTime);

                //details of phone-call
                this.callData = {
                    To: this.callForm.value.To,
                    leadId: this.leadid,
                    endedTime: new Date(this.callDetails.endedTime),
                    callduration: this.callDetails.duration,
                    CallEstablishedtime: new Date(this.callDetails.establishedTime),
                    callendcause: call.getEndCause(),
                    startedtime: new Date(this.callDetails.startedTime)
                }

                this._leadService.makeCall(this.callData).subscribe((data) => {
                    //console.log("calldetailsform value", data);
                })

                if (call.error) {
                    let errormessage = call.error.message;
                    console.log(errormessage)
                }
            },


        }

        // receive incoming call

        this.callClient = this.sinchClient.getCallClient();
        this.callClient.initStream().then(() => {
        });
        this.callClient.addEventListener({
            onIncomingCall: (incomingCall: any) => {
                //Play some groovy tunes 
                this.callingStatus = "Ringing....";
                this.audioRingTone.src = 'assets/sounds/phone_ring.wav';
                this.audioRingTone.loop = true;
                this.audioRingTone.play();
                console.log('incomingCall', incomingCall);
                incomingCall.addEventListener(this.callListeners);
            }

        })
        //end of receiving call


    }

    //  start calling
    onCalling(number: any) {
        this.callClient = this.sinchClient.getCallClient();
        this.callClient.initStream().then(function (data) {
        });
        this.call = this.callClient.callPhoneNumber(number);
        this.call.addEventListener(this.callListeners);
    }
    async callNum(number: any, code: any) {
        localStorage.getItem('callno');
        var callingNumber = code + "" + number;
        await this.onCalling(callingNumber);
        this.iscallinput = true;
    }
    //end of calling method


    //mute or unmute 
    onMute() {
        this.isMicof = true;
        this.isMicon = false;
        this.call.mute();
    }

    onUnMute() {
        this.isMicof = false;
        this.isMicon = true;
        this.call.unmute();
    }

    // hangup the call
    callhangup() {
        this.iscallinput = false;
        this.call & this.call.hangup();

    }

    callAnswer() {
        this.call.answer()
    }

0 个答案:

没有答案