How do I get the address to transfer a call on Linphone?

56 Views Asked by At

I am trying to initiate a call transfer using linphone.

This is the button to press to initiate the call transfer. When this button is pressed It should transfer the call. Also I want to see the full address printed to my terminal, print("REMOTE: \(remoteAddress)") but I get REMOTE: linphonesw.Address printed.

ThemeButton(text: "Transfer a Call") {
                    if let selectedIndex = transferCalls.transferNumbers.firstIndex(where: { $0.selected ?? false }) {
                        let selectedTransferNumber = transferCalls.transferNumbers[selectedIndex]

                        // Create SIP address using the UserLine information
                        if let line = selectedTransferNumber.line {
                            let sipAddressString = "\(line.username ?? "")@\(line.domain ?? "")"
                            do {
                                let remoteAddress = try Factory.Instance.createAddress(addr: "sip:" + sipAddressString)
                                
                                print("REMOTE: \(remoteAddress)")
                                
                                // Perform the call transfer using the created SIP address
                                phoneManager.transferCall(targetHandle: sipAddressString)
                            } catch {
                                print("Error creating SIP address: \(error)")
                            }
                        } else {
                            print("Selected transfer number does not have a valid UserLine.")
                        }
                    }
                }

This is the function responsible for creating the address.

func transferCall(targetHandle: String) {
        do {
            guard let currentCall = (mCore.currentCall != nil) ? mCore.currentCall : mCore.calls.first else {
                // Handle the case when there is no active call
                print("No active call to transfer.")
                return
            }

            print("Transfer ::: Domain: \(domain)")
            print("Transfer ::: Target Handle: \(targetHandle)")

            let remoteAddress = try Factory.Instance.createAddress(addr: "sip:" + targetHandle + "@" + domain)
            print("REMOTE: ———> \(remoteAddress)")

            try currentCall.transferTo(referTo: remoteAddress)
        } catch {
            print("Transfer Call Error: \(error)")
        }
    }

How do I solve this?

I have tried following the documentation. but there aren't many working solutions as this is my first time working with this.

1

There are 1 best solutions below

0
Viish On

Use remoteAddress.asString() (or asStringUriOnly) to convert an Address to a printable string value.