DEV Community

Ionic video call by peerjs

timsar2 on February 11, 2020

Hello, Before starting, this is ionic 5 angular 9 simple example of video call. At the end you can connect two device in same network if the app is...
Collapse
 
eestebanjjosue profile image
eestebanjjosue • Edited

Hi, thanks for this awesome tutorial, I could make a basic videocall app, but I am facing a problem, in my phone when I make it an app the camera does not work, I can see the camera and audio in the other device(my pc). Sometimes I get an error "getUserMedia error: NotReadableError". Ant idea what could be wrong? If I use my android device as a second device and I connect to the app throug LAN it works.
P.D. The sound gets returned from the speakers of the pc so it makes that awful sound if I am not wearing headphones. Is there a way to fix this too?

Collapse
 
timsar2 profile image
timsar2

If you have two htmlElemeny, one for your camera and another for your partner, you can disable input audio from partner element.
stackoverflow.com/questions/184061...

Collapse
 
timsar2 profile image
timsar2

Thank you, You can mute your video media output.

Collapse
 
naonvl profile image
naonvl • Edited

Hi this is awesome, i'm building an app based on your tutorial. i currently want to add some functionality like waiting for an answer, and also automatic destroy both user.

i also posting on stackoverflow stackoverflow.com/questions/672497..., if you got time pls help me there. thanks

Collapse
 
timsar2 profile image
timsar2 • Edited

I'm glad to hear that, I implemented video call in a real app and for that, I used simple-peer instead of peerJs.
I had no time to write about my new experience, also in the real app I found we will need a turn server to work when clients are not in the same network.
For turn server i used this repository:
github.com/coturn/coturn
run it in Linux. (for windows os use WSL)

Collapse
 
naonvl profile image
naonvl

wow thats great, so do you prefer simple peer instead of peerjs? cause i got problems with listening an event if someone on the other side click a button or something. they said to use socket.io, but i dontwanna use that

Thread Thread
 
timsar2 profile image
timsar2

Yes simplepeer was better for me,
for socket i used signalr in dot net core.
using hubconnection
you can use any other language as your signaling server line nodjs, java, python etc...

Thread Thread
 
naonvl profile image
naonvl • Edited

great!! but do you have any suggestion on listening to an event that someone on the other side fire an event? like closing or destroying the connection? i can show you my code if you could help me out

Thread Thread
 
timsar2 profile image
timsar2

Calling peer close() function in frontend side must work and As I said, From backend you can call hubconnection methods in signalr dotnet core
for other language i dont know

Thread Thread
 
naonvl profile image
naonvl • Edited

actually i use peerjs cloud server, so i only working on front end. Is using my own peerjs server a must?

Thread Thread
 
timsar2 profile image
timsar2

peerjs server is just for signaling, (both clients will create some signale and send them to each other with server)
you can implement signaling server in any language.
but for your priblem to alter other client to close the connection it must work. I don't know why close() function not triggered.
maybe you have to look at peerjs document.

Thread Thread
 
naonvl profile image
naonvl

yeah what i wrote was following the peerjs docs, i post an issue on their repo. Thanks for your help, hope you'll share more knowledge

Collapse
 
iometrine profile image
iometrine

Hello,

Thank you for your post.
I try this on my ionic capacitor project all works good (web and android) but ios.
On IOS, getUserMerdia throw an exception notallowederror. it doesn't work on ios 14.4
Did you try on ios ? If yes how did you get the stream ?
Do i need to use a plugin such as iosrtc?
Thank you for your answer

Collapse
 
timsar2 profile image
timsar2 • Edited

It's good sound if it is helpful.
Sry I didn't try on ios.
If you are going to use it on mobile network you need turn server. I hope i have free time to write about how to make real video chat

Collapse
 
gemdajs profile image
Nasirudeen Olawale

It will be helpful if you can share directives on how to make the app serve with ssl on (android) devices.

Collapse
 
timsar2 profile image
timsar2 • Edited

I used same address then running android + Conveyore (an extension) for visual studio
to solve cors issue on local host
try something like this: ionic cordova run android --address 192.168.43.105 --ssl

Collapse
 
lautalopez profile image
lautalopez

how can i implement a webrtc backend server?

Collapse
 
timsar2 profile image
timsar2 • Edited

Look at this repository
github.com/Shhzdmrz/SignalRCoreWebRTC
Good backend with signalr
And this:
dev.to/sebalr/video-call-with-webr...

You just need a signaling server
Each client should send his signal to other client
For doing this you need a server to swap client 's signal.
So used webrtc to create signal in both client and swap them with backend.
I used signalr and websocket
You can use any language and technic to swap signal between clients.

Collapse
 
innovativethinkingptyltd profile image
Innovative Thinking

Are you available to provide a paid integration?

Thread Thread
 
timsar2 profile image
timsar2 • Edited

Send me some detail please:
info.golab@gmail.com

Collapse
 
travbradfield profile image
TravBradfield

How do I end the call and close the video?

Collapse
 
timsar2 profile image
timsar2

this.peer.close()

Collapse
 
prosenjitbarui9 profile image
Prosenjit Barui

How to create room with peerjs so multi user can join that room

Collapse
 
cacardinal profile image
Chris

Would this work with a Firebase WebRTC or does it require a Peerjs server?

webrtc.org/getting-started/firebas...

Collapse
 
timsar2 profile image
timsar2 • Edited

i didn't touch firebase webrtc, but webrtc client's just need a signaling server to swap their signale(created in client side).
you can also use simple peer and a signaling server github.com/feross/simple-peer

Collapse
 
gafeell profile image
Muhammad Bilal

Hi, Can you please guide me how do i connect video call from two different network. Your code only work if app is connected to same network.

Collapse
 
timsar2 profile image
timsar2 • Edited

Ofc, As i said you need turn server to establish a connection.
Look at coturn project on github.
run it on linux or first instal wsl in windwos and run it from wsl.

Collapse
 
gafeell profile image
Muhammad Bilal

Do you have any server which i can use in my code?

Thread Thread
 
timsar2 profile image
timsar2

No mate, i dont have free public turn server.
It's just for client.
But why u not try to run it.
Just follow coturn repository from github, Run it from linux or as i said just install wsl on windows and then you can run linux from shell

Collapse
 
iometrine profile image
iometrine

If that can help someone, i created a proof of concept using peersjs with ionic capacitor thanks to the work of @timsar2 .
github.com/iometrine/ionic-iosrtc-....
Enjoy

Collapse
 
neroshanbme36 profile image
neroshanbme36

Awesome Bro.
How can I disconnect the camera and signaling server connections?. I tried this.peer.close() but it's not working. Can you please help me to sort out this.

Collapse
 
timsar2 profile image
timsar2 • Edited

I don't remember, but you can stop video stream. play() stop()
also hide the video element

Collapse
 
demirkolerme profile image
emre demirkol

Hello, Can you help me?

Can I make this project workable with firebase?

Collapse
 
timsar2 profile image
timsar2

Yes it is posible, You just need a signaling server and maybe turn server. There is an opensource turn server called coturn

Collapse
 
itsranjeet profile image
its_ranjeet

if possible please let me show how it actually works in ionic 5 app

Collapse
 
timsar2 profile image
timsar2

Ofcorse mate

Collapse
 
itsranjeet profile image
its_ranjeet

sir i am trying it in my new ionic 5 application but can not create any type of connection please help me to short out the problem if possible

Collapse
 
timsar2 profile image
timsar2

Need to look at your code or at least tell me what you are trying to do.

Collapse
 
neroshanbme36 profile image
neroshanbme36

Is it possible to record the video call?

Collapse
 
neroshanbme36 profile image
neroshanbme36

Hello,
Is it possible to record the video call?

Thanks

Collapse
 
timsar2 profile image
timsar2

I didn't try it but it can be posible

Collapse
 
g_arikado profile image
Carlos Cortina

Those who want to eliminate the echo in the video call add to the ngOnInit:

const audioPlayer = document.getElementById('my-video');
audioPlayer.volume = 0;

Collapse
 
rvasquezz profile image
RAY VASQUEZ

you are not using the default speaker! Can you change the default speaker and camera?