完成插件和blivechat连接

This commit is contained in:
John Smith
2023-11-05 16:29:11 +08:00
parent f886506c39
commit b0b38bf0f0
12 changed files with 893 additions and 1 deletions

View File

@@ -10,7 +10,10 @@ import subprocess
from typing import *
import api.plugin
import blcsdk
import blcsdk.models as sdk_models
import config
import update
logger = logging.getLogger(__name__)
@@ -233,12 +236,20 @@ class Plugin:
if self._client is client:
return
if self._client is not None:
logger.info('plugin=%s closing old client', self._id)
self._client.close()
self._client = client
def on_client_connect(self, client: 'api.plugin.PluginWsHandler'):
self._set_client(client)
# 发送初始化消息
self.send_cmd_data(sdk_models.Command.BLC_INIT, {
'blcVersion': update.VERSION,
'sdkVersion': blcsdk.__version__,
'pluginId': self._id,
})
def on_client_close(self, client: 'api.plugin.PluginWsHandler'):
if self._client is client:
self._set_client(None)