{"id":18438204,"url":"https://github.com/easemob/livestream_demo_miniprogram","last_synced_at":"2025-04-14T13:15:45.673Z","repository":{"id":137874775,"uuid":"256386822","full_name":"easemob/livestream_demo_miniprogram","owner":"easemob","description":null,"archived":false,"fork":false,"pushed_at":"2020-12-01T10:33:45.000Z","size":733,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-14T13:15:45.484Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-17T03:01:11.000Z","updated_at":"2021-07-26T06:56:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"c5aa0218-6c0b-4df5-be1b-8d7197b7210c","html_url":"https://github.com/easemob/livestream_demo_miniprogram","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Flivestream_demo_miniprogram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Flivestream_demo_miniprogram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Flivestream_demo_miniprogram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Flivestream_demo_miniprogram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/easemob","download_url":"https://codeload.github.com/easemob/livestream_demo_miniprogram/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248886343,"owners_count":21177645,"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:02.230Z","updated_at":"2025-04-14T13:15:45.571Z","avatar_url":"https://github.com/easemob.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 环信--小程序直播聊天室\n# 介绍\n******\n环信直播小程序demo是基于环信im SDK开发的一款直播小程序。这个demo可以帮助开发者们更轻松的集成环信SDK。\ndemo 包含以下功能\n  - 主播开播、下播\n  - 直播间聊天系统\n  - 点赞、礼物系统（示例不包含api）\n  - 房间禁言、黑白名单\n# 在本地跑起来\n拉取代码，导入开发者工具即可运行起来。\n\n# 项目结构\n```shell\n|- template 自定义组件目录\n    |- card 直播间列表（已开播、未开播、立即开播）\n    |- gift 礼物组件\n    |- memberListModa 成员列表组件（直播间成员、禁言名单、白名单）\n|-pages 功能页面\n    |-abount 关于直播间\n    |-active 开播列表\n    |-index 正在直播列表\n    |-live 直播间详情页面 （大部分逻辑都在此页面）\n|-utils 工具类和sdk的一些配置\n|-sdk 环信sdk\n|-app.js 小程序根实例，存放一些全局变量，注册监听事件\n|-app.json 注册页面以及全局的一些配置\n|-app.wxss 一些全局样式\n|-project.config.json工程的一些配置，和开发者工具 “详情” 中的设置一样\n```\n# 可以复用的代码\n如果想快速搭建起一个有im能力的直播小程序，可以选择复用demo中的代码，其中utils以帮助快速集成sdk，template组件里面包含礼物系统、直播列表card等\n\n# 常见问题\n+ 怎么收发消息 ?（普通消息、自定义消息)\n  ### demo中发送普通消息：\n   ```\n  + 1、let id = wx.WebIM.conn.getUniqueId() // 生成本地消息id\n  + 2、let msg = new wx.WebIM.message('txt', id); // 创建文本消息\n  + 3、msg.set({                              \n      msg: tsxtMsg,    // 消息体内容 \n      to: roomId,      // 接收房间号\n      from,            //发送方\n      roomType: true,  // 通过roomType区分聊天室、群组，true为聊天室，false为群组\n      ext: { nickName: this.data.nickName },  //扩展消息\n      success: function (id, serverMsgId) {}, //成功后的回调\n      fail: function (e) {} // 失败回调\n    });\n  + 4、msg.setGroup('groupchat') // 调用sdk接收成功的回调消息体\n  + 5、wx.WebIM.conn.send(msg.body) // socket 发送\n    ```\n  \u003e（详情请看demo中 sendTextMsg() 这个方法）\n\n  ### demo中收到普通消息：\n  + 在微信钩子函数中监听 onTextMessage 事件，通过sdk返回的成功回调，获取消息体。将消息体里的内容提取，通过this.setData()做消息上屏 \n  \u003e（详情请看 onTextMessage() 事件）\n\n  ### demo中发送自定义消息（礼物、点赞消息等）\n  ```\n  + 1、let id = wx.WebIM.conn.getUniqueId() // 生成本地消息id\n  + 2、let msg = new wx.WebIM.message('txt', id); // 创建文本消息\n  + 3、\n    msg.set({\n      to: roomId,\n      roomType: true,\n      customEvent: 'chatroom_gift', // 自定义事件\n      customExts: { note: self.data.giftModaData.giftName }, // 自定义消息扩展\n      params: { id: 'gift_' + self.data.giftModaData.showGiftId, num: giftNum }, //自定义消息参数（这里展示的是礼物类别以及送的礼物数量）\n      success: function () {},\n      fail: function () {},\n      ext: { nickName: self.data.nickName }\n    })\n  + 4、msg.setGroup('groupchat') // 调用sdk接收成功的回调消息体\n  + 5、wx.WebIM.conn.send(msg.body) // socket 发送\n  ```\n  \u003e（详情请看 sendGiftMsg()、giveLike()、sendSubtitles() 事件）\n\n  ### demo中发送自定义消息（礼物、点赞消息等）\n  + 与收到普通消息大同小异。在微信钩子函数中监听 onCustomMessage 事件，通过sdk返回的成功回调，来做数据处理\n------\n# 写在最后\n第一期直播小程序demo完善了直播间聊天部分，主播开播下播、白名单用户、房间禁言等 [礼物、点赞类的实现的仅仅是静态示例。真正结合实际应用场景还需要用户根据自己的需求完善]\n\n注意：这期我们没有加入用户系统、都是随机生成的。后续我们会引入直播视频、弹幕漂浮。让这款demo真正看起来符合一个开箱即用快速集成的直播小程序。\n\n还有一些功能demo没有去实现但是sdk是支持的，要用到的话大家可以去查[文档](https://webim.easemob.com/sdk/jsdoc/out/connection.html) [当然也可以在环信提工单进行咨询]","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasemob%2Flivestream_demo_miniprogram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feasemob%2Flivestream_demo_miniprogram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasemob%2Flivestream_demo_miniprogram/lists"}