EslInboundClientExample class.
27 | * 28 | * @author : zhouhailin 29 | * @version 1.0.0 30 | */ 31 | public class EslInboundClientExample { 32 | 33 | /** 34 | *main.
35 | * 36 | * @param args an array of {@link java.lang.String} objects. 37 | */ 38 | public static void main(String[] args) { 39 | InboundClientOption option = new InboundClientOption(); 40 | 41 | option.defaultPassword("ClueCon") 42 | .addServerOption(new ServerOption("172.16.44.246", 8021)); 43 | option.addEvents("all"); 44 | 45 | option.addListener(new IEslEventListener() { 46 | @Override 47 | public void eventReceived(String addr, EslEvent event) { 48 | System.out.println(addr); 49 | System.out.println(event); 50 | } 51 | 52 | @Override 53 | public void backgroundJobResultReceived(String addr, EslEvent event) { 54 | System.out.println(addr); 55 | System.out.println(event); 56 | } 57 | }); 58 | 59 | option.serverConnectionListener(new ServerConnectionListener() { 60 | @Override 61 | public void onOpened(ServerOption serverOption) { 62 | System.out.println("---onOpened--"); 63 | } 64 | 65 | @Override 66 | public void onClosed(ServerOption serverOption) { 67 | System.out.println("---onClosed--"); 68 | } 69 | }); 70 | 71 | InboundClient inboundClient = InboundClient.newInstance(option); 72 | 73 | inboundClient.start(); 74 | 75 | 76 | System.out.println(option.serverAddrOption().first()); 77 | System.out.println(option.serverAddrOption().last()); 78 | System.out.println(option.serverAddrOption().random()); 79 | 80 | 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 |FreeswitchEslSpringBootStarterExampleApplication class.
25 | * 26 | * @author zhouhl 27 | * @version 1.0.0 28 | */ 29 | @SpringBootApplication 30 | public class ExampleApplication { 31 | 32 | /** 33 | *main.
34 | * 35 | * @param args an array of {@link java.lang.String} objects. 36 | */ 37 | public static void main(String[] args) { 38 | SpringApplication.run(ExampleApplication.class, args); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter-example/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/example/ExampleInboundClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.example; 17 | 18 | import link.thingscloud.freeswitch.esl.InboundClient; 19 | import link.thingscloud.freeswitch.esl.InboundClientBootstrap; 20 | import lombok.extern.slf4j.Slf4j; 21 | import org.springframework.beans.factory.InitializingBean; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.stereotype.Component; 24 | 25 | /** 26 | * @author zhouhailin 27 | */ 28 | @Slf4j 29 | @Component 30 | public class ExampleInboundClient implements InitializingBean { 31 | @Autowired 32 | private InboundClient inboundClient; 33 | 34 | @Autowired 35 | private InboundClientBootstrap inboundClientBootstrap; 36 | 37 | @Override 38 | public void afterPropertiesSet() throws Exception { 39 | System.out.println(inboundClientBootstrap); 40 | } 41 | 42 | // public void hold() { 43 | // inboundClient.hold("", ""); 44 | // } 45 | // 46 | // public void record() { 47 | // inboundClient.record("", "", "", "", 1); 48 | // } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter-example/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/example/ExampleInboundClientOptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.example; 17 | 18 | import link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption; 19 | import link.thingscloud.freeswitch.esl.inbound.option.ServerOption; 20 | import link.thingscloud.freeswitch.esl.spring.boot.starter.handler.AbstractInboundClientOptionHandler; 21 | import lombok.extern.slf4j.Slf4j; 22 | import org.springframework.stereotype.Component; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | *ExampleInboundClientOptionHandler class.
28 | * 29 | * @author zhouhailin 30 | * @version 1.0.0 31 | */ 32 | @Slf4j 33 | @Component 34 | public class ExampleInboundClientOptionHandler extends AbstractInboundClientOptionHandler { 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | protected void intercept(InboundClientOption inboundClientOption) { 41 | ListHeartbeatEslEventHandler class.
27 | * 28 | * @author : zhouhailin 29 | * @version 1.0.0 30 | */ 31 | @Slf4j 32 | @Component 33 | @EslEventName(EventNames.HEARTBEAT) 34 | public class HeartbeatEslEventHandler implements EslEventHandler { 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public void handle(String addr, EslEvent event) { 40 | log.info("HeartbeatEslEventHandler handle addr[{}] EslEvent[{}].", addr, event); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter-example/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/example/ReScheduleEslEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.example; 17 | 18 | import link.thingscloud.freeswitch.esl.InboundClient; 19 | import link.thingscloud.freeswitch.esl.constant.EventNames; 20 | import link.thingscloud.freeswitch.esl.helper.EslHelper; 21 | import link.thingscloud.freeswitch.esl.spring.boot.starter.annotation.EslEventName; 22 | import link.thingscloud.freeswitch.esl.spring.boot.starter.handler.AbstractEslEventHandler; 23 | import link.thingscloud.freeswitch.esl.transport.event.EslEvent; 24 | import link.thingscloud.freeswitch.esl.transport.message.EslMessage; 25 | import lombok.extern.slf4j.Slf4j; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.stereotype.Component; 28 | 29 | /** 30 | *ReScheduleEslEventHandler class.
31 | * 32 | * @author : zhouhailin 33 | * @version 1.0.0 34 | */ 35 | @Slf4j 36 | @EslEventName(EventNames.RE_SCHEDULE) 37 | @Component 38 | public class ReScheduleEslEventHandler extends AbstractEslEventHandler { 39 | 40 | @Autowired 41 | private InboundClient inboundClient; 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public void handle(String addr, EslEvent event) { 48 | log.info("ReScheduleEslEventHandler handle addr[{}] EslEvent[{}].", addr, event); 49 | log.info("{}", inboundClient); 50 | EslMessage eslMessage = inboundClient.sendSyncApiCommand(addr, "version", null); 51 | log.info("{}", EslHelper.formatEslMessage(eslMessage)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter-example/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/example/ServerConnectionListenerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.example; 17 | 18 | import link.thingscloud.freeswitch.esl.ServerConnectionListener; 19 | import link.thingscloud.freeswitch.esl.inbound.option.ServerOption; 20 | import lombok.extern.slf4j.Slf4j; 21 | import org.springframework.stereotype.Service; 22 | 23 | /** 24 | *ServerConnectionListenerImpl class.
25 | * 26 | * @author : zhouhailin 27 | * @version 1.0.0 28 | */ 29 | @Slf4j 30 | @Service 31 | public class ServerConnectionListenerImpl implements ServerConnectionListener { 32 | /** 33 | * {@inheritDoc} 34 | */ 35 | @Override 36 | public void onOpened(ServerOption serverOption) { 37 | log.info("onOpened serverOption : {}", serverOption); 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public void onClosed(ServerOption serverOption) { 45 | log.info("onClosed serverOption : {}", serverOption); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter-example/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/example/controller/DemoController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.example.controller; 17 | 18 | import link.thingscloud.freeswitch.esl.InboundClient; 19 | import link.thingscloud.freeswitch.esl.inbound.option.ServerOption; 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.web.bind.annotation.GetMapping; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | /** 26 | *DemoController class.
27 | * 28 | * @author : zhouhailin 29 | * @version 1.0.0 30 | */ 31 | @RestController 32 | @RequestMapping("/demo") 33 | public class DemoController { 34 | 35 | @Autowired 36 | private InboundClient inboundClient; 37 | 38 | /** 39 | *demo.
40 | * 41 | * @return a {@link java.lang.String} object. 42 | */ 43 | @GetMapping("/demo") 44 | public String demo() { 45 | return "demo"; 46 | } 47 | 48 | /** 49 | *addServer1.
50 | * 51 | * @param host a {@link java.lang.String} object. 52 | * @param port a int. 53 | */ 54 | @GetMapping("/addServer1") 55 | public void addServer1(String host, int port) { 56 | InboundClient.getInstance().option().addServerOption(new ServerOption(host, port)); 57 | } 58 | 59 | /** 60 | *addServer2.
61 | * 62 | * @param host a {@link java.lang.String} object. 63 | * @param port a int. 64 | */ 65 | @GetMapping("/addServer2") 66 | public void addServer2(String host, int port) { 67 | inboundClient.option().addServerOption(new ServerOption(host, port)); 68 | } 69 | 70 | /** 71 | *removeServer1.
72 | */ 73 | @GetMapping("/removeServer1") 74 | public void removeServer1() { 75 | ServerOption serverOption = inboundClient.option().serverOptions().get(0); 76 | inboundClient.option().removeServerOption(serverOption); 77 | } 78 | 79 | /** 80 | *serverOptions.
81 | * 82 | * @return a {@link java.lang.String} object. 83 | */ 84 | @GetMapping("/serverOptions") 85 | public String serverOptions() { 86 | return inboundClient.option().serverOptions().toString(); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | link: 2 | thingscloud: 3 | freeswitch: 4 | esl: 5 | inbound: 6 | defaultPassword: ClueCon 7 | performance: false 8 | performanceCostTime: 200 9 | servers: 10 | - host: 172.16.44.246 11 | port: 8021 12 | timeoutSeconds: 5 13 | - host: 127.0.0.1 14 | port: 8021 15 | events: 16 | - all 17 | #logging: 18 | # level: 19 | # link: DEBUG 20 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter-example/src/test/java/link/thingscloud/freeswitch/esl/spring/boot/starter/example/ExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.example; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.springframework.boot.test.context.SpringBootTest; 21 | import org.springframework.test.context.junit4.SpringRunner; 22 | 23 | /** 24 | *ExampleApplicationTests class.
25 | * 26 | * @author zhouhailin 27 | * @version 1.0.0 28 | * @since 1.4.0.SNAPSHOT 29 | */ 30 | @RunWith(SpringRunner.class) 31 | @SpringBootTest 32 | public class ExampleApplicationTests { 33 | 34 | /** 35 | *contextLoads.
36 | */ 37 | @Test 38 | public void contextLoads() { 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 |EnableFreeswitchEslAutoConfiguration class.
25 | * 26 | * @author : zhouhailin 27 | * @version 1.0.0 28 | */ 29 | @Target({ElementType.TYPE}) 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Documented 32 | @Inherited 33 | @Import(FreeswitchEslAutoConfiguration.class) 34 | public @interface EnableFreeswitchEslAutoConfiguration { 35 | 36 | } 37 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/annotation/EslEventName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.annotation; 17 | 18 | import java.lang.annotation.*; 19 | 20 | /** 21 | *EslEventName class.
22 | * 23 | * @author : zhouhailin 24 | * @version 1.0.0 25 | */ 26 | @Target({ElementType.TYPE}) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface EslEventName { 30 | 31 | String[] value(); 32 | } 33 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/config/FreeswitchEslAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.config; 17 | 18 | import link.thingscloud.freeswitch.esl.IEslEventListener; 19 | import link.thingscloud.freeswitch.esl.InboundClient; 20 | import link.thingscloud.freeswitch.esl.InboundClientBootstrap; 21 | import link.thingscloud.freeswitch.esl.ServerConnectionListener; 22 | import link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption; 23 | import link.thingscloud.freeswitch.esl.spring.boot.starter.handler.InboundClientOptionHandler; 24 | import link.thingscloud.freeswitch.esl.spring.boot.starter.properties.InboundClientProperties; 25 | import link.thingscloud.freeswitch.esl.spring.boot.starter.template.DefaultInboundClientOptionHandlerTemplate; 26 | import link.thingscloud.freeswitch.esl.spring.boot.starter.template.IEslEventListenerTemplate; 27 | import link.thingscloud.freeswitch.esl.spring.boot.starter.template.ServerConnectionListenerTemplate; 28 | import lombok.extern.slf4j.Slf4j; 29 | import org.springframework.beans.factory.annotation.Autowired; 30 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 31 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 32 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 33 | import org.springframework.context.annotation.Bean; 34 | import org.springframework.context.annotation.Configuration; 35 | 36 | 37 | /** 38 | *FreeswitchEslAutoConfiguration class.
39 | * 40 | * @author : zhouhailin 41 | * @version 1.0.0 42 | */ 43 | @Slf4j 44 | @Configuration 45 | @EnableConfigurationProperties({InboundClientProperties.class}) 46 | @ConditionalOnClass(InboundClient.class) 47 | public class FreeswitchEslAutoConfiguration { 48 | 49 | /** 50 | *inboundClientPropertiesHandler.
51 | * 52 | * @return a {@link link.thingscloud.freeswitch.esl.spring.boot.starter.handler.InboundClientOptionHandler} object. 53 | */ 54 | @Bean 55 | @ConditionalOnMissingBean(InboundClientOptionHandler.class) 56 | public InboundClientOptionHandler inboundClientOptionHandler() { 57 | return new DefaultInboundClientOptionHandlerTemplate(); 58 | } 59 | 60 | /** 61 | *listener.
62 | * 63 | * @return a {@link link.thingscloud.freeswitch.esl.IEslEventListener} object. 64 | */ 65 | @Bean 66 | @ConditionalOnMissingBean(IEslEventListener.class) 67 | public IEslEventListener listener() { 68 | return new IEslEventListenerTemplate(); 69 | } 70 | 71 | /** 72 | *serverConnectionListener.
73 | * 74 | * @return a {@link link.thingscloud.freeswitch.esl.ServerConnectionListener} object. 75 | */ 76 | @Bean 77 | @ConditionalOnMissingBean(ServerConnectionListener.class) 78 | public ServerConnectionListener serverConnectionListener() { 79 | return new ServerConnectionListenerTemplate(); 80 | } 81 | 82 | /** 83 | *inboundClient.
84 | * 85 | * @param serverConnectionListener a {@link link.thingscloud.freeswitch.esl.ServerConnectionListener} object. 86 | * @param inboundClientOptionHandler a {@link link.thingscloud.freeswitch.esl.spring.boot.starter.handler.InboundClientOptionHandler} object. 87 | * @return a {@link link.thingscloud.freeswitch.esl.InboundClient} object. 88 | */ 89 | @Bean(initMethod = "start", destroyMethod = "shutdown") 90 | @ConditionalOnMissingBean(InboundClient.class) 91 | public InboundClient inboundClient(@Autowired ServerConnectionListener serverConnectionListener, @Autowired InboundClientOptionHandler inboundClientOptionHandler) { 92 | InboundClientOption option = inboundClientOptionHandler.getOption(); 93 | option.serverConnectionListener(serverConnectionListener); 94 | log.info("inboundClient properties : [{}]", option); 95 | log.info("inboundClient option : [{}]", option); 96 | return InboundClient.newInstance(option); 97 | } 98 | 99 | /** 100 | * InboundClient Bootstrap 101 | * 102 | * @param inboundClient a {@link link.thingscloud.freeswitch.esl.InboundClient} object. 103 | * @return a {@link link.thingscloud.freeswitch.esl.InboundClientBootstrap} object. 104 | */ 105 | @Bean 106 | @ConditionalOnMissingBean(InboundClientBootstrap.class) 107 | public InboundClientBootstrap inboundClientBootstrap(@Autowired InboundClient inboundClient) { 108 | return new InboundClientBootstrap(inboundClient); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/handler/AbstractEslEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.handler; 17 | 18 | import link.thingscloud.freeswitch.esl.InboundClient; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | 23 | /** 24 | *Abstract AbstractEslEventHandler class.
25 | * 26 | * @author : zhouhailin 27 | * @version 1.0.0 28 | */ 29 | public abstract class AbstractEslEventHandler implements EslEventHandler { 30 | 31 | @Autowired 32 | protected InboundClient inboundClient; 33 | 34 | protected final Logger log = LoggerFactory.getLogger(getClass()); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/handler/AbstractInboundClientOptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.handler; 17 | 18 | import link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption; 19 | import link.thingscloud.freeswitch.esl.inbound.option.ServerOption; 20 | import link.thingscloud.freeswitch.esl.spring.boot.starter.properties.InboundClientProperties; 21 | import link.thingscloud.freeswitch.esl.util.StringUtils; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | 24 | /** 25 | *Abstract AbstractInboundClientOptionHandler class.
26 | * 27 | * @author zhouhailin 28 | * @version 1.0.0 29 | */ 30 | public abstract class AbstractInboundClientOptionHandler implements InboundClientOptionHandler { 31 | 32 | @Autowired 33 | protected InboundClientProperties properties; 34 | 35 | /** 36 | *intercept.
37 | * 38 | * @param inboundClientOption a {@link link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption} object. 39 | */ 40 | protected abstract void intercept(InboundClientOption inboundClientOption); 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | @Override 46 | public InboundClientOption getOption() { 47 | InboundClientOption option = newInboundClientOption(); 48 | properties.getServers().forEach(server -> { 49 | if (StringUtils.isNotBlank(server.getHost()) && server.getPort() > 1) { 50 | option.addServerOption(new ServerOption(server.getHost(), server.getPort()) 51 | .timeoutSeconds(server.getTimeoutSeconds()) 52 | .password(server.getPassword())); 53 | } 54 | }); 55 | properties.getEvents().forEach(event -> { 56 | if (StringUtils.isNotBlank(event)) { 57 | option.addEvents(event); 58 | } 59 | }); 60 | intercept(option); 61 | return option; 62 | } 63 | 64 | /** 65 | *newInboundClientOption.
66 | * 67 | * @return a {@link link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption} object. 68 | */ 69 | protected InboundClientOption newInboundClientOption() { 70 | return new InboundClientOption().sndBufSize(properties.getSndBufSize()) 71 | .rcvBufSize(properties.getRcvBufSize()) 72 | .workerGroupThread(properties.getWorkerGroupThread()) 73 | .publicExecutorThread(properties.getPublicExecutorThread()) 74 | .privateExecutorThread(properties.getPrivateExecutorThread()) 75 | .callbackExecutorThread(properties.getCallbackExecutorThread()) 76 | .defaultTimeoutSeconds(properties.getDefaultTimeoutSeconds()) 77 | .readTimeoutSeconds(properties.getReadTimeoutSeconds()) 78 | .readerIdleTimeSeconds(properties.getReaderIdleTimeSeconds()) 79 | .defaultPassword(properties.getDefaultPassword()) 80 | .disablePublicExecutor(properties.isDisablePublicExecutor()) 81 | .performance(properties.isPerformance()) 82 | .performanceCostTime(properties.getPerformanceCostTime()) 83 | .eventPerformance(properties.isEventPerformance()) 84 | .eventPerformanceCostTime(properties.getEventPerformanceCostTime()); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/handler/DefaultEslEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.handler; 17 | 18 | import link.thingscloud.freeswitch.esl.helper.EslHelper; 19 | import link.thingscloud.freeswitch.esl.transport.event.EslEvent; 20 | 21 | /** 22 | *DefaultEslEventHandler class.
23 | * 24 | * @author : zhouhailin 25 | * @version 1.0.0 26 | */ 27 | public class DefaultEslEventHandler extends AbstractEslEventHandler { 28 | /** 29 | * {@inheritDoc} 30 | */ 31 | @Override 32 | public void handle(String addr, EslEvent event) { 33 | log.warn("Default esl event handler handle addr[{}], event[{}]", addr, EslHelper.formatEslEvent(event)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/handler/EslEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.handler; 17 | 18 | 19 | import link.thingscloud.freeswitch.esl.transport.event.EslEvent; 20 | 21 | /** 22 | *EslEventHandler interface.
23 | * 24 | * @author : zhouhailin 25 | * @version 1.0.0 26 | */ 27 | public interface EslEventHandler { 28 | 29 | /** 30 | * ConstantDEFAULT_ESL_EVENT_HANDLER="DEFAULT_ESL_EVENT_HANDLER"
31 | */
32 | String DEFAULT_ESL_EVENT_HANDLER = "DEFAULT_ESL_EVENT_HANDLER";
33 |
34 | /**
35 | * sub event key
36 | */
37 | String SUB_EVENT_HEADER_KEY = "Event-Subclass";
38 |
39 | /**
40 | * handle.
41 | * 42 | * @param addr a {@link java.lang.String} object. 43 | * @param event a {@link link.thingscloud.freeswitch.esl.transport.event.EslEvent} object. 44 | */ 45 | void handle(String addr, EslEvent event); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/handler/InboundClientOptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.handler; 17 | 18 | import link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption; 19 | 20 | /** 21 | *InboundClientOptionHandler interface.
22 | * 23 | * @author zhouhailin 24 | * @version 1.0.0 25 | */ 26 | public interface InboundClientOptionHandler { 27 | 28 | /** 29 | *getOption.
30 | * 31 | * @return a {@link link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption} object. 32 | */ 33 | InboundClientOption getOption(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/properties/InboundClientProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.properties; 17 | 18 | import lombok.Data; 19 | import org.springframework.boot.context.properties.ConfigurationProperties; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** 25 | *InboundClientProperties class.
26 | * 27 | * @author : zhouhailin 28 | * @version 1.0.0 29 | */ 30 | @Data 31 | @ConfigurationProperties(prefix = "link.thingscloud.freeswitch.esl.inbound") 32 | public class InboundClientProperties { 33 | 34 | private int sndBufSize = 65535; 35 | private int rcvBufSize = 65535; 36 | private int workerGroupThread = Runtime.getRuntime().availableProcessors() * 2; 37 | private int publicExecutorThread = Runtime.getRuntime().availableProcessors() * 2; 38 | private int privateExecutorThread = Runtime.getRuntime().availableProcessors() * 2; 39 | private int callbackExecutorThread = Runtime.getRuntime().availableProcessors() * 2; 40 | private int defaultTimeoutSeconds = 5; 41 | private int readTimeoutSeconds = 30; 42 | private int readerIdleTimeSeconds = 25; 43 | private String defaultPassword = "ClueCon"; 44 | private boolean disablePublicExecutor = false; 45 | private boolean performance = false; 46 | private long performanceCostTime = 200; 47 | private boolean eventPerformance = false; 48 | private long eventPerformanceCostTime = 200; 49 | private ListServerProperties class.
22 | * 23 | * @author : zhouhailin 24 | * @version 1.0.0 25 | */ 26 | @Data 27 | public class ServerProperties { 28 | private String host; 29 | private int port = 8021; 30 | private int timeoutSeconds; 31 | private String password; 32 | } 33 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/template/DefaultInboundClientOptionHandlerTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.template; 17 | 18 | import link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption; 19 | import link.thingscloud.freeswitch.esl.spring.boot.starter.handler.AbstractInboundClientOptionHandler; 20 | 21 | /** 22 | *DefaultInboundClientOptionHandlerTemplate class.
23 | * 24 | * @author zhouhailin 25 | * @version 1.0.0 26 | */ 27 | public class DefaultInboundClientOptionHandlerTemplate extends AbstractInboundClientOptionHandler { 28 | 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | protected void intercept(InboundClientOption option) { 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/java/link/thingscloud/freeswitch/esl/spring/boot/starter/template/IEslEventListenerTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.spring.boot.starter.template; 17 | 18 | import link.thingscloud.freeswitch.esl.IEslEventListener; 19 | import link.thingscloud.freeswitch.esl.InboundClient; 20 | import link.thingscloud.freeswitch.esl.spring.boot.starter.annotation.EslEventName; 21 | import link.thingscloud.freeswitch.esl.spring.boot.starter.handler.DefaultEslEventHandler; 22 | import link.thingscloud.freeswitch.esl.spring.boot.starter.handler.EslEventHandler; 23 | import link.thingscloud.freeswitch.esl.transport.event.EslEvent; 24 | import link.thingscloud.freeswitch.esl.util.ArrayUtils; 25 | import link.thingscloud.freeswitch.esl.util.StringUtils; 26 | import lombok.extern.slf4j.Slf4j; 27 | import org.springframework.beans.factory.InitializingBean; 28 | import org.springframework.beans.factory.annotation.Autowired; 29 | import org.springframework.util.CollectionUtils; 30 | 31 | import java.util.*; 32 | 33 | /** 34 | *IEslEventListenerTemplate class.
35 | * 36 | * @author : zhouhailin 37 | * @version 1.0.0 38 | */ 39 | @Slf4j 40 | public class IEslEventListenerTemplate implements IEslEventListener, InitializingBean { 41 | 42 | @Autowired 43 | private InboundClient inboundClient; 44 | @Autowired(required = false) 45 | private final ListServerConnectionListenerTemplate class.
24 | * 25 | * @author : zhouhailin 26 | * @version 1.0.0 27 | */ 28 | @Slf4j 29 | public class ServerConnectionListenerTemplate implements ServerConnectionListener { 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public void onOpened(ServerOption serverOption) { 35 | log.info("onOpened serverOption : {}", serverOption.host() + ":" + serverOption.port()); 36 | } 37 | 38 | /** 39 | * {@inheritDoc} 40 | */ 41 | @Override 42 | public void onClosed(ServerOption serverOption) { 43 | log.info("onClosed serverOption : {}", serverOption.host() + ":" + serverOption.port()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | link.thingscloud.freeswitch.esl.spring.boot.starter.config.FreeswitchEslAutoConfiguration 3 | -------------------------------------------------------------------------------- /freeswitch-esl-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | link.thingscloud.freeswitch.esl.spring.boot.starter.config.FreeswitchEslAutoConfiguration -------------------------------------------------------------------------------- /freeswitch-esl/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 |IEslEventListener interface.
22 | * 23 | * @author : zhouhailin 24 | * @version 1.0.0 25 | */ 26 | public interface IEslEventListener { 27 | 28 | /** 29 | * Signal of a server initiated event. 30 | * 31 | * @param addr addr 32 | * @param event as an {@link link.thingscloud.freeswitch.esl.transport.event.EslEvent} 33 | */ 34 | void eventReceived(String addr, EslEvent event); 35 | 36 | /** 37 | * Signal of an event containing the result of a client requested background job. The Job-UUID will 38 | * be available as an event header of that name. 39 | * 40 | * @param addr addr 41 | * @param event as an {@link link.thingscloud.freeswitch.esl.transport.event.EslEvent} 42 | */ 43 | void backgroundJobResultReceived(String addr, EslEvent event); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/InboundClientBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl; 17 | 18 | /** 19 | * @author zhouhailin 20 | * @since 2.1.0 21 | */ 22 | public class InboundClientBootstrap { 23 | 24 | private final InboundClient inboundClient; 25 | 26 | public InboundClientBootstrap(InboundClient inboundClient) { 27 | this.inboundClient = inboundClient; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/InboundClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl; 17 | 18 | import link.thingscloud.freeswitch.esl.exception.InboundClientException; 19 | import link.thingscloud.freeswitch.esl.inbound.NettyInboundClient; 20 | import link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption; 21 | 22 | /** 23 | * 保证单例对象 24 | * 25 | * @author : zhouhailin 26 | */ 27 | class InboundClientFactory { 28 | 29 | private InboundClient inboundClient = null; 30 | 31 | private InboundClientFactory() { 32 | } 33 | 34 | static InboundClientFactory getInstance() { 35 | return InboundClientFactoryInstance.INSTANCE; 36 | } 37 | 38 | synchronized InboundClient newInboundClient(InboundClientOption option) { 39 | if (inboundClient == null) { 40 | inboundClient = new NettyInboundClient(option == null ? new InboundClientOption() : option); 41 | return inboundClient; 42 | } 43 | throw new InboundClientException("InboundClient has been created already, instance : [" + inboundClient + "]!"); 44 | } 45 | 46 | InboundClient getInboundClient() { 47 | if (inboundClient == null) { 48 | throw new InboundClientException("InboundClient is null, you must be create it first."); 49 | } 50 | return inboundClient; 51 | } 52 | 53 | private static class InboundClientFactoryInstance { 54 | private static final InboundClientFactory INSTANCE = new InboundClientFactory(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/InboundClientService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl; 17 | 18 | /** 19 | *InboundClientService interface.
20 | * 21 | * @author : zhouhailin 22 | * @version 1.0.0 23 | */ 24 | public interface InboundClientService { 25 | 26 | /** 27 | *start.
28 | */ 29 | void start(); 30 | 31 | /** 32 | *shutdown.
33 | */ 34 | void shutdown(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/ServerConnectionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl; 17 | 18 | import link.thingscloud.freeswitch.esl.inbound.option.ServerOption; 19 | 20 | /** 21 | *ServerConnectionListener interface.
22 | * 23 | * @author : zhouhailin 24 | * @version 1.0.0 25 | */ 26 | public interface ServerConnectionListener { 27 | 28 | /** 29 | *onOpened.
30 | * 31 | * @param serverOption a {@link link.thingscloud.freeswitch.esl.inbound.option.ServerOption} object. 32 | */ 33 | void onOpened(ServerOption serverOption); 34 | 35 | /** 36 | *onClosed.
37 | * 38 | * @param serverOption a {@link link.thingscloud.freeswitch.esl.inbound.option.ServerOption} object. 39 | */ 40 | void onClosed(ServerOption serverOption); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/constant/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.constant; 17 | 18 | /** 19 | *EslConstant class.
20 | * 21 | * @author : zhouhailin 22 | * @version 1.0.0 23 | */ 24 | public class Constants { 25 | 26 | /** 27 | * ConstantBACKGROUND_JOB="BACKGROUND_JOB"
28 | */
29 | public static final String BACKGROUND_JOB = "BACKGROUND_JOB";
30 | /**
31 | * Constant PLAIN="plain"
32 | */
33 | public static final String PLAIN = "plain";
34 |
35 | public static final String SMF_ALEG = "aleg";
36 | public static final String SMF_BLEG = "bleg";
37 | public static final String SMF_HOLDB = "holdb";
38 | public static final String SMF_BOTH = "both";
39 |
40 | public static final String UUID_ANSWER = "uuid_answer";
41 | public static final String UUID_BRIDGE = "uuid_bridge";
42 | public static final String UUID_BROADCAST = "uuid_broadcast";
43 | public static final String UUID_BREAK = "uuid_break";
44 | public static final String UUID_HOLD = "uuid_hold";
45 | public static final String UUID_GETVAR = "uuid_getvar";
46 | public static final String UUID_SETVAR = "uuid_setvar";
47 | public static final String UUID_SETVAR_MULTI = "uuid_setvar_multi";
48 | public static final String UUID_RECORD = "uuid_record";
49 | public static final String UUID_TRANSFER = "uuid_transfer";
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/constant/VariableConstant.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | package link.thingscloud.freeswitch.esl.constant;
17 |
18 | /**
19 | * @author zhouhailin
20 | * @version 1.5.0
21 | */
22 | public class VariableConstant {
23 |
24 | public static final String PREFIX = "variable_";
25 |
26 | private VariableConstant() {
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/exception/EslDecoderException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | package link.thingscloud.freeswitch.esl.exception;
17 |
18 | /**
19 | * EslDecoderException class.
20 | * 21 | * @author : zhouhailin 22 | * @version 1.0.0 23 | */ 24 | public class EslDecoderException extends RuntimeException { 25 | /** 26 | *Constructor for EslDecoderException.
27 | * 28 | * @param message a {@link java.lang.String} object. 29 | */ 30 | public EslDecoderException(String message) { 31 | super(message); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/exception/InboundClientException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.exception; 17 | 18 | /** 19 | *InboundClientException class.
20 | * 21 | * @author : zhouhailin 22 | * @version 1.0.0 23 | */ 24 | public class InboundClientException extends RuntimeException { 25 | /** 26 | *Constructor for InboundClientException.
27 | * 28 | * @param message a {@link java.lang.String} object. 29 | */ 30 | public InboundClientException(String message) { 31 | super(message); 32 | } 33 | 34 | /** 35 | *Constructor for InboundClientException.
36 | * 37 | * @param message a {@link java.lang.String} object. 38 | * @param cause a {@link java.lang.Throwable} object. 39 | */ 40 | public InboundClientException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | /** 45 | *Constructor for InboundClientException.
46 | * 47 | * @param cause a {@link java.lang.Throwable} object. 48 | */ 49 | public InboundClientException(Throwable cause) { 50 | super(cause); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/exception/InboundTimeoutExcetion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.exception; 17 | 18 | /** 19 | *InboundTimeoutExcetion class.
20 | * 21 | * @author : zhouhailin 22 | * @version 1.0.0 23 | */ 24 | public class InboundTimeoutExcetion extends InboundClientException { 25 | /** 26 | *Constructor for InboundTimeoutExcetion.
27 | * 28 | * @param message a {@link java.lang.String} object. 29 | */ 30 | public InboundTimeoutExcetion(String message) { 31 | super(message); 32 | } 33 | 34 | /** 35 | *Constructor for InboundTimeoutExcetion.
36 | * 37 | * @param message a {@link java.lang.String} object. 38 | * @param cause a {@link java.lang.Throwable} object. 39 | */ 40 | public InboundTimeoutExcetion(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/helper/CommandHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.helper; 17 | 18 | /** 19 | * @author zhouhailin 20 | * @since 1.6.5 21 | */ 22 | public class CommandHelper { 23 | 24 | private final StringBuilder builder = new StringBuilder(); 25 | 26 | private CommandHelper(String cmd) { 27 | builder.append(cmd); 28 | } 29 | 30 | public static CommandHelper cmd(String cmd) { 31 | return new CommandHelper(cmd); 32 | } 33 | 34 | public CommandHelper arg(String arg) { 35 | builder.append(" ").append(arg); 36 | return this; 37 | } 38 | 39 | public CommandHelper arg(boolean arg) { 40 | builder.append(" ").append(arg); 41 | return this; 42 | } 43 | 44 | public CommandHelper arg(int arg) { 45 | builder.append(" ").append(arg); 46 | return this; 47 | } 48 | 49 | public CommandHelper arg(long arg) { 50 | builder.append(" ").append(arg); 51 | return this; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return builder.toString(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/helper/EslHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.helper; 17 | 18 | import link.thingscloud.freeswitch.esl.transport.event.EslEvent; 19 | import link.thingscloud.freeswitch.esl.transport.message.EslHeaders; 20 | import link.thingscloud.freeswitch.esl.transport.message.EslMessage; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | /** 26 | *EslHelper class.
27 | * 28 | * @author : zhouhailin 29 | * @version 1.0.0 30 | */ 31 | public class EslHelper { 32 | 33 | /** 34 | * private constructor 35 | */ 36 | private EslHelper() { 37 | } 38 | 39 | /** 40 | *formatEslEvent.
41 | * 42 | * @param event a {@link link.thingscloud.freeswitch.esl.transport.event.EslEvent} object. 43 | * @return a {@link java.lang.String} object. 44 | */ 45 | public static String formatEslEvent(EslEvent event) { 46 | 47 | StringBuilder sb = new StringBuilder(); 48 | 49 | sb.append(System.lineSeparator()); 50 | sb.append("#").append(System.lineSeparator()); 51 | sb.append("## message header : ").append(System.lineSeparator()); 52 | MapformatEslMessage.
78 | * 79 | * @param message a {@link link.thingscloud.freeswitch.esl.transport.message.EslMessage} object. 80 | * @return a {@link java.lang.String} object. 81 | */ 82 | public static String formatEslMessage(EslMessage message) { 83 | StringBuilder sb = new StringBuilder(); 84 | 85 | sb.append(System.lineSeparator()); 86 | sb.append("#").append(System.lineSeparator()); 87 | sb.append("## message header : ").append(System.lineSeparator()); 88 | 89 | MapNettyInboundClient class.
39 | * 40 | * @author : zhouhailin 41 | * @version 1.0.0 42 | */ 43 | public class NettyInboundClient extends AbstractInboundClient { 44 | 45 | private volatile boolean subscribeBackgroundJob = false; 46 | 47 | /** 48 | *Constructor for NettyInboundClient.
49 | * 50 | * @param option a {@link link.thingscloud.freeswitch.esl.inbound.option.InboundClientOption} object. 51 | */ 52 | public NettyInboundClient(InboundClientOption option) { 53 | super(option); 54 | } 55 | 56 | @Override 57 | public boolean subscribeBackgroundJob() { 58 | return subscribeBackgroundJob; 59 | } 60 | 61 | /** 62 | * {@inheritDoc} 63 | */ 64 | @Override 65 | public EslMessage sendSyncApiCommand(String addr, String command, String arg) { 66 | InboundChannelHandler handler = getAuthedHandler(addr); 67 | StringBuilder sb = new StringBuilder(); 68 | if (command != null && !command.isEmpty()) { 69 | sb.append("api "); 70 | sb.append(command); 71 | } 72 | if (arg != null && !arg.isEmpty()) { 73 | sb.append(' '); 74 | sb.append(arg); 75 | } 76 | log.debug("sendSyncApiCommand addr : {}, command : {}, arg : {}", addr, command, arg); 77 | return handler.sendSyncSingleLineCommand(sb.toString()); 78 | } 79 | 80 | /** 81 | * {@inheritDoc} 82 | */ 83 | @Override 84 | public EslMessage sendSyncApiCommand(String addr, String command, String arg, long timeoutSeconds) throws InboundTimeoutExcetion { 85 | try { 86 | return publicExecutor.submit(() -> sendSyncApiCommand(addr, command, arg)).get(timeoutSeconds, TimeUnit.SECONDS); 87 | } catch (Exception e) { 88 | throw new InboundTimeoutExcetion(String.format("sendSyncApiCommand addr : %s, command : %s, arg : %s, timeoutSeconds : %s", addr, command, arg, timeoutSeconds), e); 89 | } 90 | } 91 | 92 | /** 93 | * {@inheritDoc} 94 | */ 95 | @Override 96 | public void sendSyncApiCommand(String addr, String command, String arg, ConsumerChannelEventListener interface.
23 | * 24 | * @author : zhouhailin 25 | * @version 1.0.0 26 | */ 27 | public interface ChannelEventListener { 28 | 29 | /** 30 | *onChannelActive.
31 | * 32 | * @param remoteAddr a {@link java.lang.String} object. 33 | * @param inboundChannelHandler a {@link link.thingscloud.freeswitch.esl.inbound.handler.InboundChannelHandler} object. 34 | */ 35 | void onChannelActive(String remoteAddr, InboundChannelHandler inboundChannelHandler); 36 | 37 | /** 38 | *onChannelClosed.
39 | * 40 | * @param remoteAddr a {@link java.lang.String} object. 41 | */ 42 | void onChannelClosed(String remoteAddr); 43 | 44 | /** 45 | *handleAuthRequest.
46 | * 47 | * @param remoteAddr a {@link java.lang.String} object. 48 | * @param inboundChannelHandler a {@link link.thingscloud.freeswitch.esl.inbound.handler.InboundChannelHandler} object. 49 | */ 50 | void handleAuthRequest(String remoteAddr, InboundChannelHandler inboundChannelHandler); 51 | 52 | /** 53 | *handleEslEvent.
54 | * 55 | * @param remoteAddr a {@link java.lang.String} object. 56 | * @param event a {@link link.thingscloud.freeswitch.esl.transport.event.EslEvent} object. 57 | */ 58 | void handleEslEvent(String remoteAddr, EslEvent event); 59 | 60 | /** 61 | *handleDisconnectNotice.
62 | * 63 | * @param remoteAddr a {@link java.lang.String} object. 64 | */ 65 | void handleDisconnectNotice(String remoteAddr); 66 | 67 | /** 68 | *handleRudeRejection.
69 | * 70 | * @param remoteAddr a {@link java.lang.String} object. 71 | */ 72 | void handleRudeRejection(String remoteAddr); 73 | } 74 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/inbound/listener/EventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.inbound.listener; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | *EventListener interface.
22 | * 23 | * @author : zhouhailin 24 | * @version 1.0.0 25 | */ 26 | public interface EventListener { 27 | 28 | /** 29 | *addEvents.
30 | * 31 | * @param list a {@link java.util.List} object. 32 | */ 33 | void addEvents(ListcancelEvents.
37 | */ 38 | void cancelEvents(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/inbound/listener/ServerOptionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.inbound.listener; 17 | 18 | import link.thingscloud.freeswitch.esl.inbound.option.ServerOption; 19 | 20 | /** 21 | *ServerOptionListener interface.
22 | * 23 | * @author : zhouhailin 24 | * @version 1.0.0 25 | */ 26 | public interface ServerOptionListener { 27 | 28 | /** 29 | *onAdded.
30 | * 31 | * @param serverOption a {@link link.thingscloud.freeswitch.esl.inbound.option.ServerOption} object. 32 | */ 33 | void onAdded(ServerOption serverOption); 34 | 35 | /** 36 | *onRemoved.
37 | * 38 | * @param serverOption a {@link link.thingscloud.freeswitch.esl.inbound.option.ServerOption} object. 39 | */ 40 | void onRemoved(ServerOption serverOption); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/inbound/option/ConnectState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.inbound.option; 17 | 18 | /** 19 | *ConnectState class.
20 | * 21 | * @author : zhouhailin 22 | * @version 1.0.0 23 | */ 24 | public enum ConnectState { 25 | /** 26 | * 初始化状态 27 | */ 28 | INIT, 29 | /** 30 | * 正在连接 31 | */ 32 | CONNECTING, 33 | /** 34 | * 连接失败 35 | */ 36 | FAILED, 37 | /** 38 | * 连接成功 39 | */ 40 | CONNECTED, 41 | /** 42 | * 认证成功 43 | */ 44 | AUTHED, 45 | /** 46 | * 认证失败 47 | */ 48 | AUTHED_FAILED, 49 | /** 50 | * 正在关闭连接 51 | */ 52 | CLOSING, 53 | /** 54 | * 连接已关闭 55 | */ 56 | CLOSED, 57 | /** 58 | * 应用已停止 59 | */ 60 | SHUTDOWN 61 | } 62 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/inbound/option/ServerAddrOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.inbound.option; 17 | 18 | 19 | import link.thingscloud.freeswitch.esl.util.RandomUtils; 20 | import link.thingscloud.freeswitch.esl.util.Validate; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | *ServerAddrOption class.
26 | * 27 | * @author : zhouhailin 28 | * @version 1.0.0 29 | */ 30 | public class ServerAddrOption { 31 | private final Listfirst.
40 | * 41 | * @return a {@link java.lang.String} object. 42 | */ 43 | public String first() { 44 | Validate.notEmpty(serverOptions, VALIDATE_MESSAGE_1); 45 | return serverOptions.get(0).addr(); 46 | } 47 | 48 | /** 49 | *last.
50 | * 51 | * @return a {@link java.lang.String} object. 52 | */ 53 | public String last() { 54 | Validate.notEmpty(serverOptions, VALIDATE_MESSAGE_1); 55 | return serverOptions.get(serverOptions.size() - 1).addr(); 56 | } 57 | 58 | /** 59 | *random.
60 | * 61 | * @return a {@link java.lang.String} object. 62 | */ 63 | public String random() { 64 | Validate.notEmpty(serverOptions, VALIDATE_MESSAGE_1); 65 | return serverOptions.get(RandomUtils.nextInt(0, serverOptions.size())).addr(); 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/inbound/option/ServerOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.inbound.option; 17 | 18 | import lombok.Data; 19 | import lombok.experimental.Accessors; 20 | 21 | /** 22 | *ServerOption class.
23 | * 24 | * @author : zhouhailin 25 | * @version 1.0.0 26 | */ 27 | 28 | @Data 29 | @Accessors(fluent = true) 30 | public class ServerOption { 31 | private final String host; 32 | private final int port; 33 | private int timeoutSeconds; 34 | private String password; 35 | 36 | private ConnectState state = ConnectState.INIT; 37 | 38 | private int connectTimes = 0; 39 | 40 | /** 41 | *addr.
42 | * 43 | * @return a {@link java.lang.String} object. 44 | */ 45 | public String addr() { 46 | return host + ":" + port; 47 | } 48 | 49 | /** 50 | *addConnectTimes.
51 | */ 52 | public void addConnectTimes() { 53 | connectTimes++; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /freeswitch-esl/src/main/java/link/thingscloud/freeswitch/esl/transport/CommandResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package link.thingscloud.freeswitch.esl.transport; 17 | 18 | 19 | import link.thingscloud.freeswitch.esl.transport.message.EslHeaders; 20 | import link.thingscloud.freeswitch.esl.transport.message.EslMessage; 21 | 22 | /** 23 | *CommandResponse class.
24 | * 25 | * @author : zhouhailin 26 | * @version 1.0.0 27 | */ 28 | public class CommandResponse { 29 | 30 | private final String command; 31 | private final String replyText; 32 | private final EslMessage response; 33 | private final boolean success; 34 | 35 | /** 36 | *Constructor for CommandResponse.
37 | * 38 | * @param command a {@link java.lang.String} object. 39 | * @param response a {@link link.thingscloud.freeswitch.esl.transport.message.EslMessage} object. 40 | */ 41 | public CommandResponse(String command, EslMessage response) { 42 | this.command = command; 43 | this.response = response; 44 | this.replyText = response == null ? "" : response.getHeaderValue(EslHeaders.Name.REPLY_TEXT); 45 | this.success = replyText.startsWith("+OK"); 46 | } 47 | 48 | /** 49 | *Getter for the field command
.
isOk.
59 | * 60 | * @return true if and only if the response Reply-Text line starts with "+OK" 61 | */ 62 | public boolean isOk() { 63 | return success; 64 | } 65 | 66 | /** 67 | *Getter for the field replyText
.
Getter for the field response
.
SendEvent class.
23 | * 24 | * @author : zhouhailin 25 | * @version 1.0.0 26 | */ 27 | public class SendEvent { 28 | 29 | private final List45 | * name: value 46 | *47 | * 48 | * @param name part of line 49 | * @param value part of line 50 | * @return a {@link link.thingscloud.freeswitch.esl.transport.SendEvent} object. 51 | */ 52 | public SendEvent addLine(String name, String value) { 53 | msgLines.add(name + ": " + value); 54 | return this; 55 | } 56 | 57 | /** 58 | * A generic method to add a message line. The constructed line in the sent message will be in the 59 | * form: 60 | *
61 | * name: value 62 | *63 | * 64 | * @param line part of line 65 | */ 66 | public void addBody(String line) { 67 | msgLines.add(line); 68 | } 69 | 70 | /** 71 | * The list of strings that make up the message to send to FreeSWITCH. 72 | * 73 | * @return list of strings, as they were added to this message. 74 | */ 75 | public List
SendMsg class.
23 | * 24 | * @author : zhouhailin 25 | * @version 1.0.0 26 | */ 27 | public class SendMsg { 28 | 29 | private final List54 | * call-command: command 55 | *56 | * 57 | * @param command the string command [ execute | hangup ] 58 | * @return a {@link link.thingscloud.freeswitch.esl.transport.SendMsg} object. 59 | */ 60 | public SendMsg addCallCommand(String command) { 61 | msgLines.add("call-command: " + command); 62 | return this; 63 | } 64 | 65 | /** 66 | * Adds the following line to the message: 67 | *
68 | * execute-app-name: appName 69 | *70 | * 71 | * @param appName the string app name to execute 72 | * @return a {@link link.thingscloud.freeswitch.esl.transport.SendMsg} object. 73 | */ 74 | public SendMsg addExecuteAppName(String appName) { 75 | msgLines.add("execute-app-name: " + appName); 76 | return this; 77 | } 78 | 79 | /** 80 | * Adds the following line to the message: 81 | *
82 | * execute-app-arg: arg 83 | *84 | * 85 | * @param arg the string arg 86 | * @return a {@link link.thingscloud.freeswitch.esl.transport.SendMsg} object. 87 | */ 88 | public SendMsg addExecuteAppArg(String arg) { 89 | msgLines.add("execute-app-arg: " + arg); 90 | return this; 91 | } 92 | 93 | /** 94 | * Adds the following line to the message: 95 | *
96 | * loops: count 97 | *98 | * 99 | * @param count the int number of times to loop 100 | * @return a {@link link.thingscloud.freeswitch.esl.transport.SendMsg} object. 101 | */ 102 | public SendMsg addLoops(int count) { 103 | msgLines.add("loops: " + count); 104 | return this; 105 | } 106 | 107 | /** 108 | * Adds the following line to the message: 109 | *
110 | * hangup-cause: cause 111 | *112 | * 113 | * @param cause the string cause 114 | * @return a {@link link.thingscloud.freeswitch.esl.transport.SendMsg} object. 115 | */ 116 | public SendMsg addHangupCause(String cause) { 117 | msgLines.add("hangup-cause: " + cause); 118 | return this; 119 | } 120 | 121 | /** 122 | * Adds the following line to the message: 123 | *
124 | * nomedia-uid: value 125 | *126 | * 127 | * @param value the string value part of the line 128 | * @return a {@link link.thingscloud.freeswitch.esl.transport.SendMsg} object. 129 | */ 130 | public SendMsg addNomediaUuid(String value) { 131 | msgLines.add("nomedia-uuid: " + value); 132 | return this; 133 | } 134 | 135 | /** 136 | * Adds the following line to the message: 137 | *
138 | * event-lock: true 139 | *140 | * 141 | * @return a {@link link.thingscloud.freeswitch.esl.transport.SendMsg} object. 142 | */ 143 | public SendMsg addEventLock() { 144 | msgLines.add("event-lock: true"); 145 | return this; 146 | } 147 | 148 | /** 149 | * A generic method to add a message line. The constructed line in the sent message will be in the 150 | * form: 151 | *
152 | * name: value 153 | *154 | * 155 | * @param name part of line 156 | * @param value part of line 157 | * @return a {@link link.thingscloud.freeswitch.esl.transport.SendMsg} object. 158 | */ 159 | public SendMsg addGenericLine(String name, String value) { 160 | msgLines.add(name + ": " + value); 161 | return this; 162 | } 163 | 164 | /** 165 | * The list of strings that make up the message to send to FreeSWITCH. 166 | * 167 | * @return list of strings, as they were added to this message. 168 | */ 169 | public List
33 | * An ESL event is modelled as a collection of text lines. An event always has several eventHeader 34 | * lines, and optionally may have some eventBody lines. In addition the messageHeaders of the 35 | * original containing {@link link.thingscloud.freeswitch.esl.transport.message.EslMessage} which carried the event are also available. 36 | *
37 | * The eventHeader lines are parsed and cached in a map keyed by the eventHeader name string. An event 38 | * is always expected to have an "Event-Name" eventHeader. Commonly used eventHeader names are coded 39 | * in {@link link.thingscloud.freeswitch.esl.transport.event.EslEventHeaderNames} 40 | *
41 | * Any eventBody lines are cached in a list. 42 | *
43 | * The messageHeader lines from the original message are cached in a map keyed by {@link link.thingscloud.freeswitch.esl.transport.message.EslHeaders.Name}.
44 | *
45 | * @author : zhouhailin
46 | * @version 1.0.0
47 | * @see EslEventHeaderNames
48 | */
49 | @Slf4j
50 | public class EslEvent {
51 |
52 | private final Map Constructor for EslEvent. Constructor for EslEvent. EslEventHeaderNames class. EslFrameDecoder class. Constructor for EslFrameDecoder. Constructor for EslFrameDecoder.