###############################################################################1#2# CoCalc: Collaborative Calculation in the Cloud3#4# Copyright (C) 2016, Sagemath Inc.5#6# This program is free software: you can redistribute it and/or modify7# it under the terms of the GNU General Public License as published by8# the Free Software Foundation, either version 3 of the License, or9# (at your option) any later version.10#11# This program is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14# GNU General Public License for more details.15#16# You should have received a copy of the GNU General Public License17# along with this program. If not, see <http://www.gnu.org/licenses/>.18#19###############################################################################202122###23#24# message=require('message'); c = require('client_node').connect("http://localhost:5000")25#26###27#28# NOTE: Automatic reconnect if the server is restarted does not work with this.29# It *does* work for client_browser.coffee though, which is what matters.3031client = require('client')3233misc = require('smc-util/misc')3435exports.connect = (url) -> new Connection(url)3637class Connection extends client.Connection38_connect: (url, ondata) ->39# TODO!!! Rewrite all this using Primus... https://github.com/primus/primus40conn = require("sockjs-client-ws").create("#{url}/hub") # note -- https is not supported41@_conn = conn42conn.on("connection", () =>43@_last_pong = misc.walltime()44@_connected = true45@emit("connected", "websocket")46)47conn.on("data", ondata)48conn.on("error", (err) => @emit("error", err))49conn.on("close", () => @emit("close"))5051@_write = (data) -> conn.write(data)52535455