语音房开发手帐

云信sdk

网易云信开源clubhouse复刻 源代码,免费下载。新闻宣传页:https://c.m.163.com/news/a/G22VVED50534B9EW.html
轻松复刻本土Clubhouse,产品源码全开放,1天上线,领衔语音社交热潮!
基于网易云信新一代(G2)实时音视频SDK的多人语音聊天室Demo,包含了实时音频通话、互动连麦、麦位控制等功能,完全满足Clubhouse这类语音社交产品的需求。
Demo地址:https://github.com/netease-im/NEChatroom

语音房开发

有一份语音房云信接入的业务文档,记录了关于客户端,服务端,云信,三方的数据交互,存于我的的云笔记。

客户端语音数据流传递

  1. GlChatSocketClient 的onMessage方法接收到语音指令消息,消息解析成语音指令实体VoiceCommandEntity
  2. 执行VoiceService的notifyCommand(VoiceCommandEntity code),添加被观察对象。
public class VoiceService extends BaseService {
    
    private List> commandList = new ArrayList<>();
    
    public void observeCommand(Observer pStatusCodeObserver, boolean reg) {
        addOrRemoveObserver(commandList, pStatusCodeObserver, reg);
    }

    public void notifyCommand(VoiceCommandEntity code) {
        notifyObserver(commandList, code);
    }
    ...
}

public abstract class BaseService {

    public  void addOrRemoveObserver(List pList, T pO, boolean flag){
        ListUtils.addOrRemove(pList,pO,flag);
    }
    
    protected   void notifyObserver(List> pTList, T po){
        if(pTList==null || pTList.size()==0){
            return;
        }
        Rx2Creator.createObservableTask(new Callable() {
            @Override
            public Object call() throws Exception {
                for (Observer t:pTList){
                    t.onEvent(po);
                }
                return null;
            }
        }, AndroidSchedulers.mainThread());

    }
...
}

 
 
  1. 语音指令有:申请举手、邀请举手、解散房间、语音房麦克风状态变更、主持人变更、移除成员、离开房间等。语音房间页面和悬浮球等处调用VoiceService的observeCommand方法,添加观察对象,实时更新页面状态。

好友在线状态更新

好友列表的在线状态更新是定时刷接口实现的:

public void start() {
        if (!isStop.get()) {
            return;
        }
        isStop.set(false);
        if (readUidList().isEmpty()) {
            return;
        }
        mQueryStatusDisposable = Observable.interval(0, 120, TimeUnit.SECONDS)
                .takeWhile(new Predicate() {
                    @Override
                    public boolean test(@NonNull Long aLong) throws Exception {
                        return !isStop.get();
                    }
                })
                .flatMap(new Function>>>>() {
                    @Override
                    public ObservableSource>>> apply(@NonNull Long aLong) throws Exception {
                        LogUtil.d(TAG, "start");
                        List uidList = readUidList();
                        if (!uidList.isEmpty()) {
                            return uInfoRepo.getActiveInfo(uidList);
                        } else {
                            return Observable.just(new GLResult<>(GLProtoResult.SUCCESS, new Pair<>(ActiveInfoEntity.Switch.OFF, new ArrayList<>())));
                        }
                    }
                })
                .compose(Rx2Schedulers.observableNewThreadToMain())
                .subscribe(new Consumer>>>() {
                    @Override
                    public void accept(GLResult>> result) throws Exception {
                        if (result.isSuccess()) {
                            exposedActiveInfo.postValue(result.getSpecific().second);
                            if (TextUtils.equals(ActiveInfoEntity.Switch.OFF, result.getSpecific().first)) {
                                stop();
                            }
                        }
                    }
                }, new Consumer() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                });
    }

语音悬浮球实现

device-2021-03-29-211137.png

效果是:拖拽移动,放手自动吸附屏幕边缘
代码先存,有空更..


IMG20210329_211820.png

你可能感兴趣的:(语音房开发手帐)