summaryrefslogtreecommitdiffstats
path: root/webchat/sockjs_server_connection_transport.js
blob: 6f68b955b70d15ab97533c468b6b7972950a607a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

module.exports = function make_sockjs_server_connection_transport (connection) {
  var transport = {}

  connection.on('data', function (data) {
    try {
      var message = JSON.parse(data)
    } catch (error) {
      return console.log('error', error)
    }
    transport.onmessage(message)
  })
  connection.on('close', function () {
  })

  transport.send = function (message) {
    try {
      var data = JSON.stringify(message)
    } catch (error) {
      return console.log('sockjs transport send error:', error)
    }
    connection.write(data)
  }

  return transport
}