/// Begin handing chat packets for the connected channel

Begin handing chat packets for the connected channel
Begin handing chat packets for the connected channel
pub fn handle_chat(mut self) -> Result<(), MixerError> {
		println!("Joining channel: {}", &self.channel);
		self.join()?;
		println!("Connected to: {}", &self.channel);
		// Now that we're connected to the channel, we want to fire the `on_connect` event.
		let result = self.handler.on_connect();
		handle_handler_result(result, &mut self)?;
		while let Ok(packet) = self.client.recv_message() {
			match packet {
				OwnedMessage::Ping(packet) => self.client.send_message(&OwnedMessage::Ping(packet)).unwrap(),
				OwnedMessage::Text(text) => match serde_json::from_str::<BasePacket>(&text) {
					Ok(packet) => {
						match packet.packet_type {
							PacketType::Event => {
								let event_packet = serde_json::from_str(&text);
								if let Err(_) = event_packet {
									continue;
								}
								let event_packet: EventPacket = event_packet.unwrap();
								let result = match event_packet.event {
									EventType::ClearMessages => {
										self.handler.on_chat_cleared()
									},
									EventType::UserJoin => {
										let user_packet = serde_json::from_str::<UserJoinPacket>(&text).unwrap();
										self.handler.on_user_join(user_packet)
									},
									EventType::UserLeave => {
										let user_packet = serde_json::from_str::<UserLeavePacket>(&text).unwrap();
										self.handler.on_user_leave(user_packet)
									},
									EventType::PurgeMessage => {
										let purge_packet = serde_json::from_str::<PurgeUserPacket>(&text).unwrap();
										self.handler.on_user_purged(purge_packet)
									},
									EventType::UserTimeout => {
										let timeout_packet = serde_json::from_str::<TimeoutPacket>(&text).unwrap();
										self.handler.on_user_timeout(timeout_packet)
									},
									EventType::ChatMessage => {
										let chat_packet = serde_json::from_str::<ChatMessageEventPacket>(&text).unwrap();
										self.handler.on_message(chat_packet)
									}
									_ => HandlerResult::Nothing
								};
								handle_handler_result(result, &mut self)?;
							},
							PacketType::Method => unreachable!(),
							PacketType::Reply => {}
						}
					},
					Err(_) => println!("Could not parse text into JSON: {}", text)
				},
				OwnedMessage::Close(_) => return Ok(()),
				_ => println!("Unhandled packet type!")
			};
		}
		Ok(())
	}
pub fn handle_chat ( mut self ) -> Result < ( ) , MixerError > { println ! ( " " self channel ) ; self . join ( ) ? ; println ! ( " " self channel ) ; // Now that we're connected to the channel, we want to fire the `on_connect` event.
 let result = self . handler . on_connect ( ) ; handle_handler_result ( result , & mut self ) ? ; while let Ok ( packet ) = self . client . recv_message ( ) { match packet { OwnedMessage :: Ping ( packet ) => self . client . send_message ( & OwnedMessage :: Ping ( packet ) ) . unwrap ( ) , OwnedMessage :: Text ( text ) => match serde_json :: from_str :: < BasePacket > ( & text ) { Ok ( packet ) => { match packet . packet_type { PacketType :: Event => { let event_packet = serde_json :: from_str ( & text ) ; if let Err ( _ ) = event_packet { continue ; } let event_packet : EventPacket = event_packet . unwrap ( ) ; let result = match event_packet . event { EventType :: ClearMessages => { self . handler . on_chat_cleared ( ) } , EventType :: UserJoin => { let user_packet = serde_json :: from_str :: < UserJoinPacket > ( & text ) . unwrap ( ) ; self . handler . on_user_join ( user_packet ) } , EventType :: UserLeave => { let user_packet = serde_json :: from_str :: < UserLeavePacket > ( & text ) . unwrap ( ) ; self . handler . on_user_leave ( user_packet ) } , EventType :: PurgeMessage => { let purge_packet = serde_json :: from_str :: < PurgeUserPacket > ( & text ) . unwrap ( ) ; self . handler . on_user_purged ( purge_packet ) } , EventType :: UserTimeout => { let timeout_packet = serde_json :: from_str :: < TimeoutPacket > ( & text ) . unwrap ( ) ; self . handler . on_user_timeout ( timeout_packet ) } , EventType :: ChatMessage => { let chat_packet = serde_json :: from_str :: < ChatMessageEventPacket > ( & text ) . unwrap ( ) ; self . handler . on_message ( chat_packet ) } _ => HandlerResult :: Nothing } ; handle_handler_result ( result , & mut self ) ? ; } , PacketType :: Method => unreachable ! ( ) , PacketType :: Reply => { } } } , Err ( _ ) => println ! ( " " text ) } , OwnedMessage :: Close ( _ ) => return Ok ( ( ) ) , _ => println ! ( " " ) } ; } Ok ( ( ) ) }
Begin handing chat packets for the connected channel
Begin handing chat packets for the connected channel
mut self