Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/project/project-info/project-info.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Project information7*/89import { ProjectInfoCmds } from "@cocalc/util/types/project-info/types";10import { ProjectInfoServer } from "./server";11import { exec } from "./utils";1213// singleton, we instantiate it when we need it14let _info: ProjectInfoServer | undefined = undefined;1516export function get_ProjectInfoServer(): ProjectInfoServer {17if (_info != null) return _info;18_info = new ProjectInfoServer();19return _info;20}2122export async function project_info_ws(23primus: any,24logger: { debug: Function }25): Promise<string> {26const L = (...msg) => logger.debug("project_info:", ...msg);27const name = `project_info`;28const channel = primus.channel(name);2930function deregister(spark) {31L(`deregistering ${spark.id}`);32}3334channel.on("connection", function (spark: any): void {35// Now handle the connection36L(`channel: new connection from ${spark.address.ip} -- ${spark.id}`);3738function close(type) {39L(`event ${type}: deregistering`);40deregister(spark);41}4243spark.on("close", () => close("close"));44spark.on("end", () => close("end"));45spark.on("data", function (data: ProjectInfoCmds) {46// we assume only ProjectInfoCmds should come in, but better check what this is47if (typeof data === "object") {48switch (data.cmd) {49case "signal":50L(`Signal ${data.signal} from ${spark.id} for pids: ${data.pids}`);51exec(`kill -s ${data.signal ?? 15} ${data.pids.join(" ")}`);52break;53default:54throw Error("WARNING: unknown command -- " + data.cmd);55}56}57});58});5960channel.on("disconnection", function (spark: any): void {61L(`channel: disconnection from ${spark.address.ip} -- ${spark.id}`);62deregister(spark);63});6465return name;66}676869