various dlive fixes

master
vampi 9 months ago
parent e7ab14495e
commit 288a9b1a27

@ -52,6 +52,17 @@ class Chat extends EventEmitter {
Array.prototype.unshift.call(arguments, new Date());
console.error.apply(null, arguments);
}
_generateRandomString(length) {
var result = '';
var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for(var i = 0; i < length; i++) {
result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
}
return result;
}
}
if(typeof process === 'object') {

@ -591,13 +591,13 @@ class DLiveChannel extends Channel {
this.chat.api.post({
operationName: 'LivestreamPageRefetch',
variables: {
displayname: this.username
username: this.username
},
query: `
query LivestreamPageRefetch(
$displayname: String!
$username: String!
) {
userByDisplayName(displayname: $displayname) {
user(username: $username) {
livestream {
watchingCount
}
@ -605,31 +605,127 @@ class DLiveChannel extends Channel {
}
`
}).then((data) => {
resolve({ viewers: data.userByDisplayName.livestream && data.userByDisplayName.livestream.watchingCount, platform: this.chat.getPlatformName() });
resolve({ viewers: data.user.livestream && data.user.livestream.watchingCount, platform: this.chat.getPlatformName() });
}, reject);
});
}
getStatus() {
getStatus(original) {
return new Promise((resolve, reject) => {
this.chat.api.post({
operationName: 'LivestreamPageRefetch',
variables: {
displayname: this.username
username: this.username
},
query: `
query LivestreamPageRefetch(
$displayname: String!
$username: String!
) {
userByDisplayName(displayname: $displayname) {
user(username: $username) {
avatar
chatDisabled
chatInterval
chatLinkDisabled
chatMode
chatVerifiedOnly
displayname
donateDisabled
effect
followChatDelay
isFollowing
isMe
isSubscribing
followers {
totalCount
}
following {
totalCount
}
ongoingGiftSub {
gifter {
displayname
id
username
avatar
}
count
}
partnerStatus
role
subscribeDisabled
username
livestream {
id
permlink
title
totalReward
watchingCount
createdAt
category {
id
title
}
creator {
displayname
id
username
}
language {
id
language
}
thumbnailUrl
ageRestriction
earnRestriction
}
subSetting {
badgeColor
badgeText
benefits
streakTextColor
textColor
}
}
}
`
}).then((data) => {
resolve({ viewers: data.userByDisplayName.livestream && data.userByDisplayName.livestream.watchingCount, platform: this.chat.getPlatformName() });
if(original) {
resolve(data);
return;
}
if(!data || !data.user) {
reject(data ? data : 'No data');
return;
}
resolve({
platform: this.chat.getPlatformName(),
clientId: this.chat.id,
channelId: this.id,
user: {
avatar: data.user.avatar,
displayName: data.user.displayname,
followers: data.user.followers.totalCount,
following: data.user.following.totalCount,
},
stream: data.user.livestream ? {
isLive: true,
startTime: data.user.livestream.createdAt / 1000,
viewers: data.user.livestream.watchingCount,
title: data.user.livestream.title,
preview: data.user.livestream.thumbnailUrl,
language: data.user.livestream.language.language,
audienceType: data.user.livestream.ageRestriction ? 'X-Tag' : data.user.livestream.earnRestriction ? 'Mature-Tag' : null,
category: {
id: data.user.livestream.category.id,
name: data.user.livestream.category.title,
}
} : { isLive: false },
chat: {
interval: data.user.chatInterval
}
});
}, reject);
});
}

@ -48,9 +48,11 @@ class DLiveChat extends Chat {
getPlatformName() { return 'dlive'; }
_joinChannelByUsername(channelData) {
var channel = new DLiveChannel(this, channelData);
let channel = new DLiveChannel(this, channelData);
this.channels.push(channel);
channel.id = channelData.username + '-' + this._generateRandomString(8);
this.channels[channel.id] = channel;
return channel;
}

@ -52,7 +52,7 @@ class DLiveSocket extends EventEmitter {
connect() {
this.emit('verbose', 'Opening WebSocket ' + this.wsUrl);
this.webSocket = new WebSocket(this.wsUrl, 'graphql-ws');
this.webSocket = new WebSocket(this.wsUrl, 'graphql-ws', { headers: { 'Accept-Language': 'en-US,en;q=0.9', 'Content-type': 'text/html; charset=utf8'}});
this.webSocket.onopen = (evt) => {
this.emit('verbose', 'websocket open');
this.send({type:'connection_init',payload:{}});

Loading…
Cancel
Save