open-collaboration-service-process
Version:
A service process for integrating non Typescript projects with the Open Collaboration Tools project
93 lines • 4.13 kB
JavaScript
// ******************************************************************************
// Copyright 2024 TypeFox GmbH
// This program and the accompanying materials are made available under the
// terms of the MIT License, which is available in the project root.
// ******************************************************************************
import * as types from 'open-collaboration-protocol';
import { Encoding } from 'open-collaboration-protocol';
import { NotificationType, NotificationType2, NotificationType3, RequestType } from 'vscode-jsonrpc';
export function isOCPMessage(message) {
return types.isObject(message) && types.isString(message.method) && types.isArray(message.params);
}
// ***************************** generic messages *****************************
// all params can be either msgpack encoded base64 strings of OCPMessages or just directly OCPMessages
export const OCPRequest = new RequestType('request');
export const OCPNotification = new NotificationType('notification');
export const OCPBroadCast = new NotificationType('broadcast');
export function fromEncodedOCPMessage(encoded) {
return Encoding.decode(Uint8Array.from(Buffer.from(encoded, 'base64')));
}
export function toEncodedOCPMessage(message) {
return Buffer.from(Encoding.encode(message)).toString('base64');
}
// ***************************** To service process *****************************
export var ToServiceMessages;
(function (ToServiceMessages) {
ToServiceMessages.LOGIN = 'login';
ToServiceMessages.JOIN_ROOM = 'room/joinRoom';
ToServiceMessages.JOIN_SESSION_REQUEST = 'room/joinSessionRequest';
ToServiceMessages.CREATE_ROOM = 'room/createRoom';
ToServiceMessages.CLOSE_SESSION = 'room/closeSession';
ToServiceMessages.OPEN_DOCUMENT = 'awareness/openDocument';
ToServiceMessages.UPDATE_TEXT_SELECTION = 'awareness/updateTextSelection';
ToServiceMessages.UPDATE_DOCUMENT_CONTENT = 'awareness/updateDocument';
})(ToServiceMessages || (ToServiceMessages = {}));
/**
* resp params: [token]
*/
export const LoginRequest = new RequestType(ToServiceMessages.LOGIN);
/**
* params: [roomId]
* resp params: [roomToken, roomId]
*/
export const JoinRoomRequest = new RequestType(ToServiceMessages.JOIN_ROOM);
/**
* params: [workspace]
* resp params: [roomId, roomToken]
*/
export const CreateRoomRequest = new RequestType(ToServiceMessages.CREATE_ROOM);
export const CloseSessionRequest = new RequestType(ToServiceMessages.CLOSE_SESSION);
/**
* params: [type, documentUri, text]
* Todo: add more types for other awarness object types
*/
export const OpenDocument = new NotificationType3(ToServiceMessages.OPEN_DOCUMENT);
/**
* params: [documentPath, selections]
*/
export const UpdateTextSelection = new NotificationType2(ToServiceMessages.UPDATE_TEXT_SELECTION);
/**
* params: [documentPath, changes]
* Todo: add more types for other awarness object types
*/
export const UpdateDocumentContent = new NotificationType2(ToServiceMessages.UPDATE_DOCUMENT_CONTENT);
// ***************************** From service process ********************************
/**
* A request to the application to open the provided URL
* the token can be used to authenticate the user
* params: [token]
*/
export const Authentication = new NotificationType2('authentication');
/**
* A notification to the application when a session has been joined or created
* params: [init data of the session]
*/
export const OnInitNotification = new NotificationType('init');
/**
* A request to the application to allow a user to join the current session
* params: [user]
* resp params: [join accepted]
*/
export const JoinSessionRequest = new RequestType(ToServiceMessages.JOIN_SESSION_REQUEST);
/**
* params: [error message, stack trace]
*/
export const InternalError = new NotificationType('error');
export var BinaryResponse;
(function (BinaryResponse) {
function is(message) {
return types.isObject(message) && types.isString(message.data) && message.type === 'binaryResponse';
}
BinaryResponse.is = is;
})(BinaryResponse || (BinaryResponse = {}));
//# sourceMappingURL=messages.js.map