Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccim_sdk_android
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
ccim_sdk_android
Commits
a210c021
Commit
a210c021
authored
Jan 20, 2022
by
sheteng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
心跳问题
parent
cba08841
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
111 additions
and
80 deletions
+111
-80
.idea/misc.xml
.idea/misc.xml
+3
-0
app/src/main/java/com/ccwangluo/im/adapter/PrivateMsgAdapter.java
...main/java/com/ccwangluo/im/adapter/PrivateMsgAdapter.java
+5
-5
app/src/main/java/com/ccwangluo/im/ui/dashboard/ConnectFragment.java
...n/java/com/ccwangluo/im/ui/dashboard/ConnectFragment.java
+12
-7
app/src/main/java/com/ccwangluo/im/ui/notifications/ConnectChannelFragment.java
...ccwangluo/im/ui/notifications/ConnectChannelFragment.java
+5
-2
app/src/main/res/layout/activity_login.xml
app/src/main/res/layout/activity_login.xml
+3
-3
ccim/src/main/java/com/ccwangluo/ccim/CCIMClient.java
ccim/src/main/java/com/ccwangluo/ccim/CCIMClient.java
+1
-1
ccim/src/main/java/com/ccwangluo/ccim/manage/SocketManager.java
...rc/main/java/com/ccwangluo/ccim/manage/SocketManager.java
+13
-2
ccim/src/main/java/com/ccwangluo/ccim/socket/NettyChatClient.java
.../main/java/com/ccwangluo/ccim/socket/NettyChatClient.java
+28
-21
ccim/src/main/java/com/ccwangluo/ccim/util/ErrorCode.java
ccim/src/main/java/com/ccwangluo/ccim/util/ErrorCode.java
+1
-0
ccim/src/main/proto/common.proto
ccim/src/main/proto/common.proto
+40
-39
No files found.
.idea/misc.xml
View file @
a210c021
...
...
@@ -27,6 +27,9 @@
</map>
</option>
</component>
<component
name=
"ProjectPlainTextFileTypeManager"
>
<file
url=
"file://$PROJECT_DIR$/app/release/output-metadata.json"
/>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_8"
default=
"true"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
</component>
...
...
app/src/main/java/com/ccwangluo/im/adapter/PrivateMsgAdapter.java
View file @
a210c021
...
...
@@ -16,15 +16,15 @@ import com.ccwangluo.ccim.listener.ResultEventCallback;
import
com.ccwangluo.ccim.modle.MessageContent
;
import
com.ccwangluo.im.R
;
import
java.util.
List
;
import
java.util.
Collection
;
public
class
PrivateMsgAdapter
extends
BaseAdapter
{
private
List
<
MessageContent
>
dataList
;
private
Collection
<
MessageContent
>
dataList
;
private
Context
context
;
public
PrivateMsgAdapter
(
List
<
MessageContent
>
dataList
,
Context
context
)
{
public
PrivateMsgAdapter
(
Collection
<
MessageContent
>
dataList
,
Context
context
)
{
this
.
dataList
=
dataList
;
this
.
context
=
context
;
}
...
...
@@ -46,7 +46,7 @@ public class PrivateMsgAdapter extends BaseAdapter {
@Override
public
Object
getItem
(
int
position
)
{
return
dataList
.
get
(
position
)
;
return
position
;
}
@Override
...
...
@@ -68,7 +68,7 @@ public class PrivateMsgAdapter extends BaseAdapter {
}
else
{
mHolder
=
(
ViewHolder
)
convertView
.
getTag
();
}
MessageContent
message
=
dataList
.
get
(
position
)
;
MessageContent
message
=
(
MessageContent
)
dataList
.
toArray
()[
position
]
;
if
(
message
.
getSenderUserId
()
!=
null
)
{
mHolder
.
msg_content
.
setVisibility
(
View
.
VISIBLE
);
mHolder
.
msg_content_send
.
setVisibility
(
View
.
GONE
);
...
...
app/src/main/java/com/ccwangluo/im/ui/dashboard/ConnectFragment.java
View file @
a210c021
...
...
@@ -19,15 +19,16 @@ import com.ccwangluo.im.data.LoginViewModel;
import
com.ccwangluo.im.databinding.FragmentConnectBinding
;
import
com.ccwangluo.im.util.ToastUtil
;
import
java.util.
ArrayList
;
import
java.util.
HashMap
;
import
java.util.List
;
public
class
ConnectFragment
extends
Fragment
{
private
FragmentConnectBinding
binding
;
private
LoginViewModel
loginViewModel
;
private
PrivateMsgAdapter
privaetMsgAdapter
;
private
List
<
MessageContent
>
list
=
new
ArrayList
<>();
private
HashMap
<
Long
,
MessageContent
>
map
=
new
HashMap
<>();
private
String
filePath
;
private
boolean
isSuccess
=
false
;
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -42,7 +43,7 @@ public class ConnectFragment extends Fragment {
loginViewModel
=
new
ViewModelProvider
(
getActivity
())
.
get
(
LoginViewModel
.
class
);
privaetMsgAdapter
=
new
PrivateMsgAdapter
(
list
,
getContext
());
privaetMsgAdapter
=
new
PrivateMsgAdapter
(
map
.
values
()
,
getContext
());
binding
.
msgList
.
setAdapter
(
privaetMsgAdapter
);
...
...
@@ -52,7 +53,7 @@ public class ConnectFragment extends Fragment {
@Override
public
void
onChanged
(
MessageContent
messageContent
)
{
if
(
messageContent
.
getSenderUserId
().
equals
(
contact
.
getContactUserId
())
||
messageContent
.
getReciveUserId
().
equals
(
contact
.
getContactUserId
()))
{
list
.
add
(
messageContent
);
map
.
put
(
messageContent
.
getMsgId
(),
messageContent
);
privaetMsgAdapter
.
refreshData
();
binding
.
msgList
.
setSelection
(
privaetMsgAdapter
.
getCount
()
-
1
);
}
...
...
@@ -83,6 +84,7 @@ public class ConnectFragment extends Fragment {
@Override
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_UP
)
{
if
(
isSuccess
)
CCIMClient
.
getInstance
().
stopAndSendAudioMessage
(
contact
.
getContactUserId
(),
contact
.
getContactUserName
(),
new
ResultEventCallback
<
MessageContent
>()
{
@Override
public
void
onSuccess
(
MessageContent
message
)
{
...
...
@@ -101,12 +103,13 @@ public class ConnectFragment extends Fragment {
CCIMClient
.
getInstance
().
startRecordAudioMessage
(
getActivity
(),
new
ResultEventCallback
<
Void
>()
{
@Override
public
void
onSuccess
(
Void
unused
)
{
isSuccess
=
true
;
}
@Override
public
void
onFailed
(
int
errorCode
)
{
isSuccess
=
false
;
ToastUtil
.
show
(
getContext
(),
errorCode
+
""
);
}
});
}
...
...
@@ -117,7 +120,9 @@ public class ConnectFragment extends Fragment {
CCIMClient
.
getInstance
().
getPrivateMessage
(
contact
.
getContactUserId
(),
new
ResultEventCallback
<
List
<
MessageContent
>>()
{
@Override
public
void
onSuccess
(
List
<
MessageContent
>
messageContents
)
{
list
.
addAll
(
messageContents
);
for
(
MessageContent
messageContent
:
messageContents
)
{
map
.
put
(
messageContent
.
getMsgId
(),
messageContent
);
}
privaetMsgAdapter
.
refreshData
();
binding
.
msgList
.
setSelection
(
privaetMsgAdapter
.
getCount
()
-
1
);
}
...
...
app/src/main/java/com/ccwangluo/im/ui/notifications/ConnectChannelFragment.java
View file @
a210c021
...
...
@@ -26,6 +26,7 @@ public class ConnectChannelFragment extends Fragment {
private
LoginViewModel
loginViewModel
;
private
ChannelMsgAdapter
channelMsgAdapter
;
private
List
<
MessageContent
>
list
=
new
ArrayList
<>();
private
boolean
isSuccess
;
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -95,6 +96,7 @@ public class ConnectChannelFragment extends Fragment {
@Override
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_UP
)
{
if
(
isSuccess
)
CCIMClient
.
getInstance
().
stopAndSendChannelAudioMessage
(
channelId
,
new
ResultEventCallback
<
MessageContent
>()
{
@Override
public
void
onSuccess
(
MessageContent
message
)
{
...
...
@@ -113,12 +115,13 @@ public class ConnectChannelFragment extends Fragment {
CCIMClient
.
getInstance
().
startRecordAudioMessage
(
getActivity
(),
new
ResultEventCallback
<
Void
>()
{
@Override
public
void
onSuccess
(
Void
unused
)
{
isSuccess
=
true
;
}
@Override
public
void
onFailed
(
int
errorCode
)
{
isSuccess
=
false
;
ToastUtil
.
show
(
getContext
(),
errorCode
+
""
);
}
});
}
...
...
app/src/main/res/layout/activity_login.xml
View file @
a210c021
...
...
@@ -14,7 +14,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"Username"
android:text=
"2
0
"
android:text=
"2
1
"
android:inputType=
"textEmailAddress"
android:selectAllOnFocus=
"true"
app:layout_constraintEnd_toEndOf=
"parent"
...
...
@@ -27,7 +27,7 @@
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:hint=
"UserId"
android:text=
"2
0
"
android:text=
"2
1
"
android:imeActionLabel=
"@string/action_sign_in_short"
android:imeOptions=
"actionDone"
android:selectAllOnFocus=
"true"
...
...
@@ -69,7 +69,7 @@
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:hint=
"ip"
android:text=
"10
.4.5.134
"
android:text=
"10
6.15.237.67
"
android:imeActionLabel=
"@string/action_sign_in_short"
android:imeOptions=
"actionDone"
android:selectAllOnFocus=
"true"
...
...
ccim/src/main/java/com/ccwangluo/ccim/CCIMClient.java
View file @
a210c021
...
...
@@ -64,7 +64,7 @@ public class CCIMClient {
private
CCIMClient
()
{
callBackManager
=
new
CallBackManager
<>();
socketManager
=
new
SocketManager
(
callBackManager
);
socketManager
=
new
SocketManager
(
callBackManager
,
executor
);
contactManager
=
new
ContactManager
(
socketManager
,
callBackManager
);
channelManager
=
new
ChannelManager
(
socketManager
,
callBackManager
);
messageManager
=
new
MessageManager
(
socketManager
,
callBackManager
,
executor
);
...
...
ccim/src/main/java/com/ccwangluo/ccim/manage/SocketManager.java
View file @
a210c021
...
...
@@ -14,6 +14,7 @@ import com.ccwangluo.ccim.socket.SocketClient;
import
com.ccwangluo.ccim.util.ErrorCode
;
import
com.google.protobuf.util.JsonFormat
;
import
java.util.concurrent.ExecutorService
;
import
java.util.logging.Logger
;
import
ccim.protocol.Chat
;
...
...
@@ -31,6 +32,7 @@ public class SocketManager {
private
Handler
handler
=
new
Handler
(
Looper
.
getMainLooper
());
private
final
CallBackManager
<
Chat
.
ChatResponseMessage
>
callBackManager
;
private
ExecutorService
executor
;
public
SocketManager
(
CallBackManager
<
Chat
.
ChatResponseMessage
>
callBackManager
)
{
this
.
callBackManager
=
callBackManager
;
...
...
@@ -40,6 +42,11 @@ public class SocketManager {
private
SocketClient
socketClient
;
public
SocketManager
(
CallBackManager
<
Chat
.
ChatResponseMessage
>
callBackManager
,
ExecutorService
executor
)
{
this
.
callBackManager
=
callBackManager
;
this
.
executor
=
executor
;
}
public
void
connectChatServer
(
String
appKey
,
String
userName
,
String
extData
,
Long
userId
,
Long
ts
,
String
sign
,
String
gameServer
)
{
logger
.
info
(
"send connect"
);
...
...
@@ -76,7 +83,7 @@ public class SocketManager {
public
void
initChat
(
Context
context
,
String
appKey
,
String
userName
,
String
extData
,
Long
userId
,
Long
ts
,
String
sign
,
String
server
,
OnClientConnectListener
resultCallback
)
{
onConnectListener
=
resultCallback
;
if
(
socketClient
==
null
)
{
socketClient
=
new
NettyChatClient
(
context
,
SERVER_IP
,
SERVER_PORT
);
socketClient
=
new
NettyChatClient
(
context
,
SERVER_IP
,
SERVER_PORT
,
executor
);
}
socketClient
.
connect
(
new
MessageListener
()
{
@Override
...
...
@@ -115,9 +122,13 @@ public class SocketManager {
handler
.
post
(()
->
{
if
(
data
.
getHeader
().
getCode
()
==
Common
.
StatusCode
.
STATUS_CODE_OK
)
{
callBack
.
onSuccess
(
data
);
}
else
{
if
(
data
.
getHeader
().
getCode
()
==
Common
.
StatusCode
.
UNRECOGNIZED
){
callBack
.
onFailed
(
ErrorCode
.
ERRORCODE_NOT_EXISTS
);
}
else
{
callBack
.
onFailed
(
data
.
getHeader
().
getCode
().
getNumber
());
}
}
});
if
(
seq
>
0
)
{
//push消息
callBackManager
.
removeCallBack
(
seq
);
...
...
ccim/src/main/java/com/ccwangluo/ccim/socket/NettyChatClient.java
View file @
a210c021
...
...
@@ -9,9 +9,9 @@ import com.ccwangluo.ccim.CCIMClient;
import
com.ccwangluo.ccim.listener.MessageListener
;
import
com.ccwangluo.ccim.util.ErrorCode
;
import
java.util.
concurrent.Executors
;
import
java.util.
concurrent.ScheduledExecutorService
;
import
java.util.concurrent.
TimeUnit
;
import
java.util.
Timer
;
import
java.util.
TimerTask
;
import
java.util.concurrent.
ExecutorService
;
import
java.util.logging.Logger
;
import
ccim.protocol.Chat
;
...
...
@@ -40,13 +40,15 @@ public class NettyChatClient implements SocketClient {
private
Bootstrap
bootstrap
;
private
Context
context
;
EventLoopGroup
group
=
new
NioEventLoopGroup
();
ScheduledExecutorService
timerExcutor
;
private
ExecutorService
executor
;
private
Timer
timer
;
public
NettyChatClient
(
Context
context
,
String
ip
,
int
port
)
{
public
NettyChatClient
(
Context
context
,
String
ip
,
int
port
,
ExecutorService
executor
)
{
this
.
ip
=
ip
;
this
.
port
=
port
;
this
.
context
=
context
;
this
.
executor
=
executor
;
//注意:客户端使用的不是 ServerBootStrap 而是 Bootstrap
bootstrap
=
new
Bootstrap
();
//设置相关参数
...
...
@@ -77,6 +79,9 @@ public class NettyChatClient implements SocketClient {
}
private
void
connectSync
()
{
executor
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
channelFuture
=
bootstrap
.
connect
(
ip
,
port
).
sync
();
}
catch
(
Exception
e
)
{
...
...
@@ -86,6 +91,8 @@ public class NettyChatClient implements SocketClient {
}
}
}
});
}
public
boolean
getConnectivityStatus
(
Context
context
)
{
...
...
@@ -118,8 +125,9 @@ public class NettyChatClient implements SocketClient {
@Override
public
void
destroy
()
{
if
(
timerExcutor
!=
null
)
{
timerExcutor
.
shutdown
();
if
(
timer
!=
null
)
{
timer
.
cancel
();
timer
=
null
;
}
if
(
channelFuture
!=
null
)
{
channelFuture
.
channel
().
close
();
...
...
@@ -137,12 +145,12 @@ public class NettyChatClient implements SocketClient {
@Override
public
void
heartBeat
(
Long
frequency
,
Chat
.
ChatRequestMessage
build
)
{
if
(
timerExcutor
!=
null
)
{
timerExcutor
.
shutdown
();
if
(
timer
!=
null
){
timer
.
cancel
();
timer
=
null
;
}
timerExcutor
=
Executors
.
newScheduledThreadPool
(
1
);
timerExcutor
.
schedule
(
new
Runnable
()
{
@Override
timer
=
new
Timer
();
timer
.
schedule
(
new
TimerTask
()
{
public
void
run
()
{
if
(
getConnectivityStatus
(
context
))
{
if
(
channelFuture
!=
null
&&
channelFuture
.
channel
().
isActive
())
{
...
...
@@ -158,8 +166,7 @@ public class NettyChatClient implements SocketClient {
}
}
}
},
frequency
,
TimeUnit
.
MILLISECONDS
);
},
frequency
*
1000
,
frequency
*
1000
);
}
public
class
NettyClientHandler
extends
ChannelInboundHandlerAdapter
{
...
...
ccim/src/main/java/com/ccwangluo/ccim/util/ErrorCode.java
View file @
a210c021
...
...
@@ -11,6 +11,7 @@ public class ErrorCode {
public
static
final
int
MSG_TYPE_ERROR
=
906
;
//播放类型错误
public
static
final
int
DOWNLOAD_ERR
=
907
;
//播放类型错误
public
static
final
int
MSG_NOT_EXISTS
=
908
;
//播放类型错误
public
static
final
int
ERRORCODE_NOT_EXISTS
=
909
;
//错误类型不存在
public
static
final
int
MSG_CONTENT_IS_EMPTY
=
910
;
//发送消息体为空
public
static
final
int
START_VOICE_FAILED
=
911
;
//录音创建失败
...
...
ccim/src/main/proto/common.proto
View file @
a210c021
...
...
@@ -24,6 +24,7 @@ enum StatusCode {
// CHAT_SERVICE_ERROR = 30000;
STATUS_CODE_CHECK_CONTACT_UPDATED_ERROR
=
30001
;
// 好友请求已同意或拒绝
STATUS_CODE_CONTACT_GROUP_EXCEEDED_LIMIT_ERROR
=
30002
;
// 群组成员到达上限
STATUS_CODE_CONTACT_EXCEEDED_LIMIT_ERROR
=
30003
;
// 联系人达到上限
STATUS_CODE_NOT_CONTACT_ERROR
=
30101
;
// 非好友不能调用该api
STATUS_CODE_USER_MUTED_ERROR
=
30102
;
// 用户被禁言
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment