Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 39598
1
###############################################################################
2
#
3
# CoCalc: Collaborative Calculation in the Cloud
4
#
5
# Copyright (C) 2016, Sagemath Inc.
6
#
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#
20
###############################################################################
21
22
23
###
24
#
25
# message=require('message'); c = require('client_node').connect("http://localhost:5000")
26
#
27
###
28
#
29
# NOTE: Automatic reconnect if the server is restarted does not work with this.
30
# It *does* work for client_browser.coffee though, which is what matters.
31
32
client = require('client')
33
34
misc = require('smc-util/misc')
35
36
exports.connect = (url) -> new Connection(url)
37
38
class Connection extends client.Connection
39
_connect: (url, ondata) ->
40
# TODO!!! Rewrite all this using Primus... https://github.com/primus/primus
41
conn = require("sockjs-client-ws").create("#{url}/hub") # note -- https is not supported
42
@_conn = conn
43
conn.on("connection", () =>
44
@_last_pong = misc.walltime()
45
@_connected = true
46
@emit("connected", "websocket")
47
)
48
conn.on("data", ondata)
49
conn.on("error", (err) => @emit("error", err))
50
conn.on("close", () => @emit("close"))
51
52
@_write = (data) -> conn.write(data)
53
54
55