mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-08 02:37:44 +02:00
Move services to public (#6156)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// Copyright © 2023 Hardcore Engineering Inc.
|
||||
//
|
||||
//
|
||||
|
||||
import client, { ClientSocket } from '@hcengineering/client'
|
||||
import clientResources from '@hcengineering/client-resources'
|
||||
import { Client, ClientConnectEvent } from '@hcengineering/core'
|
||||
import { setMetadata } from '@hcengineering/platform'
|
||||
import { getTransactorEndpoint } from '@hcengineering/server-client'
|
||||
import serverToken, { generateToken } from '@hcengineering/server-token'
|
||||
import WebSocket from 'ws'
|
||||
import config from './config'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function createPlatformClient (
|
||||
workspace: string,
|
||||
productId: string,
|
||||
timeout: number,
|
||||
reconnect?: (event: ClientConnectEvent) => void
|
||||
): Promise<Client> {
|
||||
setMetadata(client.metadata.ClientSocketFactory, (url) => {
|
||||
return new WebSocket(url, {
|
||||
headers: {
|
||||
'User-Agent': config.ServiceID
|
||||
}
|
||||
}) as never as ClientSocket
|
||||
})
|
||||
|
||||
setMetadata(serverToken.metadata.Secret, config.ServerSecret)
|
||||
const token = generateToken(
|
||||
config.SystemEmail,
|
||||
{
|
||||
name: workspace,
|
||||
productId
|
||||
},
|
||||
{ mode: 'github' }
|
||||
)
|
||||
setMetadata(client.metadata.ConnectionTimeout, timeout)
|
||||
const endpoint = await getTransactorEndpoint(token)
|
||||
const connection = await (
|
||||
await clientResources()
|
||||
).function.GetClient(token, endpoint, {
|
||||
onConnect: reconnect
|
||||
})
|
||||
|
||||
return connection
|
||||
}
|
||||
Reference in New Issue
Block a user