添加构建maven配置

This commit is contained in:
远方夕阳 2022-08-18 15:40:17 +08:00
parent 822bc6f104
commit d2e9727df7
33 changed files with 377 additions and 64 deletions

View File

@ -9,6 +9,22 @@
<version>4.2.0</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>Netty based instant messaging android sdk</description>
<url>https://github.com/farsunset/cim</url>
<licenses>
<license>
<name>Apache License</name>
<url>http://www.apache.org/licenses/</url>
</license>
</licenses>
<scm>
<connection>https://github.com/farsunset/cim.git</connection>
<url>https://github.com/farsunset/cim</url>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -18,8 +34,6 @@
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-lite</artifactId>
@ -35,17 +49,107 @@
</dependency>
</dependencies>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
<additionalparam>-Xdoclint:none</additionalparam>
<!-- TODO 临时解决不规范的javadoc生成报错,后面要规范化后把这行去掉 -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!--Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<verbose>true</verbose>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!--Release -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<developers>
<developer>
<name>Jun Xia</name>
<email>3979434@qq.com</email>
<roles>
<role>Developer</role>
</roles>
<timezone>+8</timezone>
</developer>
</developers>
</project>

View File

@ -0,0 +1 @@
mvn clean install deploy -P release

View File

@ -33,35 +33,30 @@ public interface CIMEventListener {
/**
* 当收到服务端推送过来的消息时调用
*
* @param message
*/
void onMessageReceived(Message message);
/**
* 当调用CIMPushManager.sendRequest()向服务端发送请求获得相应时调用
*
* 当调用CIMPushManager.sendRequest()向服务端发送请求获得服务端响应时调用
* @param body
*/
void onReplyReceived(ReplyBody body);
/**
* 当调用CIMPushManager.sendRequest()向服务端发送请求成功时
*
* @param body
*/
void onSendFinished(SentBody body);
/**
* 当手机网络发生变化时调用
*
* @param info
*/
void onNetworkChanged(NetworkInfo info);
/**
* 当连接服务器成功时回调
*
* @param hasAutoBind true 已经自动绑定账号到服务器了不需要再手动调用bindAccount
*/
void onConnectFinished(boolean hasAutoBind);

View File

@ -38,7 +38,7 @@ import java.util.Locale;
import java.util.UUID;
/**
* CIM 功能接口
* CIM客户端sdk功能接口
*/
public class CIMPushManager {
@ -63,6 +63,9 @@ public class CIMPushManager {
/**
* 初始化,连接服务端在程序启动页或者 在Application里调用
* @param context
* @param host cim服务端IP或者域名
* @param port cim服务端端口
*/
public static void connect(Context context, String host, int port) {
@ -84,6 +87,11 @@ public class CIMPushManager {
}
/**
* 设置SDK日志打印开关
* @param context
* @param enable
*/
public static void setLoggerEnable(Context context, boolean enable) {
Intent serviceIntent = new Intent(context, CIMPushService.class);
serviceIntent.putExtra(CIMPushService.KEY_LOGGER_ENABLE, enable);
@ -91,6 +99,14 @@ public class CIMPushManager {
startService(context, serviceIntent);
}
/**
* 开启常驻通知栏
* @param context
* @param icon 通知图标
* @param channel 通知channel
* @param message 显示内容
*/
public static void startForeground(Context context,int icon, String channel , String message) {
Intent serviceIntent = new Intent(context, CIMPushService.class);
serviceIntent.putExtra(CIMPushService.KEY_NOTIFICATION_MESSAGE, message);
@ -100,6 +116,10 @@ public class CIMPushManager {
startService(context, serviceIntent);
}
/**
* 关闭常驻通知栏
* @param context
*/
public static void cancelForeground(Context context) {
Intent serviceIntent = new Intent(context, CIMPushService.class);
serviceIntent.setAction(ACTION_HIDE_PERSIST_NOTIFICATION);
@ -107,12 +127,21 @@ public class CIMPushManager {
}
/**
* 设置一个账号登录到服务端
* bind账户
* 通知服务端 长连接和uid进行关联
* @param context
* @param uid 用户标识
*/
public static void bind(Context context, long uid) {
bind(context,String.valueOf(uid));
}
/**
* bind账户
* 通知服务端 长连接和uid进行关联
* @param context
* @param uid 用户标识
*/
public static void bind(Context context, String uid) {
if (isDestroyed(context)) {
@ -122,6 +151,11 @@ public class CIMPushManager {
sendBindRequest(context, uid);
}
/**
* 通知服务端给当前长连接设置tag
* @param context
* @param tag 标识
*/
public static void setTag(Context context, String tag) {
SentBody sent = new SentBody();
@ -131,6 +165,10 @@ public class CIMPushManager {
}
/**
* 通知服务端清除tag
* @param context
*/
public static void removeTag(Context context) {
SentBody sent = new SentBody();
@ -139,6 +177,10 @@ public class CIMPushManager {
}
/**
* 长连接发送一次心跳响应
* @param context
*/
public static void pong(Context context) {
if (isDestroyed(context) || isStopped(context)) {
return;
@ -149,6 +191,8 @@ public class CIMPushManager {
startService(context, serviceIntent);
}
private static void sendBindRequest(Context context, String uid) {
CIMCacheManager.putBoolean(context, CIMCacheManager.KEY_MANUAL_STOP, false);
@ -182,7 +226,9 @@ public class CIMPushManager {
}
/**
* 发送一个CIM请求
* 向服务端发送一次自定义业务请求
* @param context
* @param body 请求体
*/
public static void sendRequest(Context context, SentBody body) {
@ -240,29 +286,50 @@ public class CIMPushManager {
autoBindAccount(context);
}
/**
* 获取sdk是否已经销毁的
* @param context
* @return
*/
public static boolean isDestroyed(Context context) {
return CIMCacheManager.getBoolean(context, CIMCacheManager.KEY_CIM_DESTROYED);
}
/**
* 判断是否暂停接收消息
* @param context
* @return
*/
public static boolean isStopped(Context context) {
return CIMCacheManager.getBoolean(context, CIMCacheManager.KEY_MANUAL_STOP);
}
/**
* 判断于服务端连接是否正常
* @param context
*/
public static boolean isConnected(Context context) {
return CIMCacheManager.getBoolean(context, CIMCacheManager.KEY_CIM_CONNECTION_STATE);
}
/**
* 判断客户端网络连接是否正常
* @param context
*/
public static boolean isNetworkConnected(Context context) {
NetworkInfo networkInfo = getNetworkInfo(context);
return networkInfo != null && networkInfo.isConnected();
}
/**
* 获取服务端网络信息
* @param context
*/
public static NetworkInfo getNetworkInfo(Context context) {
return ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
}
public static void startService(Context context, Intent intent) {
protected static void startService(Context context, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
} else {
@ -270,7 +337,6 @@ public class CIMPushManager {
}
}
private static String getVersionName(Context context) {
try {

View File

@ -9,6 +9,21 @@
<version>4.2.0</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>Netty based instant messaging server sdk for java</description>
<url>https://github.com/farsunset/cim</url>
<licenses>
<license>
<name>Apache License</name>
<url>http://www.apache.org/licenses/</url>
</license>
</licenses>
<scm>
<connection>https://github.com/farsunset/cim.git</connection>
<url>https://github.com/farsunset/cim</url>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -81,17 +96,106 @@
</dependency>
</dependencies>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
<additionalparam>-Xdoclint:none</additionalparam>
<!-- TODO 临时解决不规范的javadoc生成报错,后面要规范化后把这行去掉 -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!--Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<verbose>true</verbose>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!--Release -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<developers>
<developer>
<name>Jun Xia</name>
<email>3979434@qq.com</email>
<roles>
<role>Developer</role>
</roles>
<timezone>+8</timezone>
</developer>
</developers>
</project>

1
cim-server-sdk/release.sh Executable file
View File

@ -0,0 +1 @@
mvn clean install deploy -P release

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -49,6 +49,9 @@ public class AppSocketAcceptor extends NioSocketAcceptor {
}
/**
* bind基于tlv协议的socket端口
*/
public void bind(){
if (!config.isEnable()){

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -79,6 +79,9 @@ public class WebsocketAcceptor extends NioSocketAcceptor {
this.handshakeHandler = new HandshakeHandler(config.getHandshakePredicate());
}
/**
* bind基于websocket协议的socket端口
*/
public void bind(){
if (!config.isEnable()){

View File

@ -6,10 +6,19 @@ public class AppSocketConfig {
private static final int DEFAULT_PORT = 23456;
/*
TVL协议socket端口
*/
private Integer port;
/*
* socket消息处理器
*/
private CIMRequestHandler outerRequestHandler;
/*
是否启用TVL协议socket
*/
private boolean enable;
public Integer getPort() {

View File

@ -6,6 +6,9 @@ import com.farsunset.cim.handshake.HandshakeEvent;
import java.util.function.Predicate;
/**
* 基于websocket的服务配置
*/
public class WebsocketConfig {
private static final int DEFAULT_PORT = 34567;
@ -16,9 +19,24 @@ public class WebsocketConfig {
private Integer port;
private String path;
/*
* 消息体协议JSON 或者 Protobuf
*/
private WebsocketProtocol protocol;
/*
* socket消息处理器
*/
private CIMRequestHandler outerRequestHandler;
/*
* websocket鉴权实现
*/
private Predicate<HandshakeEvent> handshakePredicate;
/*
* 是否启用websocket
*/
private boolean enable;
public Integer getPort() {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -13,6 +13,10 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* 基于内存管理的channel组
* 根据UID管理
*/
public class SessionGroup extends ConcurrentHashMap<String, Collection<Channel>> {
private static final Collection<Channel> EMPTY_LIST = new LinkedList<>();

View File

@ -4,6 +4,11 @@ package com.farsunset.cim.group;
import com.farsunset.cim.constant.ChannelAttr;
import io.netty.channel.Channel;
/**
* 基于内存管理的channel组
* 根据tag管理
*/
public class TagSessionGroup extends SessionGroup {
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
* Copyright 2013-2022 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.