发布 bilibili 扩展库, hp socket ssl websocket 的使用
可以用来获取B站的直播弹幕,顺便演示了 hp socket 网络库中 ssl websocket 的使用
import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=759;bottom=351)
winform.add(
btnConnect={cls="button";text="连接";left=192;top=8;right=272;bottom=48;z=1};
btnStop={cls="button";text="停止";left=304;top=16;right=384;bottom=48;z=5};
edLiveRoomId={cls="edit";text="545068";left=88;top=16;right=160;bottom=48;edge=1;z=2};
listview={cls="listview";left=24;top=64;right=744;bottom=328;edge=1;fullRow=1;gridLines=1;z=4};
static={cls="static";text="直播间id:";left=16;top=16;right=104;bottom=40;transparent=1;z=3}
)
/*}}*/
io.open()
winform.listview.insertColumn("昵称",200)
winform.listview.insertColumn("内容",-1)
import aaz.bilibili.danmu;
import aaz.bilibili.util;
var danmu = aaz.bilibili.danmu()
danmu.on("connect", function(){
winform.btnConnect.disabledText = "已连接"
// 认证成功,开始发送心跳包等任务
danmu.startIntervalTask(10000);
// 开启断线自动重连
// danmu.keepConnect(10000)
})
danmu.on("danmu", function(info){
winform.listview.addItem({info.nick; info.txt})
winform.listview.ensureVisible(winform.listview.count)
})
// 系统回调
danmu.onDisconnect = function(){
winform.btnConnect.disabledText = null
}
winform.btnConnect.oncommand = function(id,event){
var roomId = winform.edLiveRoomId.text;
winform.btnConnect.disabledText = "连接..."
if( !danmu.connect(roomId) ){
winform.btnConnect.disabledText = null
}
}
// 停止
winform.btnStop.oncommand = function(id,event){
danmu.stop()
}
winform.show();
win.loopMessage();
扩展库下载
https://gitcode.net/vmax666/aaz-aardio
登录后方可回帖