From 1cb1c47a062b2b4374f838e9db220928ece9de02 Mon Sep 17 00:00:00 2001 From: flxxyz Date: Tue, 23 Jun 2020 13:13:42 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=9B=B4=E4=BC=98=E9=9B=85=E7=9A=84w?= =?UTF-8?q?eb=E6=BC=94=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/web/gift.json | 50 +++++++++++++++ example/web/host.json | 1 + example/web/index.html | 142 ++++++++++++++++++++++++++++++++++++++--- example/web/index.js | 115 --------------------------------- 4 files changed, 185 insertions(+), 123 deletions(-) create mode 100644 example/web/gift.json create mode 100644 example/web/host.json delete mode 100644 example/web/index.js diff --git a/example/web/gift.json b/example/web/gift.json new file mode 100644 index 0000000..d09a3db --- /dev/null +++ b/example/web/gift.json @@ -0,0 +1,50 @@ +{ + "192": "赞(系统)", + "193": "弱鸡(系统)", + "519": "呵呵(系统)", + "520": "稳(系统)", + "712": "棒棒哒(系统)", + "714": "怂(系统)", + "824": "荧光棒", + "1859": "小飞碟", + "20000": "鱼丸", + "20001": "弱鸡", + "20002": "办卡", + "20003": "飞机", + "20004": "火箭", + "20005": "超级火箭", + "20006": "赞", + "20008": "超大丸星", + "20234": "爱心飞机", + "20387": "心动火箭", + "20417": "福袋", + "20541": "大气", + "20542": "666", + "20618": "魔法戒指", + "20624": "魔法皇冠", + "20626": "幸福券", + "20642": "能量电池", + "20643": "能量水晶", + "20644": "能量戒指", + "20709": "壁咚", + "20710": "金鲨鱼", + "20725": "宠爱卡", + "20726": "挚爱超火", + "20727": "乖乖戴口罩", + "20728": "勤洗手", + "20758": "打弱鸡", + "20760": "风暴超火", + "20761": "风暴火箭", + "20885": "告白书", + "20886": "告白卡", + "20887": "告白飞机", + "20888": "告白火箭", + "20889": "告白超火", + "20900": "小厨娘", + "20914": "开黑券", + "20940": "狂欢卡", + "20941": "狂欢火箭", + "20951": "狂欢趴", + "20952": "狂欢飞机", + "20953": "狂欢超火" +} \ No newline at end of file diff --git a/example/web/host.json b/example/web/host.json new file mode 100644 index 0000000..13ecabc --- /dev/null +++ b/example/web/host.json @@ -0,0 +1 @@ +{"url":"https://a-sh-cn.machine.flxxyz.com/gift.php"} \ No newline at end of file diff --git a/example/web/index.html b/example/web/index.html index 8fd046c..47c728f 100644 --- a/example/web/index.html +++ b/example/web/index.html @@ -5,18 +5,144 @@ 演示页面 + + + -
- - - +
+
+ + + {{ tips }} +
+
+
    + +
-
- - - + + \ No newline at end of file diff --git a/example/web/index.js b/example/web/index.js deleted file mode 100644 index c5034f9..0000000 --- a/example/web/index.js +++ /dev/null @@ -1,115 +0,0 @@ -(function () { - var room = null - var isConn = false - - getId('s').onclick = async function () { - let roomId = getId('roomId').value - - if (roomId && roomId > 0) { - let isExit = await exit() - if (!isExit) { - getId('tips').innerText = '' - newRoom(roomId) - } - } else { - getId('tips').innerText = '请输入正确的房间号' - } - } - - getId('messages').style.height = (document.documentElement.clientHeight - 60) + 'px' - - function getId(el) { - return document.getElementById(el) - } - - function exit() { - return new Promise((resolve, reject) => { - if (isConn) { - room.logout() - isConn = false - resolve(true) - } else { - resolve(false) - } - }) - } - - function insertNode(context) { - var node = document.createElement('li') - node.innerText = context - getId('messages').appendChild(node, null) - document.querySelectorAll('li')[document.querySelectorAll('li').length - 1].scrollIntoView() - } - - function newRoom(roomId) { - room = new douyudanmaku(roomId) - room.on('connect', function () { - console.log('[connect] roomId=%s', this.roomId) - insertNode(`[connect] roomId=${this.roomId}`) - }) - room.on('disconnect', function () { - console.log('[disconnect] roomId=%s', this.roomId) - insertNode(`[disconnect] roomId=${this.roomId}`) - }) - room.on('error', function (err) { - console.log('[error] roomId=%s', this.roomId) - }) - room.on('chatmsg', function (res) { - console.log('[chatmsg]', ` [${res.nn}] ${res.txt}`) - insertNode(`[chatmsg] [${res.nn}] ${res.txt}`) - }) - room.on('loginres', function (res) { - console.log('[loginres]', '登录成功') - insertNode('[loginres] 登录成功') - }) - // room.on('uenter', function (res) { - // console.log('[uenter]', `${res.nn}进入房间`) - // insertNode(`[uenter] ${res.nn}进入房间`) - // }) - room.on('dgb', function (res) { - //斗鱼的礼物过多无法全部记录,20000以后可以判断为鱼翅购买,其他为系统赠送 - const gifts = { - 20000: '鱼丸', - 20001: '弱鸡', - 20002: '办卡', - 20003: '飞机', - 20004: '火箭', - 20005: '超级火箭', - 20006: '赞', - 20008: '超大丸星', - 20234: '爱心飞机', - 20387: '心动火箭', - 20417: '福袋', - 20541: '大气', - 20542: '666', - 20618: '魔法戒指', - 20624: '魔法彩蛋', - 20642: '能量电池', - 20643: '能量水晶', - 20644: '能量戒指', - 20710: '金鲨鱼', - 20725: '宠爱卡', - 20726: '挚爱超火', - 20727: '乖乖戴口罩', - 20728: '勤洗手', - 20885: '告白书', - 20886: '告白卡', - 20887: '告白飞机', - 20888: '告白火箭', - 20889: '告白超火', - 192: '赞(系统)', - 193: '弱鸡(系统)', - 519: '呵呵(系统)', - 520: '稳(系统)', - 712: '棒棒哒(系统)', - 714: '怂(系统)', - 824: '应援棒(系统)', - } - const gift = gifts[res.gfid] || '其他礼物' - console.log('[dgb]', `感谢${res.nn}送出${gift}`, `礼物id=${res.gfid}`) - insertNode(`[dgb] 感谢${res.nn}送出${gift} 礼物id=${res.gfid}`) - }) - room.run() - isConn = true - } -})() \ No newline at end of file