-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] 웹소켓 연결 #414 #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[Feat] 웹소켓 연결 #414 #427
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
db3d13f
feat: 웹소켓 연결, 네트워크 감지 및 백오프 구현 #414
edv-Shin 958e7b1
feat: 소켓 request와 response 분리 #414
edv-Shin c8b5544
refactor: 메세지 전송 로직 수정 (회의 필요) #414
edv-Shin cf5c4b8
Merge remote-tracking branch 'origin/dev' into feat/websocket-414
edv-Shin 2714c95
fix: dto 수정 #414
edv-Shin 810330c
chore: 불필요한 주석 삭제 #414
edv-Shin b3e739b
fix: ktlint 문법 수정 #414
edv-Shin 665044b
feat: 주석 추가 #414
edv-Shin d47824d
fix: magic string를 constant로 수정 #426
edv-Shin 5a9560f
feat: thread safe하지 않은 변수를 AtomicInteger로 수정 #414
edv-Shin 4fb3d61
refactor: repositoryScope 도입, Job 단위 취소로 리소스 누수 해결 #414
edv-Shin 1e4787d
fix: Mutex 도입을 통한 웹소켓 중복 연결 및 타이밍 이슈 해결 #414
edv-Shin c7e5e9c
fix: ktlint 문법 수정 #414
edv-Shin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest> | ||
|
|
||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
| </manifest> |
55 changes: 55 additions & 0 deletions
55
common/src/main/java/com/project200/common/utils/NetworkMonitor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package com.project200.common.utils | ||
|
|
||
| import android.Manifest | ||
| import android.content.Context | ||
| import android.net.ConnectivityManager | ||
| import android.net.Network | ||
| import android.net.NetworkCapabilities | ||
| import android.net.NetworkRequest | ||
| import androidx.annotation.RequiresPermission | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import kotlinx.coroutines.channels.awaitClose | ||
| import kotlinx.coroutines.flow.callbackFlow | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class NetworkMonitor | ||
| @Inject | ||
| constructor( | ||
| @ApplicationContext context: Context, | ||
| ) { | ||
| private val connectivityManager = | ||
| context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||
|
|
||
| // 현재 인터넷 연결 여부 확인 | ||
| @RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE) | ||
| fun isCurrentlyConnected(): Boolean { | ||
| val activeNetwork = connectivityManager.activeNetwork ?: return false | ||
| val capabilities = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false | ||
| return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) | ||
| } | ||
|
|
||
| // 네트워크 상태 변경 감지 Flow | ||
| val networkState = | ||
| callbackFlow { | ||
| val callback = | ||
| object : ConnectivityManager.NetworkCallback() { | ||
| override fun onAvailable(network: Network) { | ||
| trySend(true) | ||
| } | ||
|
|
||
| override fun onLost(network: Network) { | ||
| trySend(false) | ||
| } | ||
| } | ||
|
|
||
| val request = | ||
| NetworkRequest.Builder() | ||
| .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) | ||
| .build() | ||
|
|
||
| connectivityManager.registerNetworkCallback(request, callback) | ||
| awaitClose { connectivityManager.unregisterNetworkCallback(callback) } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest> | ||
|
|
||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
| </manifest> |
13 changes: 13 additions & 0 deletions
13
data/src/main/java/com/project200/data/api/ChatApiService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.project200.data.api | ||
|
|
||
| import com.project200.data.dto.BaseResponse | ||
| import com.project200.data.dto.TicketResponse | ||
| import retrofit2.http.POST | ||
| import retrofit2.http.Path | ||
|
|
||
| interface ChatApiService { | ||
| @POST("api/v1/chat-rooms/{chatroomId}/ticket") | ||
| suspend fun getChatTicket( | ||
| @Path("chatroomId") chatroomId: Long, | ||
| ): BaseResponse<TicketResponse> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Core network module로 빼는건 어떤가요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋은 생각인 것 같습니다!
추후 모듈로 분리하는 pr 따로 올리겠습니다