[*] mesh
This commit is contained in:
@@ -5,7 +5,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.acgist.taoyao.webrtc.mesh.listener.MediaAnswerListener;
|
||||
import com.acgist.taoyao.webrtc.mesh.listener.MediaCandidateListener;
|
||||
import com.acgist.taoyao.webrtc.mesh.listener.MediaOfferListener;
|
||||
import com.acgist.taoyao.webrtc.mesh.listener.MediaPublishListener;
|
||||
import com.acgist.taoyao.webrtc.mesh.listener.MediaSubscribeListener;
|
||||
|
||||
@@ -30,6 +32,18 @@ public class MeshAutoConfiguration {
|
||||
return new MediaSubscribeListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MediaOfferListener mediaOfferListener() {
|
||||
return new MediaOfferListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MediaAnswerListener mediaAnswerListener() {
|
||||
return new MediaAnswerListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MediaCandidateListener mediaCandidateListener() {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.acgist.taoyao.webrtc.mesh.listener;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.signal.event.media.MediaAnswerEvent;
|
||||
import com.acgist.taoyao.signal.listener.MediaListenerAdapter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Answer监听
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
public class MediaAnswerListener extends MediaListenerAdapter<MediaAnswerEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(MediaAnswerEvent event) {
|
||||
final String sn = event.getSn();
|
||||
final String to = event.getTo();
|
||||
if(sn.equals(to)) {
|
||||
log.debug("忽略Answer消息(相同终端):{}-{}", sn, to);
|
||||
return;
|
||||
}
|
||||
final Message message = event.getMessage();
|
||||
final Map<String, Object> mergeBody = event.mergeBody();
|
||||
mergeBody.put("from", sn);
|
||||
this.clientSessionManager.unicast(to, message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +1,33 @@
|
||||
package com.acgist.taoyao.webrtc.mesh.listener;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.signal.event.media.MediaCandidateEvent;
|
||||
import com.acgist.taoyao.signal.listener.MediaListenerAdapter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 候选监听
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
public class MediaCandidateListener extends MediaListenerAdapter<MediaCandidateEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(MediaCandidateEvent event) {
|
||||
final String sn = event.getSn();
|
||||
final List<String> sns = event.getSns();
|
||||
if(CollectionUtils.isEmpty(sns)) {
|
||||
final String to = event.getTo();
|
||||
if(sn.equals(to)) {
|
||||
log.debug("忽略候选消息(相同终端):{}-{}", sn, to);
|
||||
return;
|
||||
}
|
||||
final Message message = event.getMessage();
|
||||
final Map<String, Object> mergeBody = event.mergeBody();
|
||||
mergeBody.put("from", sn);
|
||||
sns.forEach(to -> this.clientSessionManager.unicast(to, message));
|
||||
this.clientSessionManager.unicast(to, message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.acgist.taoyao.webrtc.mesh.listener;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.signal.event.media.MediaOfferEvent;
|
||||
import com.acgist.taoyao.signal.listener.MediaListenerAdapter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Offer监听
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
public class MediaOfferListener extends MediaListenerAdapter<MediaOfferEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(MediaOfferEvent event) {
|
||||
final String sn = event.getSn();
|
||||
final String to = event.getTo();
|
||||
if(sn.equals(to)) {
|
||||
log.debug("忽略Offer消息(相同终端):{}-{}", sn, to);
|
||||
return;
|
||||
}
|
||||
final Message message = event.getMessage();
|
||||
final Map<String, Object> mergeBody = event.mergeBody();
|
||||
mergeBody.put("from", sn);
|
||||
this.clientSessionManager.unicast(to, message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,17 +6,24 @@ import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.signal.event.media.MediaPublishEvent;
|
||||
import com.acgist.taoyao.signal.listener.MediaListenerAdapter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 发布监听
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
public class MediaPublishListener extends MediaListenerAdapter<MediaPublishEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(MediaPublishEvent event) {
|
||||
final String sn = event.getSn();
|
||||
final String to = event.getTo();
|
||||
if(sn.equals(to)) {
|
||||
log.debug("忽略发布消息(相同终端):{}-{}", sn, to);
|
||||
return;
|
||||
}
|
||||
final Message message = event.getMessage();
|
||||
final Map<String, Object> mergeBody = event.mergeBody();
|
||||
mergeBody.put("from", sn);
|
||||
|
||||
@@ -6,17 +6,24 @@ import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.signal.event.media.MediaSubscribeEvent;
|
||||
import com.acgist.taoyao.signal.listener.MediaListenerAdapter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 订阅监听
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
public class MediaSubscribeListener extends MediaListenerAdapter<MediaSubscribeEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(MediaSubscribeEvent event) {
|
||||
final String sn = event.getSn();
|
||||
final String to = event.getTo();
|
||||
if(sn.equals(to)) {
|
||||
log.debug("忽略订阅消息(相同终端):{}-{}", sn, to);
|
||||
return;
|
||||
}
|
||||
final Message message = event.getMessage();
|
||||
final Map<String, Object> mergeBody = event.mergeBody();
|
||||
mergeBody.put("from", sn);
|
||||
|
||||
Reference in New Issue
Block a user