DEV Community

Cover image for How to Embed Video Chat in your Unity Games

How to Embed Video Chat in your Unity Games

Joel on May 05, 2020

When you're making a video game, you want to squeeze every last drop out of performance out of your graphics, code, and any plugins you may use. Ag...
Collapse
 
zegladscientist profile image
Sabio (The Glad Scientist) ๐Ÿ™ƒ

Hey Joel! This looks great and like it's easy to implement with PUN projects. Quick question...is the videochat compatible with WebGL builds? I am trying to run it in browser and getting an error about emscripten linking, didn't know if it was simply incompatible or if I should follow the thread. :)

Collapse
 
joelthomas362 profile image
Joel

Hey Sabio,

Thanks for reaching out!
Currently our video SDK does not support WebGL - however we are working on it, and it should be out later this year!

Cheers!

Collapse
 
zegladscientist profile image
Sabio (The Glad Scientist) ๐Ÿ™ƒ

Gotcha, thanks for the response. Please update here when it's ready, I am eager to try it out! :)

Collapse
 
robenscholten profile image
RobenScholten

Did you figure out what the answer to this was? I'm curious about it as well!

Collapse
 
joelthomas362 profile image
Joel

Hey Roben,

We are planning on releasing WebGL support for Unity later this year. Progress is underway and going well!

Cheers,
Joel

Thread Thread
 
joachim_hedenius profile image
Joachim Hedenius

Hi Joel,

Do you have an update on WebGL support for Unity?

Thanks so much in advance!

Cheers,
Joachim

Collapse
 
daveaccenture profile image
DaveAccenture

Hi Joel,
in JoinRemoteChannel, do we always want to LeaveChannel? What if we happen to get the same channel name again, should we skip leaving it? Or does Agora kinda require you leave and rejoin?

Collapse
 
joelthomas362 profile image
Joel

Hey Dave,
If you happen to get the same channel name again, I would skip leaving it, your suggestion is a cleaner implementation =]
Agora does not specifically require any kind of leaving and rejoining.
Cheers!

Collapse
 
daveaccenture profile image
DaveAccenture

In so doing, I do not get another 'user joined' when someone starts broadcasting. The person becoming the broadcaster gets a 'role changed' callback, but I don't see anything else happening to indicate to anyone else that a role changed or someone has started broadcasting.

Thread Thread
 
daveaccenture profile image
DaveAccenture

Some progress. If I use 'MuteVideo' (something like that) setting 'false' in the OnRoleChanged (to Broadcast) callback worked to send the video. I really wish they had a real Unit Broadcast-profile example.

Thread Thread
 
joelthomas362 profile image
Joel

Hey Dave,
I understood the question in the context of my tutorial, however these questions seem like they're related to a project you're working on. If you provide me more information I'll help out the best I can. Cheers!

Thread Thread
 
daveaccenture profile image
DaveAccenture

Yes thanks. I'm working on a VR app wherein we want one person at a time to present their webcam video to other players. So anyone can 'become broadcaster' and that locks everyone else to Audience until that person stops broacasting. Your tutorial was the best thing I could find that came close to what I need. I thought I could just change a few little things around, like set the profile, and change Role, etc. For the most part this was true. But I ran into issues. For one thing, we want to be able to have the video broadcaster to start with 'local camera on' so they can preview themselves before broadcasting, then hit a 'broadcast' button to send the video to other players. And, a 'stop broadcast' to go back to preview. There seem to be a handful of API's related to this. I finally got it (almost) working by turning on the local video, and using 'MuteVideo' to turn broadcasting on/off. In my case, each player's avatar would have the video (when being broadcast) above their head. So I need to associate a Photon player ID with an Agora user id when they join the channel, and display the correct broadcaster's video above the correct avatar.

Thread Thread
 
joelthomas362 profile image
Joel

Ok I'm glad you're making progress!
You might have already seen/know this, but when a player joins a channel, you can assign your own UID to them, instead of allowing Agora to create a random UID during channel join. So it may be possible to pass in the Photon ID into the UID parameter for consistency.

Thread Thread
 
daveaccenture profile image
DaveAccenture

I did not know that, great idea, thank you!

Collapse
 
daveaccenture profile image
DaveAccenture

Hi, thanks for this, very helpful.
I'm trying to add a 'Broadcast' feature, which is somewhat different, and a bit new to both Photon and Agora.
In this, I want one person to 'own' the one video feed, and disable anyone else's webcams/streams. When that person is done (or leaves) then everyone has a chance to become the broadcaster.
After some futzing, I thought I had it, but when I try multiplayer, my Start routine (on 'late joiners' exists because photonView.IsMine is not mine. So the engine never starts.
Would it make more sense to not check IsMine in Start in this case? Any tips appreciated.

Collapse
 
joelthomas362 profile image
Joel

Well in my example, we start in the Photon lobby, and only enter the game after we've connected to Photon and are in "multiplayer" mode.

If you are deviating from that, I'd recommend checking for "IsMine" after you manually connect to the Photon network, and receive a successful callback from Photon. I hope this helps!

Collapse
 
daveaccenture profile image
DaveAccenture

If I am also using Photon Voice (for non-video calls), do I disable Photon Voice while in a video call? Or can I make a video-only call with Agora (and let Photon do the audio)?

Collapse
 
joelthomas362 profile image
Joel

Hey Dave,
As far as I know, Agora has modules for "Video Call (including audio)" and "Audio Call".
The video module can be disabled, leaving only the audio module.

However if you have the video module enabled, you can only mute/unmute the audio, instead of fully restricting audio, access to microphone, etc.

I'm curious about your implementation, what are you aiming to make?

Also, our service is built upon our own custom-built network that's optimized for voice/video interaction. At a base level Agora provides superior quality of voice/video all over the world - with an added bonus of custom controls at your disposal to optimize the audio/video data for your specific use-case.

I hope this helps, Dave, cheers!

Collapse
 
daveaccenture profile image
DaveAccenture

Thanks for the reply. We are building a VR collaboration app (like VRChat, for example) and want to include webcam video. But (for now) we only want one person's webcam active and broadcasting. We're using Photon for everything else, including voice. I have to assume that voice will be better synced if I mute PhotonVoice and use Agora's instead.

Thread Thread
 
joelthomas362 profile image
Joel

Very cool!
Yeah i'd say that's a safe assumption!

Collapse
 
rubenvdb12 profile image
rubenvdb12 • Edited

Hey Joel, I'm using the agora blueprints implementation in Unreal 4.26. On windows it works great but when I try to load the same project on mac with the ios plugin, the plugin compiles and the blueprint nodes show up in the project but unreal crashes immediately after agora initializes, both in unreal editor as well as packaged.
Any ideas why this would happen?

Collapse
 
juanmacc20 profile image
Juan Manuel Lรณpez Guerrero

Hi Joe, thanks for everything!

I have a question: My JoinChannelByKey is returned me -7, I don't have any video on my project. Reading the agora documentation, found a reference to -7: ERR_NOT_INITIALIZED(-7), it's not related to JoinChannelByKey, but is a clue, it looks like a standard error id for all Agora . I followed all the steps, this return happens even the demo app.

I hope you can help me.
Thank you so much