{"id":18438243,"url":"https://github.com/easemob/livestream_demo_android","last_synced_at":"2025-04-07T20:35:15.765Z","repository":{"id":10568058,"uuid":"61516932","full_name":"easemob/livestream_demo_android","owner":"easemob","description":null,"archived":false,"fork":false,"pushed_at":"2023-02-09T04:11:22.000Z","size":145347,"stargazers_count":69,"open_issues_count":1,"forks_count":80,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-03-23T00:31:51.303Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/easemob.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-20T04:31:53.000Z","updated_at":"2024-09-18T03:21:50.000Z","dependencies_parsed_at":"2022-08-07T05:15:55.430Z","dependency_job_id":null,"html_url":"https://github.com/easemob/livestream_demo_android","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Flivestream_demo_android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Flivestream_demo_android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Flivestream_demo_android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Flivestream_demo_android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/easemob","download_url":"https://codeload.github.com/easemob/livestream_demo_android/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247726308,"owners_count":20985871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T06:19:14.744Z","updated_at":"2025-04-07T20:35:10.748Z","avatar_url":"https://github.com/easemob.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 环信直播聊天室简介\n\n## 简介\n\n**环信直播聊天室（以下简称直播聊天室）展示了环信 IM SDK直播聊天室的能力。除了提供基本的聊天外，还提供了赠送礼物的自定义消息，开发者可以根据自己的实际需求添加新的自定义消息。**\n\n**核心类介绍：**\n\n- CdnLiveAudienceActivity：观众直播间页面\u003c/br\u003e\n- CdnLiveHostActivity：主播直播页面\u003c/br\u003e\n- LiveAudienceFragment：集成观众端聊天室相关逻辑\u003c/br\u003e\n- LiveAnchorFragment：集成主播端聊天室相关逻辑\u003c/br\u003e\n\n**其他端开源地址：**\n\n- iOS:    https://github.com/AgoraIO-Usecase/AgoraChat-Livestream/tree/main/livestream-ios\n- Web:    https://github.com/AgoraIO-Usecase/AgoraChat-Livestream/tree/main/livestream-web\n- App Server:     https://github.com/AgoraIO-Usecase/AgoraChat-Livestream/tree/main/backend\n\n## 集成环信 Chat SDK\n\n### 开发环境要求\n\n- Android Studio 3.6或更高版本。\u003c/br\u003e\n- SDK targetVersion至少为26。\n\n### 添加远程依赖\n\n```\nimplementation 'io.hyphenate:hyphenate-chat:3.9.9'\nimplementation 'io.hyphenate:ease-im-kit:3.9.9'\n```\n可通过一下地址查看最新SDK版本号：\n- [hyphenate-chat](https://search.maven.org/search?q=g:io.hyphenate%20AND%20a:hyphenate-chat)；\u003c/br\u003e\n- [ease-im-kit](https://search.maven.org/search?q=g:io.hyphenate%20AND%20a:ease-im-kit)；\n\n**集成文档：**\u003c/br\u003e\n\n- [Android SDK 集成](http://docs-im-beta.easemob.com/document/android/quickstart.html)；\u003c/br\u003e\n- [Android UIKit 集成](http://docs-im-beta.easemob.com/document/android/easeimkit.html)；\n\n## 使用环信聊天室\n\n为方便开发者使用，项目中将聊天室相关逻辑放到了`chatroom` library 中，开发者可以根据自己的需求对这个库进行更改。\n\n### 核心类介绍\n\n- EaseChatRoomMessagesView：直播聊天室消息UI，用户可以自定义相关属性设置UI显示。\u003c/br\u003e\n- EaseLiveMessageHelper：用于监听接收自定义消息，发送自定义消息。\u003c/br\u003e\n- EaseLiveMessageType：用户定义了demo中用到的自定义消息类型（礼物消息）。\u003c/br\u003e\n- OnLiveMessageListener：监听聊天室消息接受相关事件。\n\n### 具体用法\n\n#### 1. 在聊天室加载后，进行初始化，设置房间信息。\n\n```Java\nEaseLiveMessageHelper.getInstance().init(chatroomId);\n```\n\n#### 2. 增加和取消聊天室自定义消息监听\n\n```Java\nEaseLiveMessageHelper.getInstance().addLiveMessageListener(new OnLiveMessageListener() {\n    @Override\n    public void onGiftMessageReceived(EMMessage message) {\n        \n    }\n});\nEaseLiveMessageHelper.getInstance().removeLiveMessageListener(this);\n```\n\n#### 3. 发送聊天室消息可以调用如下方法\n\n```Java\npublic void sendTxtMsg(String content, OnSendLiveMessageCallBack callBack);                                                       //文本消息\n\npublic void sendGiftMsg(String chatRoomId, String giftId, int num, OnSendLiveMessageCallBack callBack);                           //礼物消息\n\npublic void sendCustomMsg(String chatRoomId, String event, Map\u003cString, String\u003e params, final OnSendLiveMessageCallBack callBack); //自定义消息\n```\n\n#### 4. 解析消息相关参数\u003c/br\u003e\n\n（1）如果发送的自定义参数与library中相同，可以直接调用如下方法，获得所传的数据\n\n```Java\n//获取礼物消息中礼物的id\npublic String getMsgGiftId(EMMessage msg);\n//获取礼物消息中礼物的数量\npublic int getMsgGiftNum(EMMessage msg);\n```\n\n（2）如果自定义消息参数与library中不同，可以调用如下方法，获取消息中的参数\n\n```Java\npublic Map\u003cString, String\u003e getCustomMsgParams(EMMessage message);\n```\n\n#### 5. library中还提供了，判断自定义消息类型的方法\n\n```Java\npublic boolean isGiftMsg(EMMessage msg);    //礼物消息判断\n```\n\n## 环信直播聊天室架构介绍\n\n![](https://developer.android.google.cn/topic/libraries/architecture/images/final-architecture.png)\u003c/br\u003e\n环信聊天室中有两个repository，ClientRepository及AppServerRepository。其中ClientRepository用户处理环信 SDK提供\n的相关请求，AppServerRepository用户处理app server提供的接口。每个页面有相应的ViewModel以生命周期的方式存储和管\n理与UI相关的数据。LiveData是一个具有生命周期感知特性的可观察的数据保持类，一般位于ViewModel中，用于观察数据变化。\u003c/br\u003e\n\n## 集成Agora视频直播SDK\n\n环信聊天室提供了Agora CDN直播能力(https://docs.agora.io/cn/live-streaming/landing-page?platform=Android)。\n\n\n## 运行DEMO工程\n\n按照以下步骤运行示例项目：project:\\\n### 1. 克隆repo到本地。\n```java\n    git clone git@github.com:easemob/livestream_demo_android.git\n```\n\n### 2. 使用 Android Studio 打开 Android 项目(livestream_demo_android)。\n\n### 3. 配置APPKEY。\n在local.properties中配置 `CHAT_APPKEY` 和 `AGORA_APP_ID`，你可以在[开发者控制台](https://console.easemob.com/user/login/)申请相应的APPKEY。\n\n```Java\nCHAT_APPKEY=*******\n\nAGORA_APP_ID=*******\n```\n### 4. 使用AndroidStudio运行即可。\n\n## 文档\n\n- [iOS端开源地址](https://github.com/AgoraIO-Usecase/AgoraChat-Livestream/tree/main/livestream-ios)\n- [Web端开源地址](https://github.com/AgoraIO-Usecase/AgoraChat-Livestream/tree/main/livestream-web)\n- [App Server开源地址](https://github.com/AgoraIO-Usecase/AgoraChat-Livestream/tree/main/backend)\n- [Android SDK 集成](https://docs-preprod.agora.io/cn/agora-chat/enable_agora_chat?platform=Android)\u003c/br\u003e\n- [Android UIKit 集成](https://github.com/AgoraIO-Usecase/AgoraChat-UIKit-android)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasemob%2Flivestream_demo_android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feasemob%2Flivestream_demo_android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasemob%2Flivestream_demo_android/lists"}