Add config for custom device name
This commit is contained in:
parent
163c1c2125
commit
eebcef6b08
|
@ -67,6 +67,8 @@ class Config(BaseBridgeConfig):
|
||||||
copy("metrics.enabled")
|
copy("metrics.enabled")
|
||||||
copy("metrics.listen_port")
|
copy("metrics.listen_port")
|
||||||
|
|
||||||
|
copy("kakaotalk.device_name")
|
||||||
|
|
||||||
copy("bridge.username_template")
|
copy("bridge.username_template")
|
||||||
copy("bridge.displayname_template")
|
copy("bridge.displayname_template")
|
||||||
copy("bridge.displayname_preference")
|
copy("bridge.displayname_preference")
|
||||||
|
|
|
@ -83,6 +83,10 @@ manhole:
|
||||||
whitelist:
|
whitelist:
|
||||||
- 0
|
- 0
|
||||||
|
|
||||||
|
# Config for things that are directly sent to KakaoTalk.
|
||||||
|
kakaotalk:
|
||||||
|
device_name: "KakaoTalk Bridge"
|
||||||
|
|
||||||
# Bridge config
|
# Bridge config
|
||||||
bridge:
|
bridge:
|
||||||
# Localpart template of MXIDs for KakaoTalk users.
|
# Localpart template of MXIDs for KakaoTalk users.
|
||||||
|
|
|
@ -91,7 +91,7 @@ class Client:
|
||||||
@classmethod
|
@classmethod
|
||||||
def init_cls(cls, config: Config) -> None:
|
def init_cls(cls, config: Config) -> None:
|
||||||
"""Initialize RPC to the Node backend."""
|
"""Initialize RPC to the Node backend."""
|
||||||
cls._rpc_client = RPCClient(config)
|
cls._rpc_client = RPCClient(config, "kakaotalk")
|
||||||
# NOTE No need to store this, as cancelling the RPCClient will cancel this too
|
# NOTE No need to store this, as cancelling the RPCClient will cancel this too
|
||||||
asyncio.create_task(cls._keep_connected())
|
asyncio.create_task(cls._keep_connected())
|
||||||
|
|
||||||
|
|
|
@ -87,8 +87,9 @@ class RPCClient:
|
||||||
_is_disconnected: CancelableEvent
|
_is_disconnected: CancelableEvent
|
||||||
_connection_lock: asyncio.Lock
|
_connection_lock: asyncio.Lock
|
||||||
|
|
||||||
def __init__(self, config: Config) -> None:
|
def __init__(self, config: Config, register_config_key: str) -> None:
|
||||||
self.config = config
|
self.config = config
|
||||||
|
self.register_config_key = register_config_key
|
||||||
self.loop = asyncio.get_running_loop()
|
self.loop = asyncio.get_running_loop()
|
||||||
self._req_id = 0
|
self._req_id = 0
|
||||||
self._min_broadcast_id = 0
|
self._min_broadcast_id = 0
|
||||||
|
@ -144,7 +145,9 @@ class RPCClient:
|
||||||
self._reader = r
|
self._reader = r
|
||||||
self._writer = w
|
self._writer = w
|
||||||
self._read_task = self.loop.create_task(self._try_read_loop())
|
self._read_task = self.loop.create_task(self._try_read_loop())
|
||||||
await self._raw_request("register", peer_id=self.config["appservice.address"])
|
await self._raw_request("register",
|
||||||
|
peer_id=self.config["appservice.address"],
|
||||||
|
register_config=self.config[self.register_config_key])
|
||||||
self._is_connected.set()
|
self._is_connected.set()
|
||||||
self._is_disconnected.clear()
|
self._is_disconnected.clear()
|
||||||
|
|
||||||
|
|
|
@ -362,6 +362,7 @@ export default class PeerClient {
|
||||||
this.notificationID = 0
|
this.notificationID = 0
|
||||||
this.maxCommandID = 0
|
this.maxCommandID = 0
|
||||||
this.peerID = null
|
this.peerID = null
|
||||||
|
this.deviceName = "KakaoTalk Bridge"
|
||||||
|
|
||||||
/** @type {Map<string, UserClient>} */
|
/** @type {Map<string, UserClient>} */
|
||||||
this.userClients = new Map()
|
this.userClients = new Map()
|
||||||
|
@ -480,7 +481,7 @@ export default class PeerClient {
|
||||||
* @param {string} uuid
|
* @param {string} uuid
|
||||||
*/
|
*/
|
||||||
async #createAuthClient(uuid) {
|
async #createAuthClient(uuid) {
|
||||||
return await AuthApiClient.create("KakaoTalk Bridge", uuid)
|
return await AuthApiClient.create(this.deviceName, uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Wrapper for per-user commands
|
// TODO Wrapper for per-user commands
|
||||||
|
@ -865,9 +866,12 @@ export default class PeerClient {
|
||||||
/**
|
/**
|
||||||
* @param {Object} req
|
* @param {Object} req
|
||||||
* @param {string} req.peer_id
|
* @param {string} req.peer_id
|
||||||
|
* @param {Object} req.register_config
|
||||||
|
* @param {string} req.register_config.device_name
|
||||||
*/
|
*/
|
||||||
handleRegister = async (req) => {
|
handleRegister = async (req) => {
|
||||||
this.peerID = req.peer_id
|
this.peerID = req.peer_id
|
||||||
|
this.deviceName = req.register_config.device_name || this.deviceName
|
||||||
this.log(`Registered socket ${this.connID} -> ${this.peerID}`)
|
this.log(`Registered socket ${this.connID} -> ${this.peerID}`)
|
||||||
if (this.manager.clients.has(this.peerID)) {
|
if (this.manager.clients.has(this.peerID)) {
|
||||||
const oldClient = this.manager.clients.get(this.peerID)
|
const oldClient = this.manager.clients.get(this.peerID)
|
||||||
|
|
Loading…
Reference in New Issue