flutter-webrtc / dart-sip-ua

A dart-lang version of the SIP UA stack.
MIT License
328 stars 255 forks source link

SIP connection alive in the background or terminated situation #371

Open AungKOO opened 1 year ago

AungKOO commented 1 year ago

For my project, I used Flutter webRTC, sip, flutter incoming call kit, and FCM for incoming calls. But whenever the user exits the app with the back button, the SIP connection is terminated and my backend server can't know it is still alive. Whenever incoming calls are there, Although FCM and Flutter incoming call kit can wake my app and open the app with sip registration at initialization, I cannot know the current SIP state of incoming calls. So, it makes the app open but nothing. Are there any possible ways to keep SIP connection alive in background or terminated situation? I know there may be drawbacks such as devices battery draining or security issues. But it is okay for me if I can keep SIP state connection alive.

pogenz45 commented 1 year ago

I've tried staying connected SIP when the app is terminate in iOS using silent push notification (push notifications/VoIP push), but it doesn't work. Because, when the user terminates the application, iOS will not prioritize your background task. When you use silent notification to run background task, the iOS operating system will depend on the battery, resources, ... to decide which task to prioritize. So silent push notification is not stable (when app in terminate, in first push notification, it not working. I must push 2,3 times to run my background task).

So, here my solution: In the Event.actionCallAccept (note Event.actionCallIncoming not working when app terminate) of the flutter_incoming_callkit library, I will call the registration SIP function when user press button accept (in callkit).

Sound a great solution. Do you try it? Does it work?

pogenz45 commented 1 year ago

but in this situation, when i open app, app does not navigate to callScreen(Screen has 2 button accept and reject call). it mean when click accept from callkit to wake app, app running but not receive event call coming.How can you handle this?

anhquangtech commented 1 year ago

If transaction state is accepted -> navigate to call screen.

pogenz45 commented 1 year ago

but in this situation, when i open app, app does not navigate to callScreen(Screen has 2 button accept and reject call). it mean when click accept from callkit to wake app, app running but not receive event call coming.How can you handle this?

You can check SIP state after re-register success. If transaction state is STREAM, you need accept VoIP call to change transaction state is ACCEPTED. If transaction state is ACCEPTED -> navigate to call screen.

i'll try, thank you very much. Are you vietnamese?

anhquangtech commented 1 year ago

i'll try, thank you very much. Are you vietnamese?

Yes, I am 🤩

pogenz45 commented 1 year ago

but in this situation, when i open app, app does not navigate to callScreen(Screen has 2 button accept and reject call). it mean when click accept from callkit to wake app, app running but not receive event call coming.How can you handle this?

You can check SIP state after re-register success. If transaction state is STREAM, you need accept VoIP call to change transaction state is ACCEPTED. If transaction state is ACCEPTED -> navigate to call screen.

i'll try, thank you very much. Are you vietnamese?

Yes, I am 🤩

Ok anh, em sẽ thử theo cách của anh. Có khó khăn j mong anh giúp đỡ em với nhé.

pogenz45 commented 7 months ago

i'll try, thank you very much. Are you vietnamese?

Yes, I am 🤩

anh ơi cho em hỏi khi có 1 cuộc gọi đến (Em dùng call_kit_comming) để wake app lên. Nhưng khi ấn vào accept cuộc gọi thì vào app -> reconnect socket nhưng ko bắt lại được cuộc gọi đến. Cái này xử lý kiểu gì nhỉ anh. Anh làm rồi cho em tham khảo ý kiến với

hieujames commented 6 months ago

i'll try, thank you very much. Are you vietnamese?

Yes, I am 🤩

anh ơi cho em hỏi khi có 1 cuộc gọi đến (Em dùng call_kit_comming) để wake app lên. Nhưng khi ấn vào accept cuộc gọi thì vào app -> reconnect socket nhưng ko bắt lại được cuộc gọi đến. Cái này xử lý kiểu gì nhỉ anh. Anh làm rồi cho em tham khảo ý kiến với

Khi nhấn accept, bạn có thể kiểm tra kết nối và kiểm tra tín hiệu cuộc gọi đến. Cuộc gọi đến đôi khi chưa được xác thực, vì thế bạn kiểm tra xem thử Call-Id có tồn tại tự UA ko, nếu có bạn thể chuyển hướng đến mà hình nói chuyện và thời gian đợi để tín hiệu cuộc gọi hoàn toàn được accept và cập nhật trạng thái CONNECT từ UA

pogenz45 commented 6 months ago

i'll try, thank you very much. Are you vietnamese?

Yes, I am 🤩

anh ơi cho em hỏi khi có 1 cuộc gọi đến (Em dùng call_kit_comming) để wake app lên. Nhưng khi ấn vào accept cuộc gọi thì vào app -> reconnect socket nhưng ko bắt lại được cuộc gọi đến. Cái này xử lý kiểu gì nhỉ anh. Anh làm rồi cho em tham khảo ý kiến với

Khi nhấn accept, bạn có thể kiểm tra kết nối và kiểm tra tín hiệu cuộc gọi đến. Cuộc gọi đến đôi khi chưa được xác thực, vì thế bạn kiểm tra xem thử Call-Id có tồn tại tự UA ko, nếu có bạn thể chuyển hướng đến mà hình nói chuyện và thời gian đợi để tín hiệu cuộc gọi hoàn toàn được accept và cập nhật trạng thái CONNECT từ UA

Cơ mà vấn đề là ở trên tổng đài webrtc setting là chỉ bắn vào những device online. Mà khi từ background awake app lại thì device reconnect lại thì tổng đài không bắn được call in đến mà anh (Cái này có phải 1 phần do bên backend nữa đúng ko ạ). Tại em test gọi 1 cuộc trước khi vào app và vào lại app thì không bắt được sự kiện đó

hieujames commented 6 months ago

Bạn có thể làm như sau, bạn kiểm tra ở Native IOS từ pushkit xem đổ vào như thế nào, đặt một cờ và dùng invorkMethod để xử lí đến flutter sao cho reconnect trước, đài sẽ nhận tín hiệu register trước và sau đó bắn invite đến app. Lúc này ứng dụng Flutter đã được sống lại và việc còn lại bạn hãy kiểm tra ở Flutter sao cho xác minh cuộc gọi đó. Có thể sẽ ảnh hưởng mất vài giây nha, vì khi accept đợi bắt tín hiệu trả lời như thế nào nữa mới nghe có voice, chứ không thì cuộc gọi sẽ bị cancel hoặc busy,...

hieujames commented 6 months ago

Bạn có thể dùng qua Flutter_Callkeep, một libs hỗ trợ rất tốt.

pogenz45 commented 6 months ago

anh cho em thông tin liên hệ để em hỏi thêm được ko ạ

Bạn có thể dùng qua Flutter_Callkeep, một libs hỗ trợ rất tốt.

hieujames commented 6 months ago

@.*** contact for me =)))

Vào Th 3, 20 thg 2, 2024 vào lúc 23:12 pogenz @.***> đã viết:

anh cho em thông tin liên hệ để em hỏi thêm được ko ạ

Bạn có thể dùng qua Flutter_Callkeep, một libs hỗ trợ rất tốt.

— Reply to this email directly, view it on GitHub https://github.com/flutter-webrtc/dart-sip-ua/issues/371#issuecomment-1954555905, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI5X2K4RN4UKL53PFP5UVADYUTDPBAVCNFSM6AAAAAAYTPFMA2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJUGU2TKOJQGU . You are receiving this because you commented.Message ID: @.***>

hieujames commented 6 months ago

hieujames741@gmail.com contact for me =)))

abdullahriaz95 commented 3 months ago

Hey @pogenz45 Were you able to solve the issue? I am having the exact problem.

eduardothiesen commented 2 weeks ago

@hieujames @pogenz45 do you guys have a example on working from terminated (killed) state?

hieujames commented 2 weeks ago

Yes, please contact for me =))))

Vào Th 4, 7 thg 8, 2024 vào lúc 02:49 Cadu Thiesen < @.***> đã viết:

@hieujames https://github.com/hieujames @pogenz45 https://github.com/pogenz45 do you guys have a example on working from terminated (killed) state?

— Reply to this email directly, view it on GitHub https://github.com/flutter-webrtc/dart-sip-ua/issues/371#issuecomment-2272028327, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI5X2K3UB6ZJTML2LR2OAOLZQESEFAVCNFSM6AAAAAAYTPFMA2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZSGAZDQMZSG4 . You are receiving this because you were mentioned.Message ID: @.***>

Vinayak0-0 commented 1 week ago

Has anyone got a working example? I tried the background service, but got stuck with Video Calling where I couldn't find a way to send MediaStream between isolates.

abdullahriaz95 commented 1 week ago

Could you please share the working example of SIPUA in Flutter from terminated state? Especially video calling in terminated state.

On Wed, Aug 7, 2024 at 6:53 AM hieujames @.***> wrote:

Yes, please contact for me =))))

Vào Th 4, 7 thg 8, 2024 vào lúc 02:49 Cadu Thiesen < @.***> đã viết:

@hieujames https://github.com/hieujames @pogenz45 https://github.com/pogenz45 do you guys have a example on working from terminated (killed) state?

— Reply to this email directly, view it on GitHub < https://github.com/flutter-webrtc/dart-sip-ua/issues/371#issuecomment-2272028327>,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/AI5X2K3UB6ZJTML2LR2OAOLZQESEFAVCNFSM6AAAAAAYTPFMA2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZSGAZDQMZSG4>

. You are receiving this because you were mentioned.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/flutter-webrtc/dart-sip-ua/issues/371#issuecomment-2272469056, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALDFFKN7K5EUMAKTIUXQUODZQF42VAVCNFSM6AAAAAAYTPFMA2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZSGQ3DSMBVGY . You are receiving this because you commented.Message ID: @.***>