rhine-var
Version:
Variables that support multi-user collaboration and persistence, making collaboration and variable operations as simple as possible, with strict and well-defined type hints.
30 lines (29 loc) • 1.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_PUBLIC_URL = exports.PROTOCOL_LIST = void 0;
exports.createConnector = createConnector;
const hocuspocus_connector_class_1 = __importDefault(require("./hocuspocus/hocuspocus-connector.class"));
exports.PROTOCOL_LIST = ['ws://', 'wss://'];
exports.DEFAULT_PUBLIC_URL = 'wss://rvp.rhineai.com/';
function createConnector(connectorText, token) {
var _a;
let text = String(connectorText);
// Connector is String but not start with protocol
if (exports.PROTOCOL_LIST.every((protocol) => !text.startsWith(protocol))) {
// Default to use public url
text = exports.DEFAULT_PUBLIC_URL + text;
}
// Use HocuspocusConnector by default
const connector = new hocuspocus_connector_class_1.default();
// const connector = new WebsocketConnector(text)
// Environment check
const isBrowser = typeof window !== 'undefined';
const isNode = typeof process !== 'undefined' && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
if (isBrowser || isNode) {
connector.connect(text, token);
}
return connector;
}