void IChatApiListener.ChatInitializationCallback(ErrorCode result) { if (Error.Succeeded(result)) { Api.SetMessageFlushInterval(this.MessageFlushInterval); Api.SetUserChangeEventInterval(this.UserChangeEventInterval); m_ChatController.DownloadEmoticonData(); m_ChatController.SetChatState(ChatState.Initialized); } else { m_ChatController.SetChatState(ChatState.Uninitialized); } try { if (m_ChatController.InitializationComplete != null) { m_ChatController.InitializationComplete(result); } } catch (Exception x) { m_ChatController.ReportError(x.ToString()); } }
void IChatApiListener.ChatEmoticonDataDownloadCallback(ErrorCode error) { if (Error.Succeeded(error)) { m_ChatController.SetupEmoticonData(); } }
void IChatApiListener.ChatShutdownCallback(ErrorCode result) { if (Error.Succeeded(result)) { ErrorCode ret = m_ChatController.m_CoreApi.Shutdown(); if (Error.Failed(ret)) { string err = Error.GetString(ret); ReportError(string.Format("Error shutting down the Twitch sdk: {0}", err)); } m_ChatController.SetChatState(ChatState.Uninitialized); } else { // if shutdown fails the state will probably be messed up but this should never happen m_ChatController.SetChatState(ChatState.Initialized); ReportError(String.Format("Error shutting down Twith chat: {0}", result)); } try { if (m_ChatController.ShutdownComplete != null) { m_ChatController.ShutdownComplete(result); } } catch (Exception x) { m_ChatController.ReportError(x.ToString()); } }
public virtual bool Connect(bool anonymous) { m_Anonymous = anonymous; ErrorCode ret = ErrorCode.TTV_EC_SUCCESS; // connect to the channel if (anonymous) { ret = Api.ConnectAnonymous(m_ChannelName, this); } else { ret = Api.Connect(m_ChannelName, UserName, AuthToken, this); } if (Error.Failed(ret)) { String err = Error.GetString(ret); ReportError(String.Format("Error connecting: {0}", err)); FireDisconnected(m_ChannelName); return(false); } else { SetChannelState(ChannelState.Connecting); DownloadBadgeData(); return(true); } }
public bool Disconnect() { switch (m_ChannelState) { case ChannelState.Connected: case ChannelState.Connecting: { // kick off an async disconnect ErrorCode ret = Api.Disconnect(m_ChannelName); if (Error.Failed(ret)) { String err = Error.GetString(ret); ReportError(String.Format("Error disconnecting: {0}", err)); return(false); } SetChannelState(ChannelState.Disconnecting); return(true); } case ChannelState.Created: case ChannelState.Disconnected: case ChannelState.Disconnecting: default: { return(false); } } }
protected override void CheckError(ErrorCode err) { if (err != ErrorCode.TTV_EC_SUCCESS) { System.Windows.Forms.MessageBox.Show(err.ToString()); } }
internal virtual void SetupEmoticonData() { if (m_EmoticonData != null) { return; } ErrorCode ec = m_ChatApi.GetEmoticonData(out m_EmoticonData); if (Error.Succeeded(ec)) { try { if (EmoticonDataAvailable != null) { EmoticonDataAvailable(); } } catch (Exception x) { ReportError(x.ToString()); } } else { ReportError("Error preparing emoticon data: " + Error.GetString(ec)); } }
public virtual bool Initialize() { if (m_ChatState != ChatState.Uninitialized) { return(false); } SetChatState(ChatState.Initializing); ErrorCode ret = m_CoreApi.Initialize(ClientId, null); if (Error.Failed(ret)) { SetChatState(ChatState.Uninitialized); String err = Error.GetString(ret); ReportError(String.Format("Error initializing Twitch sdk: {0}", err)); return(false); } // initialize chat m_ActiveEmoticonMode = this.EmoticonParsingMode; TTV_ChatTokenizationOption tokenizationOptions = TTV_ChatTokenizationOption.TTV_CHAT_TOKENIZATION_OPTION_NONE; switch (m_ActiveEmoticonMode) { case EmoticonMode.None: tokenizationOptions = TTV_ChatTokenizationOption.TTV_CHAT_TOKENIZATION_OPTION_NONE; break; case EmoticonMode.Url: tokenizationOptions = TTV_ChatTokenizationOption.TTV_CHAT_TOKENIZATION_OPTION_EMOTICON_URLS; break; case EmoticonMode.TextureAtlas: tokenizationOptions = TTV_ChatTokenizationOption.TTV_CHAT_TOKENIZATION_OPTION_EMOTICON_TEXTURES; break; } // kick off the async init ret = m_ChatApi.Initialize(tokenizationOptions, m_ChatAPIListener); if (Error.Failed(ret)) { m_CoreApi.Shutdown(); SetChatState(ChatState.Uninitialized); String err = Error.GetString(ret); ReportError(String.Format("Error initializing Twitch chat: %s", err)); return(false); } else { SetChatState(ChatState.Initialized); return(true); } }
protected override bool CheckError(Twitch.ErrorCode err) { if (Error.Failed(err)) { System.Windows.Forms.MessageBox.Show(err.ToString()); return(false); } return(true); }
public override void Update() { base.Update(); // Submit video frame if (m_BroadcastState == BroadcastState.Broadcasting) { float curTime = Time.realtimeSinceStartup; // If you send frames too quickly to the SDK (based on the broadcast FPS you configured) it will not be able // to make use of them all. In that case, it will simply release buffers without using them which means the // game wasted time doing the capture. To mitigate this, the app should pace the captures to the broadcast FPS. float captureDelta = curTime - m_LastCaptureTime; bool isTimeForNextCapture = captureDelta >= (1.0f / (float)m_VideoParams.TargetFps); if (!isTimeForNextCapture) { return; } IntPtr p = m_SceneRenderTexture.GetNativeTexturePtr(); if (p != IntPtr.Zero) { ErrorCode ret = m_UnityBroadcastApi.SubmitTexturePointer(p, m_SceneRenderTexture.width, m_SceneRenderTexture.height); // mark the time of the first video frame submission (don't need to lock since we're setting a bool) m_AudioQueue.AcceptSamples = m_AudioParams.EnablePassthroughAudio; // if there is a problem when submitting a frame let the client know if (ret != ErrorCode.TTV_EC_SUCCESS) { string err = Error.GetString(ret); if (Error.Succeeded(ret)) { ReportWarning(string.Format("Warning in SubmitTexturePointer: {0}\n", err)); } else { ReportError(string.Format("Error in SubmitTexturePointer: {0}\n", err)); // errors are not recoverable StopBroadcasting(); } FireFrameSubmissionIssue(ret); } } m_LastCaptureTime = curTime; // TODO: we may need to handle multi-threaded rendering which means that we can't submit the texture from Update(), we need to use a render event //GL.IssuePluginEvent((int)123456); } }
void IChatChannelListener.ChatStatusCallback(string channelName, ErrorCode result) { if (Error.Succeeded(result)) { return; } // destroy the channel object Channels.Remove(m_ChannelName); DisconnectionComplete(); }
public override PixelFormat DeterminePixelFormat() { PixelFormat format = base.DeterminePixelFormat(); ErrorCode ret = m_UnityBroadcastApi.GetCapturePixelFormat(ref format); if (Error.Failed(ret)) { string err = Error.GetString(ret); ReportError(string.Format("Error in GetCapturePixelFormat: {0}", err)); } return(format); }
public override void Update() { base.Update(); if (m_BroadcastState != BroadcastState.Broadcasting) { return; } float curTime = Time.realtimeSinceStartup; // If you send frames too quickly to the SDK (based on the broadcast FPS you configured) it will not be able // to make use of them all. In that case, it will simply release buffers without using them which means the // game wasted time doing the capture. To mitigate this, the app should pace the captures to the broadcast FPS. float captureDelta = curTime - m_LastCaptureTime; bool isTimeForNextCapture = captureDelta >= (1.0f / (float)m_VideoParams.TargetFps); if (!isTimeForNextCapture) { return; } IntPtr p = m_BroadcastRenderTexture.GetNativeTexturePtr(); if (p != IntPtr.Zero) { ErrorCode ret = this.UnityStream.SubmitTexturePointer(p); // if there is a problem when submitting a frame let the client know if (ret != ErrorCode.TTV_EC_SUCCESS) { string err = Error.GetString(ret); if (Error.Succeeded(ret)) { ReportWarning(string.Format("Warning in SubmitTexturePointer: {0}\n", err)); } else { ReportError(string.Format("Error in SubmitTexturePointer: {0}\n", err)); // errors are not recoverable StopBroadcasting(); } FireFrameSubmissionIssue(ret); } } m_LastCaptureTime = curTime; }
internal virtual void DownloadEmoticonData() { // don't download emoticons if (m_ActiveEmoticonMode == EmoticonMode.None) { return; } if (m_EmoticonData == null) { ErrorCode ret = m_ChatApi.DownloadEmoticonData(); if (Error.Failed(ret)) { string err = Error.GetString(ret); ReportError(string.Format("Error trying to download emoticon data: {0}", err)); } } }
/// <summary> /// Periodically updates the internal state of the controller. /// </summary> public virtual void Update() { // for stress testing to make sure memory is being passed around properly //GC.Collect(); if (m_ChatState == ChatState.Uninitialized) { return; } ErrorCode ret = m_ChatApi.FlushEvents(); if (Error.Failed(ret)) { string err = Error.GetString(ret); ReportError(string.Format("Error flushing chat events: {0}, in state {1}", err, m_ChatState.ToString())); } }
internal virtual void SetupBadgeData() { if (m_BadgeData != null) { return; } ErrorCode ec = Api.GetBadgeData(m_ChannelName, out m_BadgeData); if (Error.Succeeded(ec)) { FireBadgeDataAvailable(m_ChannelName); } else { ReportError("Error preparing badge data: " + Error.GetString(ec)); } }
protected void UnityIosStreamInfoCallback(string message) { LitJson.JsonReader reader = new LitJson.JsonReader(message); Dictionary <string, string> dict = new Dictionary <string, string>(); reader.Read(); JsonReadFlatObjectIntoDictionary(reader, dict); ErrorCode status = (ErrorCode)Enum.Parse(typeof(ErrorCode), dict["Status"]); StreamInfo info = new StreamInfo(); info.Viewers = int.Parse(dict["Viewers"]); info.StreamId = UInt64.Parse(dict["Id"]); StreamInfoDoneCallback(status, info); }
protected void UnityIosUserInfoCallback(string message) { LitJson.JsonReader reader = new LitJson.JsonReader(message); Dictionary <string, string> dict = new Dictionary <string, string>(); reader.Read(); JsonReadFlatObjectIntoDictionary(reader, dict); ErrorCode status = (ErrorCode)Enum.Parse(typeof(ErrorCode), dict["Status"]); UserInfo info = new UserInfo(); info.Name = dict["Name"]; info.DisplayName = dict["DisplayName"]; UserInfoDoneCallback(status, info); }
protected void UnityIosArchivingStateCallback(string message) { LitJson.JsonReader reader = new LitJson.JsonReader(message); Dictionary <string, string> dict = new Dictionary <string, string>(); reader.Read(); JsonReadFlatObjectIntoDictionary(reader, dict); ErrorCode status = (ErrorCode)Enum.Parse(typeof(ErrorCode), dict["Status"]); ArchivingState state = new ArchivingState(); state.CureUrl = dict["CureUrl"]; state.RecordingEnabled = dict["RecordingEnabled"] != "0"; ArchivingStateDoneCallback(status, state); }
internal virtual void DownloadBadgeData() { // don't download badges if (this.ActiveEmoticonMode == EmoticonMode.None) { return; } if (m_BadgeData == null) { ErrorCode ret = Api.DownloadBadgeData(m_ChannelName); if (Error.Failed(ret)) { string err = Error.GetString(ret); ReportError(string.Format("Error trying to download badge data: {0}", err)); } } }
public bool SendChatMessage(string message) { if (m_ChannelState != ChannelState.Connected) { return(false); } ErrorCode ret = Api.SendMessage(m_ChannelName, message); if (Error.Failed(ret)) { String err = Error.GetString(ret); ReportError(String.Format("Error sending chat message: {0}", err)); return(false); } return(true); }
internal virtual void CleanupBadgeData() { if (m_BadgeData == null) { return; } ErrorCode ec = Api.ClearBadgeData(m_ChannelName); if (Error.Succeeded(ec)) { m_BadgeData = null; FireBadgeDataExpired(m_ChannelName); } else { ReportError("Error releasing badge data: " + Error.GetString(ec)); } }
protected void UnityIosRequestAuthTokenCallback(string message) { LitJson.JsonReader reader = new LitJson.JsonReader(message); Dictionary <string, string> dict = new Dictionary <string, string>(); reader.Read(); JsonReadFlatObjectIntoDictionary(reader, dict); ErrorCode status = (ErrorCode)Enum.Parse(typeof(ErrorCode), dict["Status"]); AuthToken token = null; if (Error.Succeeded(status)) { token = new AuthToken(); token.Data = dict["Token"]; } RequestAuthTokenDoneCallback(status, token); }
protected void UnityIosLoginCallback(string message) { LitJson.JsonReader reader = new LitJson.JsonReader(message); Dictionary <string, string> dict = new Dictionary <string, string>(); reader.Read(); JsonReadFlatObjectIntoDictionary(reader, dict); ErrorCode status = (ErrorCode)Enum.Parse(typeof(ErrorCode), dict["Status"]); ChannelInfo info = null; if (Error.Succeeded(status)) { info = new ChannelInfo(); info.Name = dict["Name"]; info.DisplayName = dict["DisplayName"]; info.ChannelUrl = dict["ChannelUrl"]; } LoginCallback(status, info); }
public virtual bool Shutdown() { if (m_ChatState != ChatState.Initialized) { return(false); } // shutdown asynchronously ErrorCode ret = m_ChatApi.Shutdown(); if (Error.Failed(ret)) { String err = Error.GetString(ret); ReportError(String.Format("Error shutting down chat: {0}", err)); return(false); } CleanupEmoticonData(); SetChatState(ChatState.ShuttingDown); return(true); }
protected void HandleFrameSubmissionIssue(ErrorCode result) { // if you are receiving TTV_WRN_QUEUELENGTH then it's possible the bitrate is too high for the user's internet connection DebugOverlay.Instance.AddViewportText("FrameSubmissionIssue: " + result.ToString(), 1); }
protected void FireGameNameListReceived(ErrorCode result, GameInfoList list) { try { if (m_BroadcastController.GameNameListReceived != null) { m_BroadcastController.GameNameListReceived(result, list == null ? new GameInfo[0] : list.List); } } catch (Exception x) { ReportError(x.ToString()); } }
protected void FireLoginAttemptComplete(ErrorCode result) { try { if (m_BroadcastController.LoginAttemptComplete != null) { m_BroadcastController.LoginAttemptComplete(result); } } catch (Exception x) { ReportError(x.ToString()); } }
void IStreamCallbacks.GetArchivingStateCallback(ErrorCode result, ArchivingState state) { this.ArchivingState = state; if (Error.Failed(result)) { //string err = Error.GetString(result); //ReportWarning(string.Format("ArchivingStateDoneCallback got failure: {0}", err)); } }
void IStreamCallbacks.LoginCallback(ErrorCode result, ChannelInfo channelInfo) { if (Error.Succeeded(result)) { this.ChannelInfo = channelInfo; SetBroadcastState(BroadcastState.LoggedIn); this.LoggedIn = true; } else { SetBroadcastState(BroadcastState.Initialized); this.LoggedIn = false; string err = Error.GetString(result); ReportError(string.Format("LoginCallback got failure: {0}", err)); } FireLoginAttemptComplete(result); }
void IChatAPIListener.ChatShutdownCallback(ErrorCode result) { if (Error.Succeeded(result)) { ErrorCode ret = m_ChatController.m_Core.Shutdown(); if (Error.Failed(ret)) { string err = Error.GetString(ret); ReportError(string.Format("Error shutting down the Twitch sdk: {0}", err)); } m_ChatController.SetChatState(ChatState.Uninitialized); } else { // if shutdown fails the state will probably be messed up but this should never happen m_ChatController.SetChatState(ChatState.Initialized); ReportError(String.Format("Error shutting down Twith chat: {0}", result)); } try { if (m_ChatController.ShutdownComplete != null) { m_ChatController.ShutdownComplete(result); } } catch (Exception x) { m_ChatController.ReportError(x.ToString()); } }
void IStreamCallbacks.StopCallback(ErrorCode ret) { if (Error.Succeeded(ret)) { this.VideoParams = null; this.AudioParams = null; CleanupBuffers(); FireBroadcastStopped(); if (this.LoggedIn) { SetBroadcastState(BroadcastState.ReadyToBroadcast); } else { SetBroadcastState(BroadcastState.Initialized); } } else { // there's not really a good state to go into here SetBroadcastState(BroadcastState.ReadyToBroadcast); string err = Error.GetString(ret); ReportError(string.Format("StopCallback got failure: {0}", err)); } }
void IChatChannelListener.ChatBadgeDataDownloadCallback(string channelName, ErrorCode error) { // grab the texture and badge data if (Error.Succeeded(error)) { SetupBadgeData(); } }
void IStreamCallbacks.GetStreamInfoCallback(ErrorCode result, StreamInfo streamInfo) { if (Error.Succeeded(result)) { this.StreamInfo = streamInfo; FireStreamInfoUpdated(streamInfo); } else { //string err = Error.GetString(result); //ReportWarning(string.Format("StreamInfoDoneCallback got failure: {0}", err)); } }
void IStreamCallbacks.SetStreamInfoCallback(ErrorCode result) { if (Error.Failed(result)) { string err = Error.GetString(result); ReportWarning(string.Format("SetStreamInfoCallback got failure: {0}", err)); } }
void IStreamCallbacks.SendStartSpanMetaDataCallback(ErrorCode ret) { if (Error.Failed(ret)) { string err = Error.GetString(ret); ReportError(string.Format("SendStartSpanMetaDataCallback got failure: {0}", err)); } }
void IStreamCallbacks.RequestAuthTokenCallback(ErrorCode result, AuthToken authToken) { if (Error.Succeeded(result)) { // Now that the user is authorized the information can be requested about which server to stream to this.AuthToken = authToken; SetBroadcastState(BroadcastState.Authenticated); } else { this.AuthToken.Data = ""; SetBroadcastState(BroadcastState.Initialized); string err = Error.GetString(result); ReportError(string.Format("RequestAuthTokenDoneCallback got failure: {0}", err)); } FireAuthTokenRequestComplete(result, authToken); }
protected void CheckError(ErrorCode err) { m_ChatController.CheckError(err); }
void IChatAPIListener.ChatEmoticonDataDownloadCallback(ErrorCode error) { if (Error.Succeeded(error)) { m_ChatController.SetupEmoticonData(); } }
protected void CheckError(ErrorCode err) { m_BroadcastController.CheckError(err); }
void IStreamCallbacks.StartCallback(ErrorCode ret) { if (Error.Succeeded(ret)) { FireBroadcastStarted(); SetBroadcastState(BroadcastState.Broadcasting); } else { this.VideoParams = null; this.AudioParams = null; SetBroadcastState(BroadcastState.ReadyToBroadcast); string err = Error.GetString(ret); ReportError(string.Format("StartCallback got failure: {0}", err)); } }
protected void FireAuthTokenRequestComplete(ErrorCode result, AuthToken authToken) { try { if (m_BroadcastController.AuthTokenRequestComplete != null) { m_BroadcastController.AuthTokenRequestComplete(result, authToken); } } catch (Exception x) { ReportError(x.ToString()); } }
protected virtual void CheckError(ErrorCode err) { }
void IStreamCallbacks.GetIngestServersCallback(ErrorCode result, IngestList ingestList) { if (Error.Succeeded(result)) { this.IngestList = ingestList; // assume we're going to use the default ingest server unless overidden by the client this.IngestServer = ingestList.DefaultServer; SetBroadcastState(BroadcastState.ReceivedIngestServers); FireIngestListReceived(ingestList); } else { string err = Error.GetString(result); ReportError(string.Format("IngestListCallback got failure: {0}", err)); // try again SetBroadcastState(BroadcastState.LoggedIn); } }
void IChatAPIListener.ChatInitializationCallback(ErrorCode result) { if (Error.Succeeded(result)) { Api.SetMessageFlushInterval(this.MessageFlushInterval); Api.SetUserChangeEventInterval(this.UserChangeEventInterval); m_ChatController.DownloadEmoticonData(); m_ChatController.SetChatState(ChatState.Initialized); } else { m_ChatController.SetChatState(ChatState.Uninitialized); } try { if (m_ChatController.InitializationComplete != null) { m_ChatController.InitializationComplete(result); } } catch (Exception x) { m_ChatController.ReportError(x.ToString()); } }
void IStreamCallbacks.GetGameNameListCallback(ErrorCode result, GameInfoList list) { if (Error.Failed(result)) { string err = Error.GetString(result); ReportError(string.Format("GameNameListCallback got failure: {0}", err)); } FireGameNameListReceived(result, list); }
protected void FireFrameSubmissionIssue(ErrorCode ret) { try { if (this.FrameSubmissionIssue != null) { this.FrameSubmissionIssue(ret); } } catch (Exception x) { ReportError(x.ToString()); } }
void IStreamCallbacks.GetUserInfoCallback(ErrorCode result, UserInfo userInfo) { this.UserInfo = userInfo; if (Error.Failed(result)) { string err = Error.GetString(result); ReportError(string.Format("UserInfoDoneCallback got failure: {0}", err)); } }