import initHeartbeat from "./heartbeat" ; import handleBlob from "./handle-blob" ; import handleMessage from "./handle-message" ; import getLogger from "@cocalc/backend/logger" ; const logger = getLogger ( "project-connection:initialize" ) ; const { enable_mesg } = require ( "@cocalc/backend/misc_node" ) ; export default function initialize ( project_id , socket ) { logger . info ( "initializing socket" ) ; enable_mesg ( socket , "connection_to_a_local_hub" ) ; socket . on ( "mesg" , ( type , mesg ) => { switch ( type ) { case "blob" : handleBlob ( { socket , project_id , uuid : mesg . uuid , blob : mesg . blob } ) ; return ; case "json" : handleMessage ( { socket , project_id , mesg } ) ; return ; default : logger . warn ( "WARNING: unknown message type" , type ) ; } } ) ; socket . write_mesg ( "json" , { event : "hello" } ) ; initHeartbeat ( socket ) ; }