当前位置:网站首页>Programmer Qixi Gift - How to quickly build an exclusive chat room for your girlfriend in 30 minutes
Programmer Qixi Gift - How to quickly build an exclusive chat room for your girlfriend in 30 minutes
2022-08-04 12:17:00 【ZEGO Instant Developer】
1 Language Chat Room Application Scenario Description
Are your Tanabata gifts ready??Programmer's Tanabata gift standard,Build an exclusive chat room for your girlfriend,Both romantic and hard nucleus!
Chat room is widely used in social scenes,社交APPRealization of the chat room scene in,主要由业务系统和移动/Web 客户端组成.Among them, the business system needs to realize the room management of the chat room、麦位管理、音频流和麦位关联关系管理等功能,The client needs to implement the login of the chat room/登出房间、拉流/停止拉流、上麦推流/Stop pushing down the mic等功能,You can also use the chat room room information channel to achieve as needed IM 功能.
1.1 Chat room business system function
chat room room management
Mainly responsible for the maintenance of the room list.
- 创建房间:用户登录业务系统后,可以创建房间,创建房间后房间列表要做新增操作.
- 销毁房间:After all users log out of the room,Need to destroy the room,销毁房间后房间列表要做删除操作.
Chat room management
Mainly responsible for defining the number of wheat slots in the room according to the business scenario,And the status management of all wheat positions in the current room.
- 用户进入房间后,只有空闲状态的麦位可以上麦.
- 用户上麦后,需要修改麦位状态为非空闲状态.
- After the user stops pushing and downloading the microphone,To reset the wheat level status.
Voice chat room audio stream management
Mainly responsible for managing the relationship between the audio stream and the microphone level in the room.
- Only the current room can pull the idle state of a flow.
1.2 Chat room client function
Chat room login/登出房间
- 用户进入客户端后,Select a room from the room list or create your own,然后登录房间.
- When the user exits the current chat room,Need to log out of room.
chat room pull flow/停止拉流
- After the user logs in to the room or receives a stream new message,need according to the flow Id Determine whether it is the stream pushed by the microphone in the non-idle state of the room,If so, initiate a pull stream.
- Before the user receives a stream deletion message or logs out of the room,to stop pulling.
语聊房SDK上麦推流/Stop pushing down the mic
- After the user logs into the room,If there is a non-idle wheat bit,Optional wheat.
- The user successfully launched the push stream on the microphone,Become a Maishang user.
- The user downloads the microphone after the user stops pushing the stream,成为观众.
Chat room signaling interaction
- Users can pass the room signaling channel,Send text messages to engage.
2 使用ZEGO SDKChat room implementation process
The following figure is the sequence diagram of the chat room implementation,Developers can refer to the sequence diagram to implement the business.
2.1 用户 A 创建房间
Call the business system to create a room interface to create a room,After the room is created successfully, the business system needs to return the currently created room ID.
2.2 用户 A Login to Business Room
Call the business system login room interface to log in to the room,Business system needs to be updated room list after a successful login,And return the room wheat level information list,The wheat level information needs to include the wheat level Id、Is it idle, etc..
2.3 用户 B 查询房间列表
Call the business system to get the room list information interface to get the room list,After the call is successful, the business system needs to return the current room information list,Room information needs to include the room ID 等.
2.4 用户 B Login to Business Room
Use the business system login room interface to log in to the room,Business system needs to be updated room list after a successful login,And return the room wheat level information list,The wheat level information needs to include the wheat level Id、Is it idle, etc..
2.5 用户 A 登录 SDK 房间
依次调用 Express Audio SDK 的初始化 SDK 接口、Set event callback interface、Login interface room,登录 SDK 房间,登录成功后,will receive the room stream update callback.
2.6 用户 A 上麦推流
Select the idle microphone position to call the microphone interface of the business system to load the microphone,The business system updates the wheat position to a non-idle state,And return the result information of the wheat,The wheat loading result information needs to include the wheat level used Id、Push stream allocated for wheat bits Id 等信息.After receiving the request and returning the data,According to the returned push ID 调用 Express Audio SDK The push interface starts to push the stream,After pushing the stream, you will receive the push stream result callback.
2.7 用户 B 登录 SDK 房间
依次调用 Express Audio SDK 的初始化 SDK 接口、Set event callback interface、Login interface room,登录 SDK 房间,登录成功后,will receive the room stream update callback.
2.8 用户 B 收到 Express Audio SDK Stream update callback pull stream
登录 SDK 房间成功后,will receive the room stream update callback,If it is a stream added,Call the business system query interface query flow ID Whether it is the push stream allocated for the current room's mic position ID,如果是则调用 Express Audio SDK Pull flow interface pull flow.
2.9 用户 B 上麦推流
Select the idle microphone position to call the microphone interface of the business system to load the microphone,The business system updates the wheat position to a non-idle state,And return the result information of the wheat,The wheat loading result information needs to include the wheat level used Id、Push stream allocated for wheat bits Id 等信息.After receiving the request and returning the data,According to the returned push ID 调用 Express Audio SDK The push interface starts to push the stream,After pushing the stream, you will receive the push stream result callback.
2.10 用户 A 收到 Express Audio SDK Stream update callback pull stream
登录 SDK 房间成功后,will receive the room stream update callback,If it is a stream added,Call the business system query interface query flow ID Whether it is the push stream allocated for the current room's mic position ID,如果是则调用 Express Audio SDK Pull flow interface pull flow.
2.11 用户 A Stop streaming after requesting the microphone
Call the microphone interface of the business system to download the microphone,The business system updates the wheat bit to an idle state,The user becomes an offline audience after successfully placing the microphone,停止推流.
2.12 停止拉流、登出房间
调用 Express Audio SDK Stop pulling streams The interface stops pulling all the streams that are being pulled、Call the logout room interface to logout SDK 房间.
2.13 Log out of business room
Call the business system logout room interface to log out of the business room.
3 语聊房SDK操作步骤
3.1 创建/销毁 Engine
在使用 Express Audio SDK 之前,需要初始化 Express Audio SDK.由于初始化操作 SDK 内部处理的流程较多,建议开发者在 App 启动时进行,详情请参考 快速开始 - 实现流程 的 “2.1 创建引擎”.
/** 定义 SDK 引擎对象 */
ZegoExpressEngine engine;
ZegoEngineProfile profile = new ZegoEngineProfile();
/** 请通过官网注册获取,格式为 123456789L */
profile.appID = appID;
/** 64个字符,请通过官网注册获取,格式为"0123456789012345678901234567890123456789012345678901234567890123" */
profile.appSign = appSign;
/** 通用场景接入 */
profile.scenario = ZegoScenario.GENERAL;
/** 设置app的application 对象 */
profile.application = getApplication();
/** 创建引擎 */
engine = ZegoExpressEngine.createEngine(profile, null);
/** 销毁 SDK */
ZegoExpressEngine.destroyEngine(null);
3.2 设置事件回调
可以根据场景需要,在初始化 SDK 后监听想要关注的事件通知,比如用户加入房间,房间流更新等等.
// 设置事件回调,Listen for room stream updates
engine.setEventHandler(new IZegoEventHandler() {
@Override
public void onRoomStreamUpdate(String roomID, ZegoUpdateType updateType, ArrayList<ZegoStream> streamList) {
super.onRoomStreamUpdate(roomID, updateType, streamList);
if (ZegoUpdateType.ADD == updateType) {
// 流新增
} else if (ZegoUpdateType.DELETE == updateType) {
// 流删除
}
}
});
3.3 登录/logout chat room
用户上麦推流之前,需要先登录房间,在收到登录房间成功的回调后可以直接调用 loginRoom 接口进行推拉流操作,详情请参考 快速开始 - 实现流程 的 “2.2 登录房间”.
/** 创建用户 */
ZegoUser user = new ZegoUser("Anchor1");
/** 开始登陆房间 */
engine.loginRoom("LiveRoom", user);
/** 登出房间 */
engine.logoutRoom("room1");
3.4 Chat room starts/停止推流
调用 startPublishingStream 接口,可以向远端用户发送本端的音视频流.如果不需要继续推流,请调用 stopPublishingStream 停止推流,详情请参考 快速开始 - 实现流程 的 “2.3 推流”.
/** 开始推流 */
engine.startPublishingStream("stream1");
/** 停止推流 */
engine.stopPublishingStream();
3.5 chat room pull flow/停止拉流
调用 startPlayingStream 进行拉流,如果不需要继续拉流,请调用 stopPlayingStream 停止拉流,详情请参考 快速开始 - 实现流程 的 “2.4 拉流”.
/** * 开始拉流 */
engine.startPlayingStream("stream1");
/** 停止拉流 */
engine.stopPlayingStream(streamID);
Get chat roomSDK更多帮助
你学会了吗?
Get the chat room of this articleDemo、开发文档、技术支持,访问即构文档中心
近期有开发规划的开发者可上即构官网查看,恰逢即构七周年全线音视频产品1折的优惠,联系商务获取RTC产品优惠;
边栏推荐
猜你喜欢
【VBox】解决复制VBox虚拟机后提示硬盘UUID 已经存在的问题
聪明的儿子处理婆媳关系的方法(处理婆媳关系的方法)
Leetcode brush - structure binary tree (105. Once upon a time sequence and the sequence structure binary tree traversal sequence, 106. From the sequence with the sequence structure binary tree travers
深度学习------pytorch实现划拳模型训练
yolo系列的Neck模块
Based on the BiLSTM regression forecast method
划重点!2022面试必刷461道大厂架构面试真题汇总+面经+简历模板
涨姿势了!原来这才是多线程正确实现方式
244 page PDF!"2022 China cloud computing ecological blue book published
BOSS直聘回应女大学生连遭两次性骚扰:高度重视求职者安全 可通过App等举报
随机推荐
Rust 从入门到精通04-变量
表的完整性约束;非外键约束
MySQL - Explain详解
shell之循环语句(for、while、until)
节流函数(每隔一段时间就会执行一次)
深度学习------pytorch-gpu环境搭建
外置USB供电与内置锂电池供电自动切换电路
分布式链路追踪Jaeger + 微服务Pig在Rainbond上的实践分享
简要介绍电源效率测试
backbone核心详解系列——RepVGG
matlab串口读写
项目管理前景
今天15:00 | CVPR 2022 论文分享精彩继续
微信服务号调用API实现微信报警
聪明的儿子处理婆媳关系的方法(处理婆媳关系的方法)
企业应当实施的5个云安全管理策略
Redis (1) installation and configuration
Share | technology integration electronic fence function of scheduling system
UMA & Hong Kong Polytechnic & Ali propose SP-ViT to learn 2D space prior knowledge for visual Transformer!
记我的第一篇CCF-A会议论文|在经历六次被拒之后,我的论文终于中啦,耶!