시그니처 후원
- 시그니처 별로 설정된 시간 만큼 GIF가 재생되도록 기능 추가
This commit is contained in:
		| @@ -95,7 +95,7 @@ extension LiveApi: TargetType { | ||||
|             return "/live/room/info/\(roomId)" | ||||
|              | ||||
|         case .donation: | ||||
|             return "/live/room/donation" | ||||
|             return "/live/room/donation/v2" | ||||
|              | ||||
|         case .refundDonation(let roomId): | ||||
|             return "/live/room/donation/refund/\(roomId)" | ||||
|   | ||||
| @@ -15,6 +15,7 @@ struct LiveRoomChatRawMessage: Codable { | ||||
|     let type: LiveRoomChatRawMessageType | ||||
|     let message: String | ||||
|     let can: Int | ||||
|     var signature: LiveRoomDonationResponse? = nil | ||||
|     var signatureImageUrl: String? = nil | ||||
|     let donationMessage: String? | ||||
|     var isActiveRoulette: Bool? = nil | ||||
|   | ||||
							
								
								
									
										13
									
								
								SodaLive/Sources/Live/Room/LiveRoomDonationResponse.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								SodaLive/Sources/Live/Room/LiveRoomDonationResponse.swift
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| // | ||||
| //  LiveRoomDonationResponse.swift | ||||
| //  SodaLive | ||||
| // | ||||
| //  Created by klaus on 5/1/24. | ||||
| // | ||||
|  | ||||
| import Foundation | ||||
|  | ||||
| struct LiveRoomDonationResponse: Codable { | ||||
|     let imageUrl: String | ||||
|     let time: Int | ||||
| } | ||||
| @@ -159,17 +159,13 @@ final class LiveRoomViewModel: NSObject, ObservableObject { | ||||
|      | ||||
|     @Published var signatureImageUrl = "" { | ||||
|         didSet { | ||||
|             if signatureImageUrl.trimmingCharacters(in: .whitespacesAndNewlines).count > 0 { | ||||
|                 DispatchQueue.main.asyncAfter(deadline: .now() + 7) { | ||||
|                     if let imageUrl = self.signatureImageUrls.first { | ||||
|                         self.signatureImageUrl = imageUrl | ||||
|                         self.signatureImageUrls.removeFirst() | ||||
|                     } else { | ||||
|                         self.signatureImageUrl = "" | ||||
|                         self.isShowSignatureImage = false | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             showSignatureImage() | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     @Published var signature: LiveRoomDonationResponse? = nil { | ||||
|         didSet { | ||||
|             showSignatureImage() | ||||
|         } | ||||
|     } | ||||
|      | ||||
| @@ -187,6 +183,7 @@ final class LiveRoomViewModel: NSObject, ObservableObject { | ||||
|     @Published var selectedMenu: SelectedMenu? = nil | ||||
|      | ||||
|     var signatureImageUrls = [String]() | ||||
|     var signatureList = [LiveRoomDonationResponse]() | ||||
|     var isShowSignatureImage = false | ||||
|      | ||||
|     var timer: DispatchSourceTimer? | ||||
| @@ -399,7 +396,7 @@ final class LiveRoomViewModel: NSObject, ObservableObject { | ||||
|                      | ||||
|                     do { | ||||
|                         let jsonDecoder = JSONDecoder() | ||||
|                         let decoded = try jsonDecoder.decode(ApiResponse<String>.self, from: responseData) | ||||
|                         let decoded = try jsonDecoder.decode(ApiResponse<LiveRoomDonationResponse>.self, from: responseData) | ||||
|                          | ||||
|                         self.isLoading = false | ||||
|                          | ||||
| @@ -409,7 +406,8 @@ final class LiveRoomViewModel: NSObject, ObservableObject { | ||||
|                                 type: .DONATION, | ||||
|                                 message: rawMessage, | ||||
|                                 can: can, | ||||
|                                 signatureImageUrl: decoded.data, | ||||
|                                 signature: decoded.data, | ||||
|                                 signatureImageUrl: decoded.data?.imageUrl, | ||||
|                                 donationMessage: message | ||||
|                             ) | ||||
|                              | ||||
| @@ -431,7 +429,7 @@ final class LiveRoomViewModel: NSObject, ObservableObject { | ||||
|                                         ) | ||||
|                                          | ||||
|                                         totalDonationCan += can | ||||
|                                         showSignatureImage(imageUrl: decoded.data ?? "") | ||||
|                                         addSignature(signature: decoded.data) | ||||
|                                          | ||||
|                                         self.messageChangeFlag.toggle() | ||||
|                                         if self.messages.count > 100 { | ||||
| @@ -1689,7 +1687,7 @@ final class LiveRoomViewModel: NSObject, ObservableObject { | ||||
|             .store(in: &subscription) | ||||
|     } | ||||
|      | ||||
|     private func showSignatureImage(imageUrl: String) { | ||||
|     private func addSignatureImage(imageUrl: String) { | ||||
|         if imageUrl.trimmingCharacters(in: .whitespacesAndNewlines).count > 0 { | ||||
|             if !isShowSignatureImage { | ||||
|                 isShowSignatureImage = true | ||||
| @@ -1699,6 +1697,41 @@ final class LiveRoomViewModel: NSObject, ObservableObject { | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     private func addSignature(signature: LiveRoomDonationResponse?) { | ||||
|         if let signature = signature { | ||||
|             if !isShowSignatureImage { | ||||
|                 self.signature = signature | ||||
|                 isShowSignatureImage = true | ||||
|             } else { | ||||
|                 self.signatureList.append(signature) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     private func showSignatureImage() { | ||||
|         if let signature = signature { | ||||
|             DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(signature.time)) { | ||||
|                 if let nextSignature = self.signatureList.first { | ||||
|                     self.signature = nextSignature | ||||
|                     self.signatureList.removeFirst() | ||||
|                 } else { | ||||
|                     self.signature = nil | ||||
|                     self.isShowSignatureImage = false | ||||
|                 } | ||||
|             } | ||||
|         } else if signatureImageUrl.trimmingCharacters(in: .whitespacesAndNewlines).count > 0 { | ||||
|             DispatchQueue.main.asyncAfter(deadline: .now() + 7) { | ||||
|                 if let imageUrl = self.signatureImageUrls.first { | ||||
|                     self.signatureImageUrl = imageUrl | ||||
|                     self.signatureImageUrls.removeFirst() | ||||
|                 } else { | ||||
|                     self.signatureImageUrl = "" | ||||
|                     self.isShowSignatureImage = false | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| extension LiveRoomViewModel: AgoraRtcEngineDelegate { | ||||
| @@ -1863,7 +1896,12 @@ extension LiveRoomViewModel: AgoraRtmChannelDelegate { | ||||
|                     ) | ||||
|                      | ||||
|                     self.totalDonationCan += decoded.can | ||||
|                     self.showSignatureImage(imageUrl: decoded.signatureImageUrl ?? "") | ||||
|                      | ||||
|                     if let signature = decoded.signature { | ||||
|                         self.addSignature(signature: signature) | ||||
|                     } else if let imageUrl = decoded.signatureImageUrl { | ||||
|                         self.addSignatureImage(imageUrl: imageUrl) | ||||
|                     } | ||||
|                 } else if decoded.type == .ROULETTE_DONATION { | ||||
|                     self.messages.append( | ||||
|                         LiveRoomRouletteDonationChat( | ||||
|   | ||||
| @@ -272,6 +272,21 @@ struct LiveRoomViewV2: View { | ||||
|                                         Spacer() | ||||
|                                     } | ||||
|                                 } | ||||
|                                  | ||||
|                                 if let signature = viewModel.signature { | ||||
|                                     VStack { | ||||
|                                         Spacer() | ||||
|                                          | ||||
|                                         AnimatedImage(url: URL(string: signature.imageUrl)) | ||||
|                                             .resizable() | ||||
|                                             .aspectRatio(contentMode: .fit) | ||||
|                                             .frame(width: screenSize().width - 64) | ||||
|                                          | ||||
|                                         Spacer() | ||||
|                                         Spacer() | ||||
|                                         Spacer() | ||||
|                                     } | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                          | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Yu Sung
					Yu Sung