or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

analytics.mdcloud-development.mdconfiguration.mdcore-services.mddevelopment-tools.mdecommerce.mdindex.mdlive-streaming.mdlogistics.mdmedia-content.mdmessaging.mdqr-codes.mduser-management.md

live-streaming.mddocs/

0

# Live Streaming

1

2

Complete live streaming functionality including room management, broadcast control, product integration, audience management, and real-time interaction features for WeChat MiniApp live commerce.

3

4

## Capabilities

5

6

### Live Service Interface

7

8

Core live streaming operations for room management and broadcast control.

9

10

```java { .api }

11

public interface WxMaLiveService {

12

// Room Management

13

WxMaCreateRoomResult createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException;

14

boolean deleteRoom(Integer roomId) throws WxErrorException;

15

boolean editRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException;

16

WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException;

17

List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException;

18

WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException;

19

20

// Room Features

21

String getPushUrl(Integer roomId) throws WxErrorException;

22

WxMaLiveSharedCode getSharedCode(Integer roomId, String params) throws WxErrorException;

23

boolean updatefeedpublic(Integer roomId, Integer isFeedsPublic) throws WxErrorException;

24

boolean updatereplay(Integer roomId, Integer closeReplay) throws WxErrorException;

25

boolean updatekf(Integer roomId, Integer closeKf) throws WxErrorException;

26

boolean updatecomment(Integer roomId, Integer banComment) throws WxErrorException;

27

28

// Assistant Management

29

boolean addAssistant(Integer roomId, List<WxMaLiveAssistantInfo> users) throws WxErrorException;

30

boolean modifyAssistant(Integer roomId, String username, String nickname) throws WxErrorException;

31

boolean removeAssistant(Integer roomId, String username) throws WxErrorException;

32

List<WxMaAssistantResult.Assistant> getAssistantList(Integer roomId) throws WxErrorException;

33

34

// Sub-anchor Management

35

boolean addSubanchor(Integer roomId, String username) throws WxErrorException;

36

boolean modifySubanchor(Integer roomId, String username) throws WxErrorException;

37

boolean deleteSubanchor(Integer roomId) throws WxErrorException;

38

String getSubanchor(Integer roomId) throws WxErrorException;

39

40

// Product Management in Live Room

41

boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxErrorException;

42

boolean onsale(Integer roomId, Integer goodsId, Integer onSale) throws WxErrorException;

43

boolean deleteInRoom(Integer roomId, Integer goodsId) throws WxErrorException;

44

boolean push(Integer roomId, Integer goodsId) throws WxErrorException;

45

boolean sort(Integer roomId, List<Map<String, String>> goods) throws WxErrorException;

46

String getVideo(Integer roomId, Integer goodsId) throws WxErrorException;

47

}

48

```

49

50

### Live Goods Service

51

52

Product management specifically for live streaming scenarios.

53

54

```java { .api }

55

public interface WxMaLiveGoodsService {

56

// Live streaming product management

57

WxMaLiveGoodsResult addGoods(WxMaLiveGoodsInfo goodsInfo) throws WxErrorException;

58

boolean deleteGoods(Integer goodsId) throws WxErrorException;

59

boolean updateGoods(WxMaLiveGoodsInfo goodsInfo) throws WxErrorException;

60

WxMaLiveGoodsInfo getGoods(Integer goodsId) throws WxErrorException;

61

WxMaLiveGoodsList getGoodsList(Integer offset, Integer limit, Integer status) throws WxErrorException;

62

boolean auditGoods(Integer goodsId) throws WxErrorException;

63

boolean resetAuditGoods(Integer goodsId) throws WxErrorException;

64

}

65

```

66

67

### Live Member Service

68

69

Audience and participant management for live streaming rooms.

70

71

```java { .api }

72

public interface WxMaLiveMemberService {

73

// Member role management

74

boolean addRole(Integer roomId, String username, String role) throws WxErrorException;

75

boolean deleteRole(Integer roomId, String username, String role) throws WxErrorException;

76

List<WxMaLiveMemberResult.Member> getRole(Integer roomId, String role) throws WxErrorException;

77

}

78

```

79

80

### Live Room Data Models

81

82

Comprehensive data models for live streaming room configuration and management.

83

84

```java { .api }

85

public class WxMaLiveRoomInfo implements Serializable {

86

private Integer roomId; // Room ID (for updates)

87

private String name; // Room name

88

private String coverImg; // Cover image URL

89

private Long startTime; // Start timestamp (seconds)

90

private Long endTime; // End timestamp (seconds)

91

private String anchorName; // Anchor name

92

private String anchorWechat; // Anchor WeChat ID

93

private String shareImg; // Share image URL

94

private Integer feedsPublic; // Official collection (0: no, 1: yes)

95

private Integer type; // Room type (1: phone landscape, 0: phone portrait)

96

private Integer screenType; // Screen type (0: horizontal, 1: vertical)

97

private Integer closeLike; // Close like (0: open, 1: close)

98

private Integer closeGoods; // Close goods (0: open, 1: close)

99

private Integer closeComment; // Close comment (0: open, 1: close)

100

private Integer closeReplay; // Close replay (0: open, 1: close)

101

private Integer closeShare; // Close share (0: open, 1: close)

102

private Integer closeKf; // Close customer service (0: open, 1: close)

103

104

// Getters and setters

105

public Integer getRoomId();

106

public void setRoomId(Integer roomId);

107

public String getName();

108

public void setName(String name);

109

public String getCoverImg();

110

public void setCoverImg(String coverImg);

111

public Long getStartTime();

112

public void setStartTime(Long startTime);

113

public Long getEndTime();

114

public void setEndTime(Long endTime);

115

public String getAnchorName();

116

public void setAnchorName(String anchorName);

117

public String getAnchorWechat();

118

public void setAnchorWechat(String anchorWechat);

119

public String getShareImg();

120

public void setShareImg(String shareImg);

121

122

// Utility methods

123

public Date getStartTimeAsDate();

124

public Date getEndTimeAsDate();

125

public static WxMaLiveRoomInfo fromJson(String json);

126

public String toJson();

127

}

128

```

129

130

```java { .api }

131

public class WxMaCreateRoomResult implements Serializable {

132

private Integer roomId; // Created room ID

133

private String qrCodeUrl; // QR code URL for sharing

134

135

public Integer getRoomId();

136

public void setRoomId(Integer roomId);

137

public String getQrCodeUrl();

138

public void setQrCodeUrl(String qrCodeUrl);

139

}

140

141

public class WxMaLiveResult implements Serializable {

142

private Integer total; // Total count

143

private List<RoomInfo> roomInfo; // Room information list

144

145

public static class RoomInfo {

146

private String name; // Room name

147

private Integer roomId; // Room ID

148

private String coverImg; // Cover image

149

private String shareImg; // Share image

150

private Integer liveStatus; // Live status (101: not started, 102: live, 103: ended, 104: banned, 105: paused)

151

private Long startTime; // Start time

152

private Long endTime; // End time

153

private String anchorName; // Anchor name

154

private List<GoodsInfo> goods; // Goods in room

155

156

// Getters and setters

157

public String getName();

158

public void setName(String name);

159

public Integer getRoomId();

160

public void setRoomId(Integer roomId);

161

public Integer getLiveStatus();

162

public void setLiveStatus(Integer liveStatus);

163

public List<GoodsInfo> getGoods();

164

public void setGoods(List<GoodsInfo> goods);

165

}

166

167

public static class GoodsInfo {

168

private String coverImg; // Product cover image

169

private String url; // Product page URL

170

private Integer price; // Price (in cents)

171

private String name; // Product name

172

private Integer priceType; // Price type (1: one price, 2: price range)

173

174

// Getters and setters

175

public String getName();

176

public void setName(String name);

177

public Integer getPrice();

178

public void setPrice(Integer price);

179

public String getCoverImg();

180

public void setCoverImg(String coverImg);

181

}

182

}

183

```

184

185

### Live Assistant and Role Management

186

187

Models for managing assistants and roles in live streaming rooms.

188

189

```java { .api }

190

public class WxMaLiveAssistantInfo implements Serializable {

191

private String username; // WeChat number

192

private String nickname; // Display nickname

193

194

public WxMaLiveAssistantInfo();

195

public WxMaLiveAssistantInfo(String username, String nickname);

196

197

public String getUsername();

198

public void setUsername(String username);

199

public String getNickname();

200

public void setNickname(String nickname);

201

}

202

203

public class WxMaAssistantResult implements Serializable {

204

private Integer count; // Assistant count

205

private Integer maxCount; // Maximum allowed

206

private List<Assistant> list; // Assistant list

207

208

public static class Assistant {

209

private String username; // WeChat number

210

private String nickname; // Display nickname

211

private Long timestamp; // Add timestamp

212

213

public String getUsername();

214

public void setUsername(String username);

215

public String getNickname();

216

public void setNickname(String nickname);

217

public Long getTimestamp();

218

public void setTimestamp(Long timestamp);

219

}

220

}

221

```

222

223

### Live Goods Models

224

225

Product models specifically for live streaming scenarios.

226

227

```java { .api }

228

public class WxMaLiveGoodsInfo implements Serializable {

229

private Integer goodsId; // Goods ID

230

private String coverImgUrl; // Cover image URL

231

private String name; // Product name

232

private Integer priceType; // Price type (1: single price, 2: range)

233

private Integer price; // Price (in cents, for single price)

234

private Integer price2; // End price (in cents, for range)

235

private String url; // Product detail page URL

236

private Integer priceTicketPrice; // Original price (for display)

237

private String priceTicketDesc; // Price description

238

private Integer auditStatus; // Audit status (0: not submitted, 1: pending, 2: rejected, 3: approved)

239

240

// Getters and setters

241

public Integer getGoodsId();

242

public void setGoodsId(Integer goodsId);

243

public String getName();

244

public void setName(String name);

245

public String getCoverImgUrl();

246

public void setCoverImgUrl(String coverImgUrl);

247

public Integer getPriceType();

248

public void setPriceType(Integer priceType);

249

public Integer getPrice();

250

public void setPrice(Integer price);

251

public String getUrl();

252

public void setUrl(String url);

253

public Integer getAuditStatus();

254

public void setAuditStatus(Integer auditStatus);

255

}

256

```

257

258

## Usage Examples

259

260

### Live Room Management

261

262

#### Create Live Room

263

264

```java

265

@Service

266

public class LiveStreamingService {

267

268

@Autowired

269

private WxMaService wxMaService;

270

271

public WxMaCreateRoomResult createLiveRoom(LiveRoomCreateRequest request) {

272

try {

273

// Upload cover and share images

274

String coverImgUrl = uploadImageToWeChat(request.getCoverImage());

275

String shareImgUrl = uploadImageToWeChat(request.getShareImage());

276

277

// Create room info

278

WxMaLiveRoomInfo roomInfo = new WxMaLiveRoomInfo();

279

roomInfo.setName(request.getRoomName());

280

roomInfo.setCoverImg(coverImgUrl);

281

roomInfo.setShareImg(shareImgUrl);

282

roomInfo.setAnchorName(request.getAnchorName());

283

roomInfo.setAnchorWechat(request.getAnchorWechatId());

284

285

// Set time (convert to seconds)

286

roomInfo.setStartTime(request.getStartTime().getTime() / 1000);

287

roomInfo.setEndTime(request.getEndTime().getTime() / 1000);

288

289

// Set room features

290

roomInfo.setType(request.getType()); // 0: portrait, 1: landscape

291

roomInfo.setScreenType(request.getScreenType()); // 0: horizontal, 1: vertical

292

roomInfo.setCloseLike(request.getCloseLike()); // 0: allow, 1: disable

293

roomInfo.setCloseGoods(request.getCloseGoods()); // 0: show, 1: hide

294

roomInfo.setCloseComment(request.getCloseComment()); // 0: allow, 1: disable

295

roomInfo.setCloseReplay(request.getCloseReplay()); // 0: allow, 1: disable

296

roomInfo.setCloseKf(request.getCloseKf()); // 0: allow, 1: disable

297

roomInfo.setFeedsPublic(request.getFeedsPublic()); // 0: private, 1: public

298

299

// Create room

300

WxMaCreateRoomResult result = wxMaService.getLiveService()

301

.createRoom(roomInfo);

302

303

logger.info("Live room created: {} - {}", result.getRoomId(), request.getRoomName());

304

305

// Store room info in database

306

saveRoomToDatabase(result, request);

307

308

return result;

309

310

} catch (WxErrorException e) {

311

logger.error("Failed to create live room: {}", e.getMessage());

312

throw new LiveRoomCreationException("Live room creation failed", e);

313

}

314

}

315

}

316

```

317

318

#### Update Live Room Settings

319

320

```java

321

public void updateLiveRoom(Integer roomId, LiveRoomUpdateRequest request) {

322

try {

323

// Get existing room info

324

WxMaLiveResult liveResult = wxMaService.getLiveService()

325

.getLiveInfo(0, 100);

326

327

WxMaLiveResult.RoomInfo existingRoom = liveResult.getRoomInfo().stream()

328

.filter(room -> room.getRoomId().equals(roomId))

329

.findFirst()

330

.orElseThrow(() -> new LiveRoomNotFoundException("Room not found: " + roomId));

331

332

// Update room info

333

WxMaLiveRoomInfo updateInfo = new WxMaLiveRoomInfo();

334

updateInfo.setRoomId(roomId);

335

updateInfo.setName(request.getName() != null ? request.getName() : existingRoom.getName());

336

337

if (request.getCoverImage() != null) {

338

String newCoverUrl = uploadImageToWeChat(request.getCoverImage());

339

updateInfo.setCoverImg(newCoverUrl);

340

}

341

342

if (request.getStartTime() != null) {

343

updateInfo.setStartTime(request.getStartTime().getTime() / 1000);

344

}

345

346

if (request.getEndTime() != null) {

347

updateInfo.setEndTime(request.getEndTime().getTime() / 1000);

348

}

349

350

// Apply updates

351

boolean success = wxMaService.getLiveService().editRoom(updateInfo);

352

353

if (success) {

354

logger.info("Live room updated: {}", roomId);

355

}

356

357

} catch (WxErrorException e) {

358

logger.error("Failed to update live room {}: {}", roomId, e.getMessage());

359

throw new LiveRoomUpdateException("Room update failed", e);

360

}

361

}

362

```

363

364

#### Room Feature Management

365

366

```java

367

public void configureRoomFeatures(Integer roomId, RoomFeaturesConfig config) {

368

try {

369

// Update individual features

370

if (config.getFeedsPublic() != null) {

371

wxMaService.getLiveService().updatefeedpublic(roomId, config.getFeedsPublic());

372

}

373

374

if (config.getCloseReplay() != null) {

375

wxMaService.getLiveService().updatereplay(roomId, config.getCloseReplay());

376

}

377

378

if (config.getCloseKf() != null) {

379

wxMaService.getLiveService().updatekf(roomId, config.getCloseKf());

380

}

381

382

if (config.getBanComment() != null) {

383

wxMaService.getLiveService().updatecomment(roomId, config.getBanComment());

384

}

385

386

logger.info("Room features updated for room: {}", roomId);

387

388

} catch (WxErrorException e) {

389

logger.error("Failed to update room features for room {}: {}",

390

roomId, e.getMessage());

391

}

392

}

393

```

394

395

### Assistant and Role Management

396

397

#### Add Live Assistants

398

399

```java

400

public void addLiveAssistants(Integer roomId, List<AssistantInfo> assistants) {

401

try {

402

List<WxMaLiveAssistantInfo> assistantInfos = assistants.stream()

403

.map(assistant -> new WxMaLiveAssistantInfo(

404

assistant.getWechatId(),

405

assistant.getNickname()

406

))

407

.collect(Collectors.toList());

408

409

boolean success = wxMaService.getLiveService()

410

.addAssistant(roomId, assistantInfos);

411

412

if (success) {

413

logger.info("Added {} assistants to room {}", assistants.size(), roomId);

414

}

415

416

} catch (WxErrorException e) {

417

logger.error("Failed to add assistants to room {}: {}", roomId, e.getMessage());

418

}

419

}

420

421

public void manageAssistant(Integer roomId, String wechatId, String action, String nickname) {

422

try {

423

switch (action.toLowerCase()) {

424

case "modify":

425

wxMaService.getLiveService().modifyAssistant(roomId, wechatId, nickname);

426

logger.info("Modified assistant {} in room {}", wechatId, roomId);

427

break;

428

429

case "remove":

430

wxMaService.getLiveService().removeAssistant(roomId, wechatId);

431

logger.info("Removed assistant {} from room {}", wechatId, roomId);

432

break;

433

434

default:

435

logger.warn("Unknown assistant action: {}", action);

436

}

437

438

} catch (WxErrorException e) {

439

logger.error("Failed to {} assistant {} in room {}: {}",

440

action, wechatId, roomId, e.getMessage());

441

}

442

}

443

```

444

445

#### Sub-anchor Management

446

447

```java

448

public void addSubAnchor(Integer roomId, String wechatId) {

449

try {

450

boolean success = wxMaService.getLiveService().addSubanchor(roomId, wechatId);

451

452

if (success) {

453

logger.info("Added sub-anchor {} to room {}", wechatId, roomId);

454

}

455

456

} catch (WxErrorException e) {

457

logger.error("Failed to add sub-anchor {} to room {}: {}",

458

wechatId, roomId, e.getMessage());

459

}

460

}

461

462

public String getSubAnchor(Integer roomId) {

463

try {

464

return wxMaService.getLiveService().getSubanchor(roomId);

465

466

} catch (WxErrorException e) {

467

logger.error("Failed to get sub-anchor for room {}: {}", roomId, e.getMessage());

468

return null;

469

}

470

}

471

```

472

473

### Product Management in Live Rooms

474

475

#### Add Products to Live Room

476

477

```java

478

@Service

479

public class LiveProductService {

480

481

public void addProductsToLiveRoom(Integer roomId, List<Integer> productIds) {

482

try {

483

boolean success = wxMaService.getLiveService()

484

.addGoodsToRoom(roomId, productIds);

485

486

if (success) {

487

logger.info("Added {} products to live room {}", productIds.size(), roomId);

488

489

// Set initial products as on-sale

490

for (Integer productId : productIds) {

491

wxMaService.getLiveService().onsale(roomId, productId, 1);

492

}

493

}

494

495

} catch (WxErrorException e) {

496

logger.error("Failed to add products to room {}: {}", roomId, e.getMessage());

497

}

498

}

499

500

public void manageProductInRoom(Integer roomId, Integer productId, String action) {

501

try {

502

switch (action.toLowerCase()) {

503

case "onsale":

504

wxMaService.getLiveService().onsale(roomId, productId, 1);

505

logger.info("Put product {} on sale in room {}", productId, roomId);

506

break;

507

508

case "offsale":

509

wxMaService.getLiveService().onsale(roomId, productId, 0);

510

logger.info("Took product {} off sale in room {}", productId, roomId);

511

break;

512

513

case "push":

514

wxMaService.getLiveService().push(roomId, productId);

515

logger.info("Pushed product {} in room {}", productId, roomId);

516

break;

517

518

case "remove":

519

wxMaService.getLiveService().deleteInRoom(roomId, productId);

520

logger.info("Removed product {} from room {}", productId, roomId);

521

break;

522

}

523

524

} catch (WxErrorException e) {

525

logger.error("Failed to {} product {} in room {}: {}",

526

action, productId, roomId, e.getMessage());

527

}

528

}

529

530

public void sortProductsInRoom(Integer roomId, List<ProductSortInfo> sortOrder) {

531

try {

532

List<Map<String, String>> goods = sortOrder.stream()

533

.map(product -> {

534

Map<String, String> goodsMap = new HashMap<>();

535

goodsMap.put("goodsId", product.getProductId().toString());

536

goodsMap.put("sortOrder", product.getSortOrder().toString());

537

return goodsMap;

538

})

539

.collect(Collectors.toList());

540

541

boolean success = wxMaService.getLiveService().sort(roomId, goods);

542

543

if (success) {

544

logger.info("Updated product sort order for room {}", roomId);

545

}

546

547

} catch (WxErrorException e) {

548

logger.error("Failed to sort products in room {}: {}", roomId, e.getMessage());

549

}

550

}

551

}

552

```

553

554

### Live Goods Management

555

556

#### Create Live Streaming Product

557

558

```java

559

public Integer createLiveProduct(LiveProductCreateRequest request) {

560

try {

561

// Upload product cover image

562

String coverImgUrl = uploadImageToWeChat(request.getCoverImage());

563

564

WxMaLiveGoodsInfo goodsInfo = new WxMaLiveGoodsInfo();

565

goodsInfo.setCoverImgUrl(coverImgUrl);

566

goodsInfo.setName(request.getName());

567

goodsInfo.setPriceType(request.getPriceType()); // 1: single, 2: range

568

569

if (request.getPriceType() == 1) {

570

goodsInfo.setPrice(request.getPrice());

571

} else {

572

goodsInfo.setPrice(request.getMinPrice());

573

goodsInfo.setPrice2(request.getMaxPrice());

574

}

575

576

goodsInfo.setUrl(request.getProductUrl());

577

goodsInfo.setPriceTicketPrice(request.getOriginalPrice());

578

goodsInfo.setPriceTicketDesc(request.getPriceDescription());

579

580

WxMaLiveGoodsResult result = wxMaService.getLiveGoodsService()

581

.addGoods(goodsInfo);

582

583

Integer goodsId = result.getGoodsId();

584

logger.info("Live product created: {} - {}", goodsId, request.getName());

585

586

// Submit for audit

587

wxMaService.getLiveGoodsService().auditGoods(goodsId);

588

589

return goodsId;

590

591

} catch (WxErrorException e) {

592

logger.error("Failed to create live product: {}", e.getMessage());

593

throw new LiveProductCreationException("Live product creation failed", e);

594

}

595

}

596

```

597

598

#### Manage Live Product Lifecycle

599

600

```java

601

public void updateLiveProduct(Integer goodsId, LiveProductUpdateRequest request) {

602

try {

603

// Get existing product

604

WxMaLiveGoodsInfo existingProduct = wxMaService.getLiveGoodsService()

605

.getGoods(goodsId);

606

607

// Update fields

608

if (request.getName() != null) {

609

existingProduct.setName(request.getName());

610

}

611

612

if (request.getPrice() != null) {

613

existingProduct.setPrice(request.getPrice());

614

}

615

616

if (request.getCoverImage() != null) {

617

String newCoverUrl = uploadImageToWeChat(request.getCoverImage());

618

existingProduct.setCoverImgUrl(newCoverUrl);

619

}

620

621

// Update product

622

boolean success = wxMaService.getLiveGoodsService()

623

.updateGoods(existingProduct);

624

625

if (success) {

626

logger.info("Live product updated: {}", goodsId);

627

628

// Re-submit for audit if needed

629

if (request.isResubmitForAudit()) {

630

wxMaService.getLiveGoodsService().resetAuditGoods(goodsId);

631

wxMaService.getLiveGoodsService().auditGoods(goodsId);

632

}

633

}

634

635

} catch (WxErrorException e) {

636

logger.error("Failed to update live product {}: {}", goodsId, e.getMessage());

637

}

638

}

639

640

public void deleteLiveProduct(Integer goodsId) {

641

try {

642

boolean success = wxMaService.getLiveGoodsService().deleteGoods(goodsId);

643

644

if (success) {

645

logger.info("Live product deleted: {}", goodsId);

646

}

647

648

} catch (WxErrorException e) {

649

logger.error("Failed to delete live product {}: {}", goodsId, e.getMessage());

650

}

651

}

652

```

653

654

### Live Room Analytics and Monitoring

655

656

```java

657

@Service

658

public class LiveAnalyticsService {

659

660

public LiveRoomStats getLiveRoomStats(Integer roomId) {

661

try {

662

// Get room info

663

WxMaLiveResult roomResult = wxMaService.getLiveService()

664

.getLiveInfo(0, 100);

665

666

WxMaLiveResult.RoomInfo room = roomResult.getRoomInfo().stream()

667

.filter(r -> r.getRoomId().equals(roomId))

668

.findFirst()

669

.orElse(null);

670

671

if (room == null) {

672

throw new LiveRoomNotFoundException("Room not found: " + roomId);

673

}

674

675

// Get replay data

676

WxMaLiveResult replayResult = wxMaService.getLiveService()

677

.getLiveReplay(roomId, 0, 100);

678

679

// Build statistics

680

LiveRoomStats stats = new LiveRoomStats();

681

stats.setRoomId(roomId);

682

stats.setRoomName(room.getName());

683

stats.setLiveStatus(room.getLiveStatus());

684

stats.setProductCount(room.getGoods() != null ? room.getGoods().size() : 0);

685

stats.setReplayCount(replayResult.getTotal());

686

687

return stats;

688

689

} catch (WxErrorException e) {

690

logger.error("Failed to get room stats for {}: {}", roomId, e.getMessage());

691

throw new LiveAnalyticsException("Failed to get room statistics", e);

692

}

693

}

694

695

@Scheduled(fixedRate = 300000) // Every 5 minutes

696

public void monitorLiveRooms() {

697

try {

698

List<WxMaLiveResult.RoomInfo> rooms = wxMaService.getLiveService()

699

.getLiveInfos();

700

701

for (WxMaLiveResult.RoomInfo room : rooms) {

702

if (room.getLiveStatus() == 102) { // Currently live

703

// Monitor live room metrics

704

monitorRoomMetrics(room);

705

}

706

}

707

708

} catch (WxErrorException e) {

709

logger.error("Live room monitoring failed: {}", e.getMessage());

710

}

711

}

712

713

private void monitorRoomMetrics(WxMaLiveResult.RoomInfo room) {

714

// Track viewer count, engagement, product performance

715

// Send alerts if needed

716

logger.info("Room {} is live with {} products",

717

room.getRoomId(),

718

room.getGoods() != null ? room.getGoods().size() : 0);

719

}

720

}

721

```

722

723

### Live Room Event Handler

724

725

```java

726

@Component

727

public class LiveRoomEventHandler {

728

729

@EventListener

730

public void handleLiveRoomStart(LiveRoomStartEvent event) {

731

Integer roomId = event.getRoomId();

732

733

try {

734

// Get push URL for streaming

735

String pushUrl = wxMaService.getLiveService().getPushUrl(roomId);

736

737

// Notify streaming system

738

streamingService.startStream(roomId, pushUrl);

739

740

// Send notifications to followers

741

notificationService.notifyLiveStart(roomId);

742

743

logger.info("Live room {} started with push URL: {}", roomId, pushUrl);

744

745

} catch (WxErrorException e) {

746

logger.error("Failed to handle live room start for {}: {}",

747

roomId, e.getMessage());

748

}

749

}

750

751

@EventListener

752

public void handleLiveRoomEnd(LiveRoomEndEvent event) {

753

Integer roomId = event.getRoomId();

754

755

// Generate room performance report

756

LiveRoomStats stats = liveAnalyticsService.getLiveRoomStats(roomId);

757

758

// Save metrics to database

759

metricsService.saveLiveRoomMetrics(stats);

760

761

logger.info("Live room {} ended. Stats saved.", roomId);

762

}

763

}

764

```

765

766

This live streaming module provides comprehensive functionality for creating, managing, and monitoring WeChat MiniApp live streaming rooms with full product integration, role management, and real-time interaction capabilities.