2021-08-06 10:18:50 +00:00
|
|
|
//
|
|
|
|
// Copyright © 2020 Anticrm Platform Contributors.
|
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
2024-04-06 08:14:06 +00:00
|
|
|
import type { AccountClient, ClientConnectEvent, MeasureContext, TxPersistenceStore } from '@hcengineering/core'
|
2022-09-21 08:08:25 +00:00
|
|
|
import type { Plugin, Resource } from '@hcengineering/platform'
|
2023-05-19 11:46:05 +00:00
|
|
|
import { Metadata, plugin } from '@hcengineering/platform'
|
2021-08-06 10:18:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export const clientId = 'client' as Plugin
|
|
|
|
|
2021-12-06 16:57:35 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export type ClientSocketFactory = (url: string) => ClientSocket
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface ClientSocket {
|
|
|
|
onmessage?: ((this: ClientSocket, ev: MessageEvent) => any) | null
|
|
|
|
onclose?: ((this: ClientSocket, ev: CloseEvent) => any) | null
|
|
|
|
onopen?: ((this: ClientSocket, ev: Event) => any) | null
|
|
|
|
onerror?: ((this: ClientSocket, ev: Event) => any) | null
|
|
|
|
|
|
|
|
send: (data: string | ArrayBufferLike | Blob | ArrayBufferView) => void
|
|
|
|
|
2023-03-24 04:53:12 +00:00
|
|
|
close: (code?: number) => void
|
2023-04-13 05:18:35 +00:00
|
|
|
|
|
|
|
readyState: ClientSocketReadyState
|
2024-04-25 15:15:11 +00:00
|
|
|
|
|
|
|
bufferedAmount?: number
|
2023-04-13 05:18:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export enum ClientSocketReadyState {
|
|
|
|
CONNECTING = 0,
|
|
|
|
OPEN = 1,
|
|
|
|
CLOSING = 2,
|
|
|
|
CLOSED = 3
|
2021-12-06 16:57:35 +00:00
|
|
|
}
|
|
|
|
|
2024-07-18 18:04:48 +00:00
|
|
|
export interface ClientFactoryOptions {
|
2024-09-18 03:01:27 +00:00
|
|
|
onHello?: (serverVersion?: string) => boolean
|
2024-07-18 18:04:48 +00:00
|
|
|
onUpgrade?: () => void
|
|
|
|
onUnauthorized?: () => void
|
|
|
|
onConnect?: (event: ClientConnectEvent, data: any) => void
|
|
|
|
ctx?: MeasureContext
|
|
|
|
onDialTimeout?: () => void | Promise<void>
|
|
|
|
}
|
|
|
|
|
2021-11-30 11:11:37 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2024-07-18 18:04:48 +00:00
|
|
|
export type ClientFactory = (token: string, endpoint: string, opt?: ClientFactoryOptions) => Promise<AccountClient>
|
2021-11-30 11:11:37 +00:00
|
|
|
|
2022-04-29 05:27:17 +00:00
|
|
|
export default plugin(clientId, {
|
|
|
|
metadata: {
|
|
|
|
ClientSocketFactory: '' as Metadata<ClientSocketFactory>,
|
2023-04-25 07:34:10 +00:00
|
|
|
FilterModel: '' as Metadata<boolean>,
|
2023-05-10 17:16:13 +00:00
|
|
|
ExtraPlugins: '' as Metadata<Plugin[]>,
|
|
|
|
UseBinaryProtocol: '' as Metadata<boolean>,
|
2024-04-04 04:20:26 +00:00
|
|
|
UseProtocolCompression: '' as Metadata<boolean>,
|
2024-05-30 09:19:23 +00:00
|
|
|
ConnectionTimeout: '' as Metadata<number>,
|
2024-04-04 04:20:26 +00:00
|
|
|
OverridePersistenceStore: '' as Metadata<TxPersistenceStore>
|
2022-04-29 05:27:17 +00:00
|
|
|
},
|
|
|
|
function: {
|
|
|
|
GetClient: '' as Resource<ClientFactory>
|
2023-04-20 10:11:22 +00:00
|
|
|
},
|
|
|
|
event: {
|
|
|
|
NetworkRequests: '' as Metadata<string>
|
2021-08-06 10:18:50 +00:00
|
|
|
}
|
2022-04-29 05:27:17 +00:00
|
|
|
})
|