-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtes.js
30 lines (25 loc) · 919 Bytes
/
tes.js
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
const { WebcastPushConnection } = require('tiktok-live-connector')
// Username of someone who is currently live
let tiktokUsername = 'axelaj3'
// Create a new wrapper object and pass the username
let tiktokLiveConnection = new WebcastPushConnection(tiktokUsername)
// Connect to the chat (await can be used as well)
tiktokLiveConnection
.connect()
.then((state) => {
console.info(`Connected to roomId ${state.roomId}`)
})
.catch((err) => {
console.error('Failed to connect', err)
})
// Define the events that you want to handle
// In this case we listen to chat messages (comments)
tiktokLiveConnection.on('chat', (data) => {
console.log(
`${data.uniqueId} (userId:${data.userId}) writes: ${data.comment}`,
)
})
// And here we receive gifts sent to the streamer
tiktokLiveConnection.on('gift', (data) => {
console.log(`${data.uniqueId} (userId:${data.userId}) sends ${data.giftId}`)
})