@@ -9,17 +9,56 @@ export interface DanmuMsg {
9
9
timestamp : number
10
10
/** 是否为天选抽奖弹幕 */
11
11
lottery : boolean
12
- /** 弹幕表情 */
12
+ /** 表情弹幕内容 */
13
13
emoticon ?: {
14
14
id : string
15
15
height : number
16
16
width : number
17
17
url : string
18
18
}
19
+ /** 弹幕内小表情映射,key为表情文字,如"[妙]" */
20
+ in_message_emoticon ?: Record < string , {
21
+ id : string
22
+ emoticon_id : number
23
+ height : number
24
+ width : number
25
+ url : string
26
+ description : string
27
+ } >
19
28
}
20
29
21
30
const parser = ( data : any , roomId : number ) : DanmuMsg => {
22
31
const rawData = data . info
32
+ const content = rawData [ 1 ]
33
+ // 是否包含中括号
34
+ const parseInMessageEmoticon = / \[ .* ?\] / . test ( content )
35
+ console . log ( 'parseInMessageEmoticon' , parseInMessageEmoticon )
36
+ let inMessageEmoticon
37
+ if ( parseInMessageEmoticon ) {
38
+ const messageExtraInfo = JSON . parse ( rawData [ 0 ] [ 15 ] . extra )
39
+ const emoctionDict : Record < string , {
40
+ id : string
41
+ emoticon_id : number
42
+ height : number
43
+ width : number
44
+ url : string
45
+ description : string
46
+ } > = { }
47
+ if ( messageExtraInfo . emots ) {
48
+ inMessageEmoticon = Object . keys ( messageExtraInfo . emots ) . reduce ( ( acc , key ) => {
49
+ const emoticon = messageExtraInfo . emots [ key ]
50
+ acc [ key ] = {
51
+ id : emoticon . emoticon_unique ,
52
+ emoticon_id : emoticon . emoticon_id ,
53
+ height : emoticon . height ,
54
+ width : emoticon . width ,
55
+ url : emoticon . url ,
56
+ description : emoticon . descript ,
57
+ }
58
+ return acc
59
+ } , emoctionDict )
60
+ }
61
+ }
23
62
return {
24
63
user : {
25
64
uid : rawData [ 2 ] [ 0 ] ,
@@ -47,7 +86,7 @@ const parser = (data: any, roomId: number): DanmuMsg => {
47
86
room_admin : rawData [ 2 ] [ 2 ] === 1 ,
48
87
} ,
49
88
} ,
50
- content : rawData [ 1 ] ,
89
+ content,
51
90
timestamp : rawData [ 0 ] [ 4 ] ,
52
91
lottery : rawData [ 0 ] [ 9 ] !== 0 ,
53
92
emoticon : rawData [ 0 ] [ 13 ] ?. emoticon_unique ? {
@@ -56,6 +95,7 @@ const parser = (data: any, roomId: number): DanmuMsg => {
56
95
width : rawData [ 0 ] [ 13 ] . width ,
57
96
url : rawData [ 0 ] [ 13 ] . url ,
58
97
} : undefined ,
98
+ in_message_emoticon : inMessageEmoticon ,
59
99
}
60
100
}
61
101
0 commit comments