From 73fe4a42ecc53deced5bf105e540f0524a27b1ef Mon Sep 17 00:00:00 2001 From: jack ning Date: Sun, 8 Jun 2025 13:23:55 +0800 Subject: [PATCH] update plugins/freeswitch: add 1 mod 7 del 1 files --- .../kbase/batch/KnowledgeExportJob.java | 2 - .../java/com/bytedesk/voc/VocApplication.java | 1 - .../freeswitch/EslInboundClientExample.java | 83 -------- .../freeswitch/FreeSwitchConfig.java | 4 +- .../FreeSwitchEslInboundConfig.java | 179 ++++++++++++++++++ 5 files changed, 180 insertions(+), 89 deletions(-) delete mode 100644 plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/EslInboundClientExample.java create mode 100644 plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/FreeSwitchEslInboundConfig.java diff --git a/modules/kbase/src/main/java/com/bytedesk/kbase/batch/KnowledgeExportJob.java b/modules/kbase/src/main/java/com/bytedesk/kbase/batch/KnowledgeExportJob.java index 758a878885..1afbbe8db3 100644 --- a/modules/kbase/src/main/java/com/bytedesk/kbase/batch/KnowledgeExportJob.java +++ b/modules/kbase/src/main/java/com/bytedesk/kbase/batch/KnowledgeExportJob.java @@ -34,7 +34,6 @@ package com.bytedesk.kbase.batch; // import org.springframework.context.annotation.Bean; // import org.springframework.context.annotation.Configuration; // import org.springframework.core.io.FileSystemResource; -// import org.springframework.scheduling.annotation.EnableScheduling; // // import org.springframework.scheduling.annotation.Scheduled; // import org.springframework.transaction.PlatformTransactionManager; @@ -48,7 +47,6 @@ package com.bytedesk.kbase.batch; // */ // @Slf4j // @Configuration -// @EnableScheduling // @RequiredArgsConstructor // public class KnowledgeExportJob { diff --git a/modules/voc/src/main/java/com/bytedesk/voc/VocApplication.java b/modules/voc/src/main/java/com/bytedesk/voc/VocApplication.java index 0ae7102503..dc818dbe83 100644 --- a/modules/voc/src/main/java/com/bytedesk/voc/VocApplication.java +++ b/modules/voc/src/main/java/com/bytedesk/voc/VocApplication.java @@ -18,7 +18,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication // @EnableCaching // @EnableAsync -// @EnableScheduling public class VocApplication { // public static void main(String[] args) { diff --git a/plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/EslInboundClientExample.java b/plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/EslInboundClientExample.java deleted file mode 100644 index f9ae1f858a..0000000000 --- a/plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/EslInboundClientExample.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * @Author: jackning 270580156@qq.com - * @Date: 2025-06-05 20:19:54 - * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-06-07 09:35:10 - * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk - * Please be aware of the BSL license restrictions before installing Bytedesk IM – - * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. - * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE - * contact: 270580156@qq.com - * - * Copyright (c) 2025 by bytedesk.com, All Rights Reserved. - */ -package com.bytedesk.freeswitch.freeswitch; - -import link.thingscloud.freeswitch.esl.IEslEventListener; -import link.thingscloud.freeswitch.esl.InboundClient; -import link.thingscloud.freeswitch.esl.ServerConnectionListener; -import link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption; -import link.thingscloud.freeswitch.esl.inbound.option.ServerOption; -import link.thingscloud.freeswitch.esl.transport.event.EslEvent; - -/** - * https://github.com/zhouhailin/freeswitch-externals - * - *

EslInboundClientExample class.

- * - * @author : zhouhailin - * @version 1.0.0 - */ -public class EslInboundClientExample { - - /** - *

main.

- * - * @param args an array of {@link java.lang.String} objects. - */ - public static void main(String[] args) { - InboundClientOption option = new InboundClientOption(); - - option.defaultPassword("ClueCon") - .addServerOption(new ServerOption("172.16.44.246", 8021)); - option.addEvents("all"); - - option.addListener(new IEslEventListener() { - @Override - public void eventReceived(String addr, EslEvent event) { - System.out.println(addr); - System.out.println(event); - } - - @Override - public void backgroundJobResultReceived(String addr, EslEvent event) { - System.out.println(addr); - System.out.println(event); - } - }); - - option.serverConnectionListener(new ServerConnectionListener() { - @Override - public void onOpened(ServerOption serverOption) { - System.out.println("---onOpened--"); - } - - @Override - public void onClosed(ServerOption serverOption) { - System.out.println("---onClosed--"); - } - }); - - InboundClient inboundClient = InboundClient.newInstance(option); - - inboundClient.start(); - - - System.out.println(option.serverAddrOption().first()); - System.out.println(option.serverAddrOption().last()); - System.out.println(option.serverAddrOption().random()); - - - } - -} diff --git a/plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/FreeSwitchConfig.java b/plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/FreeSwitchConfig.java index ecdf32bc91..ebfbdc2ba1 100644 --- a/plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/FreeSwitchConfig.java +++ b/plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/FreeSwitchConfig.java @@ -2,7 +2,7 @@ * @Author: jackning 270580156@qq.com * @Date: 2025-05-24 10:14:52 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-06-07 07:13:25 + * @LastEditTime: 2025-06-08 13:15:20 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -20,7 +20,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; -import org.springframework.scheduling.annotation.EnableScheduling; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -29,7 +28,6 @@ import lombok.extern.slf4j.Slf4j; @Slf4j @Configuration @RequiredArgsConstructor -@EnableScheduling @ComponentScan("com.bytedesk.freeswitch") @ConditionalOnProperty(name = "bytedesk.freeswitch.enabled", havingValue = "true", matchIfMissing = false) public class FreeSwitchConfig { diff --git a/plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/FreeSwitchEslInboundConfig.java b/plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/FreeSwitchEslInboundConfig.java new file mode 100644 index 0000000000..1066fbf3a3 --- /dev/null +++ b/plugins/freeswitch/src/main/java/com/bytedesk/freeswitch/freeswitch/FreeSwitchEslInboundConfig.java @@ -0,0 +1,179 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2025-06-05 20:19:54 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-06-08 13:10:08 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * + * Copyright (c) 2025 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.freeswitch.freeswitch; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import link.thingscloud.freeswitch.esl.IEslEventListener; +import link.thingscloud.freeswitch.esl.InboundClient; +import link.thingscloud.freeswitch.esl.ServerConnectionListener; +import link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption; +import link.thingscloud.freeswitch.esl.inbound.option.ServerOption; +import link.thingscloud.freeswitch.esl.transport.event.EslEvent; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * 使用 thingscloud 库的 FreeSwitch ESL 客户端配置 + * + * 参考链接:https://github.com/zhouhailin/freeswitch-externals + * + * @author jackning + * @version 1.0.0 + */ +@Slf4j +@Configuration +@RequiredArgsConstructor +@ComponentScan("com.bytedesk.freeswitch") +@ConditionalOnProperty(name = "bytedesk.freeswitch.enabled", havingValue = "true", matchIfMissing = false) +public class FreeSwitchEslInboundConfig { + + private final FreeSwitchProperties freeSwitchProperties; + + /** + * 配置基于 thingscloud 的 FreeSwitch ESL 客户端 + */ + @Bean + public InboundClient thingsCloudEslClient() { + InboundClientOption option = new InboundClientOption(); + + log.info("配置 thingscloud ESL 客户端: {}:{}", + freeSwitchProperties.getServer(), + freeSwitchProperties.getEslPort()); + + // 配置服务器连接信息 + option.defaultPassword(freeSwitchProperties.getEslPassword()) + .addServerOption(new ServerOption( + freeSwitchProperties.getServer(), + freeSwitchProperties.getEslPort() + )); + + // 订阅所有事件 + option.addEvents("all"); + + // 添加事件监听器 + option.addListener(new IEslEventListener() { + @Override + public void eventReceived(String addr, EslEvent event) { + log.debug("收到事件来自 {}: {}", addr, event.getEventName()); + // 在这里可以添加具体的事件处理逻辑 + handleEvent(event); + } + + @Override + public void backgroundJobResultReceived(String addr, EslEvent event) { + log.debug("收到后台任务结果来自 {}: {}", addr, event); + } + }); + + // 添加服务器连接监听器 + option.serverConnectionListener(new ServerConnectionListener() { + @Override + public void onOpened(ServerOption serverOption) { + log.info("thingscloud ESL 连接已打开: {}:{}", + serverOption.host(), serverOption.port()); + } + + @Override + public void onClosed(ServerOption serverOption) { + log.warn("thingscloud ESL 连接已关闭: {}:{}", + serverOption.host(), serverOption.port()); + } + }); + + // 创建并启动客户端 + InboundClient inboundClient = InboundClient.newInstance(option); + + try { + inboundClient.start(); + log.info("thingscloud ESL 客户端启动成功"); + } catch (Exception e) { + log.error("thingscloud ESL 客户端启动失败: {}", e.getMessage(), e); + } + + return inboundClient; + } + + /** + * 处理接收到的事件 + */ + private void handleEvent(EslEvent event) { + String eventName = event.getEventName(); + + switch(eventName) { + case "CHANNEL_CREATE": + handleChannelCreate(event); + break; + + case "CHANNEL_ANSWER": + handleChannelAnswer(event); + break; + + case "CHANNEL_HANGUP": + handleChannelHangup(event); + break; + + case "DTMF": + handleDtmf(event); + break; + + default: + log.trace("未处理的事件类型: {}", eventName); + break; + } + } + + /** + * 处理通道创建事件 + */ + private void handleChannelCreate(EslEvent event) { + String uuid = event.getEventHeaders().get("Unique-ID"); + String callerId = event.getEventHeaders().get("Caller-Caller-ID-Number"); + String destination = event.getEventHeaders().get("Caller-Destination-Number"); + + log.info("thingscloud - 通道创建: UUID {} 主叫 {} 被叫 {}", uuid, callerId, destination); + } + + /** + * 处理通道应答事件 + */ + private void handleChannelAnswer(EslEvent event) { + String uuid = event.getEventHeaders().get("Unique-ID"); + + log.info("thingscloud - 通道应答: UUID {}", uuid); + } + + /** + * 处理通道挂断事件 + */ + private void handleChannelHangup(EslEvent event) { + String uuid = event.getEventHeaders().get("Unique-ID"); + String hangupCause = event.getEventHeaders().get("Hangup-Cause"); + + log.info("thingscloud - 通道挂断: UUID {} 原因 {}", uuid, hangupCause); + } + + /** + * 处理DTMF按键事件 + */ + private void handleDtmf(EslEvent event) { + String uuid = event.getEventHeaders().get("Unique-ID"); + String digit = event.getEventHeaders().get("DTMF-Digit"); + + log.info("thingscloud - DTMF按键: UUID {} 键值 {}", uuid, digit); + } +}