Usage
The plugin is implemented as static methods that can be called from Unity.
Initialization
Initialize Plugin
void Phenix.Init(ChannelExpressOptions options)
Initialize the plugin and create the ChannelExpress.
options
parameter of typeChannelExpressOptions
(required)
The plugin is initialized with ChannelExpressOptions wich can be created with a builder as shown in the following code snippet:
1ChannelExpressOptions channelExpressOptions = new ChannelExpressOptions.ChannelExpressOptionsBuilder()2 .WithBackendUri("https://example.yourdomain.com/phenix/")3 .Build();4Phenix.Init(channelExpressOptions);
Check if Already Intialized
bool Phenix.IsInitialized()
Check if the plugin has been intialized.
Channel Express APIs
Channel Express Options Builder
ChannelExpressOptions.ChannelExpressOptionsBuilder
WithBackendUri(string backendUri)
(required) - URL to your backend. We send requests here to authenticate and get streaming tokens.WithPCastUri(string pCastUri)
(optional) - Allows overriding default PCast™ URI.WithAuthenticationToken(string authenticationToken)
(optional) - The authentication token generated using the Phenix EdgeAuth library.
Channel APIs
Join a Channel
string JoinChannel(JoinChannelOptions options)
Join a channel and automatically view the most recent content published to that channel.
options
parameter of typeJoinChannelOptions
(required)- return the channel unique identifier
1JoinChannelOptions joinChannelOptions = new JoinChannelOptions.JoinChannelOptionsBuilder()2 .WithRoomAlias("MyAwesomeChannel")3 .Build();4string channelUuid = Phenix.JoinChannel(joinChannelOptions1);
Join Channel Options Builder
JoinChannelOptions.JoinChannelOptionsBuilder
WithRoomAlias(string roomAlias)
(required)WithCapabilities(string[] capabilities)
(optional) - The list of all capabilities to subscribe with.WithStreamToken(string streamToken)
(optional) - alternative to room aliasWithStreamSelectionStrategy(StreamSelectionStrategy streamSelectionStrategy)
(optional) - choose the stream selection strategy. Possible values areStreamSelectionStrategy.HIGH_AVAILABILITY
orStreamSelectionStrategy.MOST_RECENT
Leave a Channel
void LeaveChannel(string uuid)
Leave a Channel and stop viewing of its published content.
uuid
parameter of typestring
(required) - The channel unique identifier that the user wants to leave
1string channelUuid = ... //obtained when joining a channel2Phenix.LeaveChannel(channelUuid);
Check if a Specific Channel is Joined
bool IsChannelJoined(string uuid)
Check if the channel is joined.
uuid
parameter of typestring
(required) - The channel unique identifier
1string channelUuid = ... //obtained when joining a channel2Phenix.IsChannelJoined(channelUuid)
Check if any Channel is Joined
bool IsJoined()
Check if any channel is joined.
1Phenix.IsJoined()
Check if a Channel Exists
bool ChannelExists(string uuid)
Check if the channel exists.
uuid
parameter of typestring
(required) - The channel unique identifier
1string channelUuid = ... //obtained when joining a channel2Phenix.ChannelExists(channelUuid)
Check Which Channels are Joined
string[] GetChannels()
Check which channels are currently joined.
- return a list containing the channel unique identifiers for all the channels that are joined
1string[] channels = Phenix.GetChannels();
Get the Published Content
Texture2D GetTexture(string uuid)
Get the texture that holds the published content.
uuid
parameter of typestring
(required) - The channel unique identifier- return a texture of type
Texture2D
1// Script that is attached to a GameObject2private void Awake ()3{4 string channelUuid = ... //obtained when joining a channel5 rend = GetComponent<Renderer>();6 rend.material.mainTexture = Phenix.GetTexture(uuid);7}
Rejoin the Channel
void RejoinChannel(string uuid)
Rejoin the channel.
uuid
parameter of typestring
(required) - The channel unique identifier
1// Script that is attached to a GameObject2private void Awake ()3{4 string channelUuid = ... //obtained when joining a channel5 Phenix.RejoinChannel(channelUuid);6}
Limit Channel Bandwidth
void SetBandwidthLimit(string uuid, PhenixDefinitionBandwidths bandwidth)
Limit the bandwidth of a channel.
uuid
parameter of typestring
(required) - The channel unique identifierbandwidth
parameter of typePhenixDefinitionBandwidths
(required) - The value to wich we want to limit the bandwidth
1// Script that is attached to a GameObject2private void Awake ()3{4 string channelUuid = ... //obtained when joining a channel5 Phenix.SetBandwidthLimit(channelUuid, PhenixDefinitionBandwidths.PhenixStandardDefinitionBandwidth);6}
Get the Channel Bandwidth Limit
PhenixDefinitionBandwidths GetBandwidthLimit(string uuid)
Get the channel bandwidth limit.
uuid
parameter of typestring
(required) - The channel unique identifier
1// Script that is attached to a GameObject2private void Awake ()3{4 string channelUuid = ... //obtained when joining a channel5 Phenix.GetBandwidthLimit(channelUuid);6}
Flip the Channel Video Around its Axis
void SetTextureFlip(string uuid, PhenixTextureFlipAxis axisFlip)
Flip the video around its axis.
uuid
parameter of typestring
(required) - The channel unique identifieraxisFlip
parameter of typePhenixTextureFlipAxis
(required) - The value that defines around which axis to flip the video.
1// Script that is attached to a GameObject2private void Awake ()3{4 string channelUuid = ... //obtained when joining a channel5 SetTextureFlip(channelUuid, PhenixTextureFlipAxis.FlipUAxis);6}
Get the Channel Flipped Axis
PhenixTextureFlipAxis GetTextureFlip(string uuid)
Get the axis around which the video is flipped.
uuid
parameter of typestring
(required) - The channel unique identifier
1// Script that is attached to a GameObject2private void Awake ()3{4 string channelUuid = ... //obtained when joining a channel5 Phenix.GetTextureFlip(channelUuid);6}
Channel Callbacks
Channel Subscribe Events
OnSubscribeEvent(string uuid, PhenixRequestStatus requestStatus)
Triggered when a channel is joined or left.
1Phenix.OnSubscribeEvent callback;23private void Awake()4{5 callback = new Phenix.OnSubscribeEvent((uuid, status) =>6 {7 print("uuid:" + uuid);8 print("status:" + status);9 }10 );11 Phenix.OnSubscribeEvent += callback;12}1314private void OnDestroy()15{16 // Cleanup callback to avoid leaks17 Phenix.OnSubscribeEvent -= callback;18}
Channel Join or Leave Detailed Event
OnJoinChannelEvent(string uuid, PhenixRequestStatus requestStatus)
Triggered when a channel is joined or left.
1Phenix.OnJoinChannelEvent callback;23private void Awake()4{5 callback = new Phenix.OnJoinChannelEvent((uuid, status) =>6 {7 print("uuid:" + uuid);8 print("status:" + status);9 }10 );11 Phenix.OnJoinChannelEvent += callback;12}1314private void OnDestroy()15{16 // Cleanup callback to avoid leaks17 Phenix.OnJoinChannelEvent -= callback;18}
Unrecoverable Error Event
OnUnrecoverableErrorEvent(PhenixRequestStatus status, string description)
Triggered when an error occurs that the plugin can't recover from.
1Phenix.OnUnrecoverableErrorEvent callback;23private void Awake()4{5 callback = new Phenix.OnUnrecoverableErrorEvent(status =>6 {7 print("status:" + status);8 }9 );10 Phenix.OnUnrecoverableErrorEvent += callback;11}1213private void OnDestroy()14{15 // Cleanup callback to avoid leaks16 Phenix.OnUnrecoverableErrorEvent -= callback;17}
Channel Join or Leave Events
JoinEvent(bool joined)
Triggered when at least one channel is joined or the user leaves all the channels.
1Phenix.JoinEvent callback;23private void Awake()4{5 callback = new Phenix.JoinEvent(joined =>6 {7 print("At least one channel is joined:" + joined);8 }9 );10 Phenix.OnJoinEvent += callback;11}1213private void OnDestroy()14{15 // Cleanup callback to avoid leaks16 Phenix.OnJoinEvent -= callback;17}