2021-12-10 09:47:54 +00:00
|
|
|
import client from '@anticrm/client'
|
|
|
|
import clientResources from '@anticrm/client-resources'
|
|
|
|
import { Client } from '@anticrm/core'
|
|
|
|
import { setMetadata } from '@anticrm/platform'
|
2022-01-27 08:53:09 +00:00
|
|
|
import { generateToken } from '@anticrm/server-token'
|
2021-12-10 09:47:54 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line
|
|
|
|
const WebSocket = require('ws')
|
|
|
|
|
|
|
|
export async function connect (transactorUrl: string, workspace: string): Promise<Client> {
|
|
|
|
console.log('connecting to transactor...')
|
2022-01-27 08:53:09 +00:00
|
|
|
const token = generateToken('anticrm@hc.engineering', workspace)
|
2021-12-10 09:47:54 +00:00
|
|
|
|
|
|
|
// We need to override default factory with 'ws' one.
|
|
|
|
setMetadata(client.metadata.ClientSocketFactory, (url) => new WebSocket(url))
|
|
|
|
return await (await clientResources()).function.GetClient(token, transactorUrl)
|
|
|
|
}
|