xiewenjie vor 3 Jahren
Ursprung
Commit
2ac05dbefc

+ 62 - 11
pom.xml

@@ -14,12 +14,6 @@
     <name>fdkk-meta</name>
     <description>fdkk-meta</description>
     <packaging>jar</packaging>
-    <repositories>
-        <repository>
-            <id>jitpack.io</id>
-            <url>https://jitpack.io</url>
-        </repository>
-    </repositories>
     <properties>
         <java.version>1.8</java.version>
         <hutool.version>5.7.7</hutool.version>
@@ -29,7 +23,10 @@
         <mybatis-plus-boot-starter.version>3.4.3.1</mybatis-plus-boot-starter.version>
         <druid.version>1.2.6</druid.version>
         <pagehelper.boot.version>1.3.1</pagehelper.boot.version>
-
+        <grpc.version>1.36.0</grpc.version>
+        <os.plugin.version>1.5.0.Final</os.plugin.version>
+        <protobuf.plugin.version>0.5.0</protobuf.plugin.version>
+        <protoc.version>3.3.0</protoc.version>
     </properties>
     <dependencies>
         <dependency>
@@ -134,15 +131,51 @@
 <!--        </dependency>-->
         <!--redis连接池 end-->
         <dependency>
-            <groupId>com.github.soriole</groupId>
-            <artifactId>webrtc-signaling-server</artifactId>
-            <version>v0.0.6</version>
+            <groupId>net.devh</groupId>
+            <artifactId>grpc-client-spring-boot-starter</artifactId>
+            <version>2.13.1.RELEASE</version>
+        </dependency>
+        <dependency>
+            <groupId>net.devh</groupId>
+            <artifactId>grpc-server-spring-boot-starter</artifactId>
+            <version>2.13.1.RELEASE</version>
+        </dependency>
+        <!-- grpc 这里的版本很重要,不同的版本代码都会有不同 -->
+
+        <dependency>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-protobuf</artifactId>
+            <version>${grpc.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-stub</artifactId>
+            <version>${grpc.version}</version>
+        </dependency>
+        <!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java-util -->
+        <dependency>
+            <groupId>com.google.protobuf</groupId>
+            <artifactId>protobuf-java-util</artifactId>
+            <version>3.7.1</version>
+        </dependency>
+
+        <!-- https://mvnrepository.com/artifact/com.googlecode.protobuf-java-format/protobuf-java-format -->
+        <dependency>
+            <groupId>com.googlecode.protobuf-java-format</groupId>
+            <artifactId>protobuf-java-format</artifactId>
+            <version>1.4</version>
         </dependency>
     </dependencies>
 
 
     <build>
-
+        <extensions>
+            <extension>
+                <groupId>kr.motd.maven</groupId>
+                <artifactId>os-maven-plugin</artifactId>
+                <version>${os.plugin.version}</version>
+            </extension>
+        </extensions>
         <resources>
             <resource>
                 <directory>src/main/resources</directory>
@@ -172,6 +205,24 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.xolstice.maven.plugins</groupId>
+                <artifactId>protobuf-maven-plugin</artifactId>
+                <version>${protobuf.plugin.version}</version>
+                <configuration>
+                    <protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
+                    <pluginId>grpc-java</pluginId>
+                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>compile</goal>
+                            <goal>compile-custom</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
         <finalName>${project.artifactId}</finalName>
     </build>

+ 0 - 2
src/main/java/com/fdkk/fdkkmeta/FdkkMetaApplication.java

@@ -1,8 +1,6 @@
 package com.fdkk.fdkkmeta;
 
-import com.fdkk.fdkkmeta.config.TrtcConfig;
 import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

+ 15 - 0
src/main/java/com/fdkk/fdkkmeta/config/MetaConfig.java

@@ -0,0 +1,15 @@
+package com.fdkk.fdkkmeta.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "fdkk")
+public class MetaConfig {
+
+    private String freespacePath;
+
+
+}

+ 0 - 19
src/main/java/com/fdkk/fdkkmeta/config/TrtcConfig.java

@@ -1,19 +0,0 @@
-package com.fdkk.fdkkmeta.config;
-
-import lombok.Data;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.PostConstruct;
-
-@Data
-@Component
-@ConfigurationProperties(prefix = "trtc")
-public class TrtcConfig {
-
-    private String rtmpHost;
-
-
-}

+ 46 - 0
src/main/java/com/fdkk/fdkkmeta/grpcService/sceneGrpcServer.java

@@ -0,0 +1,46 @@
+package com.fdkk.fdkkmeta.grpcService;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ArrayUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.fdkk.fdkkmeta.config.MetaConfig;
+import com.fdkk.fdkkmeta.domain.dto.RouteDto;
+import com.fdkk.fdkkmeta.domain.po.PointPO;
+import com.fdkk.fdkkmeta.grpc.*;
+import com.fdkk.fdkkmeta.util.ProtoJsonUtils;
+import com.fdkk.fdkkmeta.util.kesar.GetRoute;
+import com.google.protobuf.Message;
+import com.googlecode.protobuf.format.JsonFormat;
+import io.grpc.stub.StreamObserver;
+import lombok.extern.slf4j.Slf4j;
+import net.devh.boot.grpc.server.service.GrpcService;
+import org.json.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author Xiewj
+ * @date 2022/5/9
+ */
+@GrpcService
+@Slf4j
+public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBase {
+    @Autowired
+    MetaConfig metaConfig;
+    @Override
+    public void testMethod(SceneRequest request, StreamObserver<SceneReply> responseObserver) {
+        // grpc服务端获取调用端请求参数
+        String id = request.getId();
+        String name = request.getName();
+        // 这里可以有自己的业务代码,只需要按照porto中的返回类型返回参数即可
+        SceneReply res = SceneReply.newBuilder().setRes(id+","+name).build();
+        responseObserver.onNext(res);
+        responseObserver.onCompleted();
+        log.info("回复{}",res);
+
+    }
+
+}

+ 0 - 1
src/main/java/com/fdkk/fdkkmeta/socketIO/ServerRunner.java

@@ -1,7 +1,6 @@
 package com.fdkk.fdkkmeta.socketIO;
 
 import com.corundumstudio.socketio.SocketIOServer;
-import com.fdkk.fdkkmeta.config.TrtcConfig;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.core.annotation.Order;

+ 0 - 21
src/main/java/com/fdkk/fdkkmeta/socketIO/SocketIoServer.java

@@ -22,7 +22,6 @@ import com.fdkk.fdkkmeta.domain.vo.PointsVO;
 import com.fdkk.fdkkmeta.redis.RedisCache;
 import com.fdkk.fdkkmeta.util.FpsUtil;
 import com.fdkk.fdkkmeta.util.GenerateUserSig;
-import com.fdkk.fdkkmeta.util.TrtcUtil;
 import com.fdkk.fdkkmeta.util.kesar.GetRoute;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -45,8 +44,6 @@ public class SocketIoServer {
     private static SocketIOServer socketIoServer;
 
     @Autowired
-    TrtcUtil trtcUtil;
-    @Autowired
     RedisCache redisCache;
 
     // 获取推送消息接收入口
@@ -253,24 +250,6 @@ public class SocketIoServer {
                 reverses);
     }
 
-    // 获取推送消息接收入口
-    @OnEvent(value = "getPush")
-    public void getPush(SocketIOClient client, AckRequest ackRequest, PushDto param) throws IOException, InterruptedException {
-        SocketIoServer.log.info("接收到客户端消息:{}", JSON.toJSONString(param));
-        //TODO 调用命令去推送流
-        String pushURl = trtcUtil.getPushURl(param);
-        SocketIoServer.log.info("转换URL:{}", pushURl);
-        String key="r:"+param.getRoomId()+"u:"+param.getUserId();
-        log.info("user-key,{}",key);
-        //创建线程
-        //判断当前用户是否开启推流线程
-        if (!redisCache.hasKey(key)){
-            String userId = param.getUserId();
-            String pid = "123123";
-            log.info("pid{}",pid);
-        }
-//        client.sendEvent("getPush", pushURl);
-    }
     /**
      * 加入房间
      * */

+ 36 - 0
src/main/java/com/fdkk/fdkkmeta/util/ProtoJsonUtils.java

@@ -0,0 +1,36 @@
+package com.fdkk.fdkkmeta.util;
+import com.google.gson.Gson;
+import com.google.protobuf.Message;
+import com.google.protobuf.util.JsonFormat;
+import com.google.protobuf.Message;
+
+import java.io.IOException;
+
+/**
+ * 特别主要:
+ * <ul>
+ *  <li>该实现无法处理含有Any类型字段的Message</li>
+ *  <li>enum类型数据会转化为enum的字符串名</li>
+ *  <li>bytes会转化为utf8编码的字符串</li>
+ * </ul>
+ * @author Yang Guanrong
+ * @date 2019/08/20 17:11
+ */
+public class ProtoJsonUtils {
+
+    public static String toJson(Message sourceMessage)
+            throws IOException {
+        String json = JsonFormat.printer().print(sourceMessage);
+        return json;
+    }
+
+    public static Message toProtoBean(Message.Builder targetBuilder, String json){
+        try {
+            JsonFormat.parser().merge(json, targetBuilder);
+
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return targetBuilder.build();
+    }
+}

+ 0 - 21
src/main/java/com/fdkk/fdkkmeta/util/TrtcUtil.java

@@ -1,21 +0,0 @@
-package com.fdkk.fdkkmeta.util;
-
-import com.fdkk.fdkkmeta.config.TrtcConfig;
-import com.fdkk.fdkkmeta.domain.dto.PushDto;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-/**
- * @author Xiewj
- * @date 2022/3/29
- */
-@Component
-public class TrtcUtil {
-   @Autowired
-   TrtcConfig trtcConfig;
-
-   public String getPushURl(PushDto dto){
-
-      return trtcConfig.getRtmpHost()+dto.getRoomId();
-   }
-}

+ 46 - 0
src/main/proto/scene.proto

@@ -0,0 +1,46 @@
+//版本
+syntax = "proto3";
+package scene;
+option java_multiple_files = true;
+// grpc插件生成的类的报名,随便写
+option java_package = "com.fdkk.fdkkmeta.grpc";
+
+// grpc的方法
+service SceneGrpcService {
+  rpc testMethod (SceneRequest) returns (SceneReply){}
+  rpc getRoute (RouteRequest) returns (RouteReply){}
+
+}
+// 全局对象
+message Point {
+  string x=1;
+  string y=2;
+  string z=3;
+}
+// 全局对象
+message RouteArray{
+  int32 id=1;
+  Point location=2;
+}
+// getRoute入参对象
+message RouteRequest {
+  Point s_location=1;
+  Point e_location=2;
+  string sceneCode=3;
+}
+
+// getRoute出参对象
+message RouteReply{
+  repeated RouteArray in=1;
+}
+
+// 入参对象
+message SceneRequest {
+  string id=1;
+  string name=2;
+}
+// 出参对象
+message SceneReply {
+  string res=1;
+}
+

+ 8 - 4
src/main/resources/application-dev.yml

@@ -9,8 +9,8 @@ socketio:
   port: 9099
   upgradeTimeout: 1000000
   workCount: 100
-trtc:
-  rtmpHost: "rtmp://rtmp.rtc.qq.com/push/"
+fdkk:
+  freespacePath: H:\workfile
 server:
   port: 9010
   servlet:
@@ -105,11 +105,15 @@ mybatis-plus:
       table-underline: true
   mapper-locations: classpath*:mapper/**/*Mapper.xml
   typeAliasesPackage: com.fdkk.**.domain
-
-
 # PageHelper分页插件
 pagehelper:
   helperDialect: mysql
   supportMethodsArguments: true
   params: count=countSql
   page-size-zero: true
+grpc:
+  # grpc server相关配置
+  server:
+    # 启动端口
+    port: 3000
+    address: 0.0.0.0

+ 0 - 1
src/test/java/com/fdkk/fdkkmeta/FdkkMetaApplicationTests.java

@@ -6,7 +6,6 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.socket.aio.AioClient;
 import cn.hutool.socket.aio.AioSession;
 import cn.hutool.socket.aio.SimpleIoAction;
-import com.fdkk.fdkkmeta.config.TrtcConfig;
 import com.fdkk.fdkkmeta.redis.RedisCache;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;