Video

EnableVideo(bool enable, PeerMetadata metadata)

For enabling video, first you need to get initialize Texture Id. Consider initializing it in Awake or Start. Call JSNative.NewTexture() to initialize.

.csharp
public class VideoSection: MonoBehaviour
{
    private int m_TextureId =1;
 
    private void Start()
    {
        GetNewTextureId();
    }
 
    public void GetNewTextureId()
    {
        m_TextureId = JSNative.NewTexture();
    }
}

Once you setup the texture id, you can call JSNative.AttachVideo(peerId, m_TextureId) to ,map peer id with externally created unity Texture; Use Texture2D.CreateExternalTexture (opens in a new tab) to get external.

Check the below script to get the texture which can be attached toi any raw image or material.

.csharp
public class VideoSection: MonoBehaviour
{
    private HuddleUserInfo _userInfo;
 
    private int m_TextureId =1;
 
    public Texture2D Texture { get; private set; }
    public bool isVideoPlaying=false;
 
    [SerializeField]
    private RawImage _videoTexture;
 
		private void Start()
    {
        GetNewTextureId();
    }
 
    public void Setup(HuddleUserInfo userInfo)
    {
        _userInfo = userInfo;
    }
 
    private void Update()
    {
        if (isVideoPlaying)
        {
            SetupTexture();
        }
    }
 
    public void GetNewTextureId()
    {
        m_TextureId = JSNative.NewTexture();
    }
 
    public void AttachVideo()
    {
        JSNative.AttachVideo(_userInfo.PeerId, m_TextureId);
    }
 
    public void SetupTexture()
    {
        if (Texture != null)
            Object.Destroy(Texture);
        Texture = Texture2D.CreateExternalTexture(1280, 720, TextureFormat.RGBA32, false, true, (IntPtr)m_TextureId);
        _videoTexture.texture = Texture;
    }
}

once above setup is done, you can simply call Huddle01Core.Instance.EnableVideo to enable and disable local peer video. Same process can be use to get the remote peer video, all you need to do is to subscribe OnStopPeerVideo and OnResumePeerVideo events from Huddle01Core class.

Parameters

ParamsTypeDescription
enableVideoboolsetting video status of peer
metadataPeerMetadataPeer metadata class object
.csharp
public void EnableVideoStreaming(bool enableVideo)
{
    Huddle01Core.Instance.EnableVideo(enableVideo, userSectionRef.UserInfo.Metadata);
 
}

Huddle01Core.OnResumePeerVideo(string peerId)

This event gets invoked when any peer(including local peer) enable their video. Subcribe to this event to receive notification.

Parameters

ParamsTypeDescription
peerIdstringpeer id, can be both local and remote
.csharp
 
private void OnEnable()
{
    Huddle01Core.OnResumePeerVideo += OnPeerVideoResume;
}    
 
private void OnDisable()
{
    Huddle01Core.OnResumePeerVideo -= OnPeerVideoResume;
}
 
private void OnPeerVideoResume(string peerId)
{
    Debug.Log($"Enable video of peer : {peerId}");
}
 

Huddle01Core.OnStopPeerVideo(string peerId)

This event gets invoked when any peer(including local peer) disable their video. Subcribe to this event to receive notification.

Parameters

ParamsTypeDescription
peerIdstringpeer id, can be both local and remote
.csharp
 
private void OnEnable()
{
    Huddle01Core.OnStopPeerVideo += OnPeerVideoStop;
}    
 
private void OnDisable()
{
    Huddle01Core.OnStopPeerVideo -= OnPeerVideoStop;
}
 
private void OnPeerVideoStop(string peerId)
{
    Debug.Log($"Enable video of peer : {peerId}");
}
Audio/Video Infrastructure designed for developers to empower them to ship simple yet powerful Audio/Video Apps.
support
company
Copyright © 2024 Graphene 01, Inc. All Rights Reserved.