Subversion Repositories HomeAutomation

Rev

Rev 1962 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1962 Rev 1986
Line 3... Line 3...
3
 
3
 
4
var SOCKET_STATE_CONNECTED      = 0x00;
4
var SOCKET_STATE_CONNECTED      = 0x00;
5
var SOCKET_STATE_DISCONNECTED   = 0x01;
5
var SOCKET_STATE_DISCONNECTED   = 0x01;
6
var SOCKET_STATE_ACCEPTED       = 0x02;
6
var SOCKET_STATE_ACCEPTED       = 0x02;
7
 
7
 
8
function Socket_OnNewData(socket_id, server_id, data)
8
function Socket_OnNewData(id, data)
9
{
9
{
10
  var id = socket_id;
-
 
11
 
-
 
12
  if (!Socket_Connections[id])
-
 
13
  {
-
 
14
    id = server_id;
-
 
15
  }
-
 
16
 
-
 
17
  if (Socket_Connections[id])
10
  if (Socket_Connections[id])
18
  {
11
  {
19
    Socket_Connections[id]["ondata"](id, data);
12
    Socket_Connections[id]["ondata"](id, data);
20
  }
13
  }
-
 
14
 
-
 
15
  return true;
-
 
16
}
-
 
17
 
-
 
18
function Socket_OnNewClient(id, server_id)
-
 
19
{
-
 
20
  if (Socket_Connections[server_id])
-
 
21
  {
-
 
22
    Socket_Connections[id] = { "ondata" : Socket_Connections[server_id]["ondata"], "onstate" : Socket_Connections[server_id]["onstate"] };
-
 
23
   
-
 
24
    Socket_Connections[server_id]["onaccept"](id, server_id);
-
 
25
  }
21
 
26
 
22
  return true;
27
  return true;
23
}
28
}
24
 
29
 
25
function Socket_OnNewState(socket_id, server_id, state)
30
function Socket_OnNewState(id, state)
26
{
31
{
27
  var id = socket_id;
-
 
28
 
-
 
29
  if (!Socket_Connections[id])
-
 
30
  {
-
 
31
    id = server_id;
-
 
32
  }
-
 
33
 
-
 
34
  if (Socket_Connections[id])
32
  if (Socket_Connections[id])
35
  {
33
  {
36
    Socket_Connections[id]["onstate"](id, state);
34
    Socket_Connections[id]["onstate"](id, state);
37
   
35
   
38
    if (state == SOCKET_STATE_DISCONNECTED)
36
    if (state == SOCKET_STATE_DISCONNECTED)
Line 42... Line 40...
42
  }
40
  }
43
 
41
 
44
  return true;
42
  return true;
45
}
43
}
46
 
44
 
47
function Socket_StartServer(port, ondata_callback, onstate_callback)
45
function Socket_StartServer(port, onaccept_callback, ondata_callback, onstate_callback)
48
{
46
{
49
  socket_id = SocketExport_StartServer(port);
47
  socket_id = SocketExport_StartServer(port);
50
 
48
 
51
  if (socket_id > 0)
49
  if (socket_id > 0)
52
  {
50
  {
53
    Socket_Connections[socket_id] = { "ondata" : ondata_callback, "onstate" : onstate_callback };
51
    Socket_Connections[socket_id] = { "onaccept" : onaccept_callback, "ondata" : ondata_callback, "onstate" : onstate_callback };
54
  }
52
  }
55
 
53
 
56
  return socket_id;
54
  return socket_id;
57
}
55
}
58
 
56