OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2022-01-13 4545664bbece1b1b185945376b344b1660669a53
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class WebSocketMock
  constructor: (@url) ->
    @onclose = ->
    @onopen = ->
    @onerror = ->
    @onmessage = ->
    @readyState = 0
    @bufferedAmount = 0
    @extensions = ''
    @protocol = ''
    setTimeout(@handle_open, 0)
  
  # WebSocket API
  
  close: ->
    @handle_close()
    @readyState = 2
   
  send: (msg) ->
    if @readyState isnt 1 then return false
    @handle_send(msg)
    return true
  
  # Helpers
  
  _accept: ->
    @readyState = 1
    @onopen({'type': 'open'})
  
  _shutdown: ->
    @readyState = 3
    @onclose({'type': 'close'})
  
  _error: ->
    @readyState = 3
    @onerror({'type': 'error'})
  
  _respond: (data) ->
    @onmessage({'type': 'message', 'data': data})
    
  # Handlers
  
  handle_send: (msg) ->
    # implement me
  
  handle_close: ->
    # implement me
  
  handle_open: ->
    # implement me
 
exports.WebSocketMock = WebSocketMock