[+] 终端
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.acgist</groupId>
|
||||
<artifactId>taoyao-boot</artifactId>
|
||||
<artifactId>taoyao-media</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.acgist.taoyao.signal.config;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||
|
||||
import com.acgist.taoyao.signal.session.websocket.WebSocketSignal;
|
||||
@@ -13,6 +14,7 @@ import com.acgist.taoyao.signal.session.websocket.WebSocketSignal;
|
||||
* @author acgist
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebSocket
|
||||
public class SignalAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -9,22 +9,30 @@ public interface ClientMediaHandler {
|
||||
|
||||
/**
|
||||
* 打开
|
||||
*
|
||||
* @param id 终端媒体流ID
|
||||
*/
|
||||
void open(String id);
|
||||
|
||||
/**
|
||||
* 暂停
|
||||
*
|
||||
* @param id 终端媒体流ID
|
||||
*/
|
||||
void pause();
|
||||
void pause(String id);
|
||||
|
||||
/**
|
||||
* 恢复
|
||||
*
|
||||
* @param id 终端媒体流ID
|
||||
*/
|
||||
void resume();
|
||||
void resume(String id);
|
||||
|
||||
/**
|
||||
* 关闭
|
||||
*
|
||||
* @param id 终端媒体流ID
|
||||
*/
|
||||
void close();
|
||||
void close(String id);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,81 @@
|
||||
package com.acgist.taoyao.signal.media;
|
||||
|
||||
/**
|
||||
* 终端推流
|
||||
*/
|
||||
public class ClientMediaPublisher {
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.acgist.taoyao.signal.media.stream.ClientMediaStream;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 终端媒体流发布者(终端推流)
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientMediaPublisher implements ClientMediaHandler {
|
||||
|
||||
/**
|
||||
* 发布终端媒体流
|
||||
*/
|
||||
private Map<String, ClientMediaStream> streams = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* 发布
|
||||
*
|
||||
* @param id 终端媒体流ID
|
||||
*
|
||||
* @see #open(String)
|
||||
*/
|
||||
public void publish(String id) {
|
||||
this.open(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消发布
|
||||
*
|
||||
* @param id 终端媒体流ID
|
||||
*
|
||||
* @see #close(String)
|
||||
*/
|
||||
public void unpublish(String id) {
|
||||
this.close(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(String id) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause(String id) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume(String id) {
|
||||
final ClientMediaStream stream = this.streams.get(id);
|
||||
if(stream != null) {
|
||||
try {
|
||||
stream.resume();
|
||||
} catch (IOException e) {
|
||||
log.error("终端媒体流恢复异常:{}", id, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(String id) {
|
||||
final ClientMediaStream stream = this.streams.get(id);
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
log.error("终端媒体流关闭异常:{}", id, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.acgist.taoyao.signal.media;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.acgist.taoyao.signal.media.stream.ClientMediaStream;
|
||||
|
||||
/**
|
||||
* 终端媒体订阅者(终端拉流)
|
||||
*
|
||||
@@ -7,10 +12,31 @@ package com.acgist.taoyao.signal.media;
|
||||
*/
|
||||
public class ClientMediaSubscriber implements ClientMediaHandler {
|
||||
|
||||
/**
|
||||
* 订阅终端媒体流
|
||||
*/
|
||||
private List<ClientMediaStream> streams = new CopyOnWriteArrayList<>();
|
||||
|
||||
/**
|
||||
* 订阅
|
||||
*
|
||||
* @param id 终端媒体流ID
|
||||
*
|
||||
* @see #open(String)
|
||||
*/
|
||||
public void subscribe(String id) {
|
||||
this.open(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订阅
|
||||
*
|
||||
* @param id 终端媒体流ID
|
||||
*
|
||||
* @see #close(String)
|
||||
*/
|
||||
public void unsubscribe(String id) {
|
||||
this.close(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -20,19 +46,19 @@ public class ClientMediaSubscriber implements ClientMediaHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
public void pause(String id) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
public void resume(String id) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
public void close(String id) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.acgist.taoyao.signal.media.stream;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 终端媒体流
|
||||
*
|
||||
@@ -58,23 +60,31 @@ public interface ClientMediaStream {
|
||||
|
||||
/**
|
||||
* 打开终端媒体流
|
||||
*
|
||||
* @throws IO异常
|
||||
*/
|
||||
void open();
|
||||
void open() throws IOException;
|
||||
|
||||
/**
|
||||
* 暂停终端媒体流
|
||||
*
|
||||
* @throws IO异常
|
||||
*/
|
||||
void pause();
|
||||
void pause() throws IOException;
|
||||
|
||||
/**
|
||||
* 恢复终端媒体流
|
||||
*
|
||||
* @throws IO异常
|
||||
*/
|
||||
void resume();
|
||||
void resume() throws IOException;
|
||||
|
||||
/**
|
||||
* 关闭终端媒体流
|
||||
*
|
||||
* @throws IO异常
|
||||
*/
|
||||
void close();
|
||||
void close() throws IOException;
|
||||
|
||||
/**
|
||||
* @return 终端媒体流类型
|
||||
|
||||
Reference in New Issue
Block a user