LiveModel.ets
11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import { HttpBizUtil, HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork';
import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
import { Logger, ToastUtils, EmitterEventId, EmitterUtils, SPHelper } from 'wdKit';
import { ContentDetailDTO, LiveDetailsBean, LiveRoomBean, LiveRoomDataBean,
LiveRoomItemBean,
ReserveItemBean, ValueType } from 'wdBean/Index';
import { ContentDetailRequest } from 'wdDetailPlayApi/Index';
import { SpConstants } from 'wdConstant/Index';
import { LiveMessageOptType } from 'wdBean/src/main/ets/bean/live/LiveRoomBean';
const TAG = 'LiveModel'
export class LiveModel {
getContentDetail(contentId: string, relId: string, relType: string) {
return new Promise<Array<ContentDetailDTO>>((success, fail) => {
ContentDetailRequest.getContentDetail({
contentId: contentId,
relId: relId,
relType: relType
}).then(async (resDTO: ResponseDTO<ContentDetailDTO[]>) => {
console.log(TAG, 'getContentDetail:', JSON.stringify(resDTO.data))
if (resDTO.data) {
//console.error("XXXXZZZZ", '---getContentDetail-0---1------------')
success(resDTO.data)
}else {
// console.error("XXXXZZZZ", '---getContentDetail-0--2----1--------')
fail("数据为空")
}
}).catch(() => {
// console.error("XXXXZZZZ", '---getContentDetail-0--2----2--------')
fail("数据为空")
})
})
}
/**
* 直播内容详情
* @param contentId
* @param relId 关系id
* @param relType 关系类型;1.频道关系;2.专题关系;
* @returns
*/
getLiveDetails(contentId: string, relId: string, relType: string) {
return new Promise<Array<LiveDetailsBean>>((success, fail) => {
HttpRequest.get<ResponseDTO<Array<LiveDetailsBean>>>(
HttpUrlUtils.getLiveDetailsUrl() + `?relId=${relId}&relType=${relType}&contentId=${contentId}`,
).then((data: ResponseDTO<Array<LiveDetailsBean>>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.message)
})
})
}
/**
* 获取直播详情页面直播间数据列表
* @param pageNum
* @param mLiveId
* @param liveId
* @param pageSize
* @returns
*/
getLiveList(pageNum: number, mLiveId: string, liveId: string, pageSize: number) {
let params: Record<string, string> = {};
params['pageNum'] = pageNum + ''
params['mLiveId'] = mLiveId
params['liveId'] = liveId
params['pageSize'] = pageSize + ''
return new Promise<LiveRoomBean>((success, fail) => {
HttpRequest.post<ResponseDTO<LiveRoomBean>>(
HttpUrlUtils.getLiveListUrl(),
params,
).then((data: ResponseDTO<LiveRoomBean>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
})
})
}
/**
* 获取直播详情页面大家聊数据列表
* @param pageNum
* @param mLiveId
* @param liveId
* @param pageSize
* @returns
*/
getLiveChatList(pageNum: number, mLiveId: string, liveId: string, pageSize: number) {
let params: Record<string, string> = {};
params['pageNum'] = pageNum + ''
params['mLiveId'] = mLiveId
params['liveId'] = liveId
params['pageSize'] = pageSize + ''
return new Promise<LiveRoomBean>((success, fail) => {
HttpBizUtil.post<ResponseDTO<LiveRoomBean>>(
HttpUrlUtils.getLiveChatListUrl(),
params,
).then((data: ResponseDTO<LiveRoomBean>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
})
})
}
/**
* C端评论列表 竖屏直播间
* @param pageNum
* @param mLiveId
* @param liveId
* @param pageSize
* @returns
*/
getLiveCommentList(pageNum: number, mLiveId: string, liveId: string, pageSize: number) {
let params: Record<string, string> = {};
params['pageNum'] = pageNum + ''
params['mLiveId'] = mLiveId
params['liveId'] = liveId
params['pageSize'] = pageSize + ''
return new Promise<LiveRoomBean>((success, fail) => {
HttpRequest.post<ResponseDTO<LiveRoomBean>>(
HttpUrlUtils.getLiveCommentListUrl(),
params,
).then((data: ResponseDTO<LiveRoomBean>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
})
})
}
/**
* 获取直播数据
* @param liveId
* @returns
*/
getLiveRoomData(liveId: string) {
return new Promise<LiveRoomDataBean>((success, fail) => {
HttpRequest.get<ResponseDTO<LiveRoomDataBean>>(
HttpUrlUtils.getLiveRoomDataUrl() + `?liveId=${liveId}`,
).then((data: ResponseDTO<LiveRoomDataBean>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
})
})
}
/**
* 直播详情-C端点赞接口
* @param liveId
* @param number
* @param deviceId
* @returns
*/
getLiveRoomNumberLike(liveId: string, number: number, deviceId: string | number) {
return new Promise<number>((success, fail) => {
HttpRequest.get<ResponseDTO<number>>(
HttpUrlUtils.getLiveRoomNumberLikeUrl() + `?liveId=${liveId}&number=${number}&deviceId=${deviceId}`,
).then((data: ResponseDTO<number>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
})
})
}
/**
* 直播详情-查询是否点赞接口
* @param liveId
* @param userId
* @param deviceId
* @returns
*/
getLiveLike(liveId: string, userId: ValueType, deviceId: string | number) {
return new Promise<boolean>((success, fail) => {
HttpRequest.get<ResponseDTO<boolean>>(
HttpUrlUtils.getLiveLikeUrl() + `?liveId=${liveId}&userId=${userId}&deviceId=${deviceId}`,
).then((data: ResponseDTO<boolean>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
})
})
}
/**
* 获取直播预约状态
* @param relationId
* @param liveId
* @returns
*/
getLiveAppointmentStatus(relationId: string, liveId: string) {
return new Promise<boolean>((success, fail) => {
HttpRequest.get<ResponseDTO<boolean>>(
HttpUrlUtils.getLiveAppointmentStatusUrl() + `?relationId=${relationId}&liveId=${liveId}`,
).then((data: ResponseDTO<boolean>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
})
})
}
/**
* 直播预约/取消预约
* @param relationId
* @param mLiveId
* @param isSubscribe
* @returns
*/
liveAppointment(relationId: string, liveId: string, isSubscribe: boolean) {
let params: Record<string, string> = {};
params['relationId'] = relationId
params['liveId'] = liveId
params['isSubscribe'] = `${isSubscribe}`
return new Promise<ResponseDTO<string>>((success, fail) => {
HttpRequest.post<ResponseDTO<string>>(
HttpUrlUtils.getLiveAppointmentUrl(),
params,
).then((data: ResponseDTO<string>) => {
if (data.code != 0) {
fail(data.message)
ToastUtils.shortToast(data.message)
return
}
if (data.code == 0) {
const reserveModel = new ReserveItemBean(Number(liveId), relationId, isSubscribe)
EmitterUtils.sendEvent(EmitterEventId.LIVE_ROOM_SUBSCRIBE, JSON.stringify(reserveModel))
}
success(data)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
})
})
}
liveSendComment(comment: string, content: ContentDetailDTO) {
let tourist: boolean = !HttpUtils.isLogin()
let roomId: string = content.liveInfo.mlive.roomId as string
let liveId: string = content.newsId + ''
let mLiveId: string = content.liveInfo.mlive.mliveId as string
let commentItem: LiveRoomItemBean = {} as LiveRoomItemBean
commentItem.text = comment
commentItem.isWall = 0
commentItem.dataType = LiveMessageOptType.ZH_TEXT_MSG
let params: Record<string, string | number> = {};
params["liveId"] = liveId
params["mliveId"] = mLiveId
params["roomId"] = roomId
params["title"] = content.newsTitle
params["text"] = comment
if (tourist) {
params["deviceId"] = HttpUtils.getDeviceId()
params["senderUserName"] = SPHelper.default.getSync(SpConstants.TOURIST_NICK_NAME, "") as string
} else {
params["senderUserId"] = SPHelper.default.getSync(SpConstants.USER_ID, "") as string
params["senderAvatarUrl"] = SPHelper.default.getSync(SpConstants.USER_HEAD_PHOTO_URL, "") as string
params["senderUserName"] = SPHelper.default.getSync(SpConstants.USER_NAME, "") as string
commentItem.senderUserAvatarUrl = params["senderAvatarUrl"]
}
commentItem.senderUserName = params["senderUserName"]
params["customizeExpression"] = 0
params["role"] = tourist ? "tourist" : "audience"
commentItem.role = tourist ? "tourist" : "audience"
let url = tourist ? HttpUrlUtils.getLiveTouristSendBarrageUrl() : HttpUrlUtils.getLiveSendBarrageUrl()
return new Promise<SendLiveCommentRes>((success, fail) => {
HttpRequest.post<ResponseDTO<SendLiveCommentInterfaceRes>>(url, params).then((data) => {
let res:SendLiveCommentRes = {
preDisplay: data.data?.preDisplay || false,
tipMessage: data.message,
commentItem: commentItem
}
success(res)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
})
})
}
}
interface SendLiveCommentInterfaceRes {
preDisplay: boolean
}
export interface SendLiveCommentRes {
preDisplay: boolean
tipMessage: string
commentItem: LiveRoomItemBean
}