private void BtYoutube_Click(object sender, EventArgs e) { if (ws.IsAlive == false) { return; } if (youtubeWindow != null) { youtubeWindow.BringToFront(); return; } youtubeWindow = new YoutubeWindow(); youtubeWindow.FormClosing += YoutubeWindow_FormClosing; youtubeWindow.Show(); }
private void YoutubeWindow_FormClosing(object sender, FormClosingEventArgs e) { youtubeWindow = null; }
// Handling incoming messages private void Ws_OnMessage(object sender, MessageEventArgs e) { if (e.Data != String.Empty) { string msg = "<empty message>"; // Response for handshake if (e.Data.Contains("register_0")) { RegisterResponse rr = JsonConvert.DeserializeObject <RegisterResponse>(e.Data); msg = "Handshake successful." + Environment.NewLine + rr.ToString(); SubscribeWebsocketEvents(); } else if (e.Data.Contains("newPair")) { CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data); if (cfr.Payload.ReturnValue && cfr.Type == "response") { msg = "Pairing request acknowledged."; } else if (!cfr.Payload.ReturnValue && cfr.Type == "response") { msg = "Pairing request unsuccessful."; } else if (cfr.Type == "registered") { RegisterResponse rr = JsonConvert.DeserializeObject <RegisterResponse>(e.Data); if (String.IsNullOrEmpty(selectedDevice.ApiKey)) { selectedDevice.ApiKey = rr.Payload.client_key; } SaveDeviceList(); SubscribeWebsocketEvents(); } } // Response for audio status request else if (e.Data.Contains("volume_sub")) { AudioStatusResponse asr = JsonConvert.DeserializeObject <AudioStatusResponse>(e.Data); msg = "Audio status received." + Environment.NewLine + asr.ToString(); // Displaying the volume level string txt = asr.Payload.Volume + "/" + asr.Payload.VolumeMax; btVol.Invoke(new Action(() => { btVol.Text = txt; })); // Setting the speaker icon on mute button if (asr.Payload.Mute) { btnMute.Invoke(new Action(() => { btnMute.Image = Resources.Speaker_off; })); Global._isMuted = true; } else { btnMute.Invoke(new Action(() => { btnMute.Image = Resources.Speaker_on; })); Global._isMuted = false; } } // Response for volume up request else if (e.Data.Contains("volumeup_1")) { CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data); if (cfr.Payload.ReturnValue) { msg = "Volume up acknowledged."; } else { msg = "Volume up request rejected."; } } // Response for volume down request else if (e.Data.Contains("volumedown_1")) { CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data); if (cfr.Payload.ReturnValue) { msg = "Volume down acknowledged."; } else { msg = "Volume down request rejected."; } } // Response for toggle mute request else if (e.Data.Contains("toggle_mute")) { CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data); if (cfr.Payload.ReturnValue) { msg = "Toggle mute acknowledged."; } else { msg = "Toggle mute request rejected."; } } // Response for current channel info request else if (e.Data.Contains("channel_sub")) { ci = JsonConvert.DeserializeObject <ChannelInfo>(e.Data); // Displaying the current channel string chan = String.Format("({0}) {1}", ci.Payload.ChannelNumber, ci.Payload.ChannelName); btVol.Invoke(new Action(() => { btChan.Text = chan; })); msg = "Current channel info arrived."; } // Response for channel up/down request else if (e.Data.Contains("channelup_1") || e.Data.Contains("channeldown_1")) { CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data); if (cfr.Payload.ReturnValue) { GetCurrentChannel(); msg = cfr.Id == "channelup_1" ? "Channel up success." : "Channel down success."; } } // Response for get channels list request else if (e.Data.Contains("getchannels_1")) { clr = JsonConvert.DeserializeObject <ChannelListResponse>(e.Data); if (clr.Payload.ReturnValue == true) { // Opening the channel list window chWindow = new ChannelListWindow { channels = clr.Payload.ChannelList }; chWindow.ci = ci; chWindow.ShowDialog(); msg = "Channel list request succeeded."; } else { msg = "Channel list request unsuccessful."; } } else if (e.Data.Contains("get_inputlist")) { if (e.Data.Contains("\"returnValue\":true")) { Input response = new Input(); response = JsonConvert.DeserializeObject <Input>(e.Data); inputWindow = new InputListWindow { InputList = response.Payload.Devices }; inputWindow.ShowDialog(); } } // Response for displaying toast message on the screen request else if (e.Data.Contains("toast_1")) { CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data); if (cfr.Payload.ReturnValue) { msg = "Toast message request succeeded."; } else { msg = "Toast message request rejected."; } } else if (e.Data.Contains("openchannel_1")) { // Missing response from WebOs!!! //CallFunctionResponse cfr = JsonConvert.DeserializeObject<CallFunctionResponse>(e.Data); //if (cfr.Payload.returnValue) //{ // msg = "Open channel request succeeded."; //} //else //{ // msg = "Open channel request rejected."; //} } else if (e.Data.Contains("youtube_open")) { AppSession.LaunchAppResponse yr = JsonConvert.DeserializeObject <AppSession.LaunchAppResponse>(e.Data); if (yr.Payload.ReturnValue) { msg = "Youtube open video request succeeded."; (Application.OpenForms["YoutubeWindow"] as YoutubeWindow).ClearUrlField(); (Application.OpenForms["YoutubeWindow"] as YoutubeWindow).sessionId = yr.Payload.SessionId; appSession.SessionId = yr.Payload.SessionId; } else { msg = "Youtube open video request rejected."; } } else if (e.Data.Contains("youtube_close")) { CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data); if (cfr.Payload.ReturnValue == true) { msg = "Youtube app close request succeeded."; youtubeWindow.Invoke(new Action(() => { youtubeWindow.Close(); })); youtubeWindow = null; } else { msg = "Youtube app close request rejected." + Environment.NewLine + e.Data; } } else if (e.Data.Contains("ForeGroundAppInfo")) { AppSession.AppInfoResponse yr = JsonConvert.DeserializeObject <AppSession.AppInfoResponse>(e.Data); if (yr.Payload.ReturnValue) { msg = "Foreground app info request succeeded."; switch (yr.Payload.AppId) { case "youtube.leanback.v4": (Application.OpenForms["YoutubeWindow"] as YoutubeWindow).youtubeInfo = yr; break; case "com.webos.app.livetv": break; default: break; } } else { msg = "Foreground app info request rejected."; } } else if (e.Data.Contains("play_01")) { CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data); if (cfr.Payload.ReturnValue) { msg = "Play button request succeeded."; } else { msg = "Play button request rejected."; } } else if (e.Data.Contains("pause")) { CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data); if (cfr.Payload.ReturnValue) { msg = "Pause button request succeeded."; } else { msg = "Pause button request rejected."; } } else if (e.Data.Contains("getchannelprograminfo_1")) { channelProgramInfo = JsonConvert.DeserializeObject <ChannelProgramInfo>(e.Data); if (channelProgramInfo.Payload.ReturnValue) { // Opening the program info list window progInfoWindow = new ProgramInfoWindow { ChanProginfo = channelProgramInfo }; progInfoWindow.ShowDialog(); msg = "Channel program info request succeeded."; } else { msg = "Channel program info request rejected."; } } else { msg = e.Data; } DisplayMessage(msg); } }