izuemon commited on
Commit
633f93f
Β·
verified Β·
1 Parent(s): bd44cf4

Update get_msg.py

Browse files
Files changed (1) hide show
  1. get_msg.py +22 -3
get_msg.py CHANGED
@@ -24,6 +24,7 @@ ACCOUNT_WS_URL = (
24
  "wss://account-ws.channel.io/socket.io/"
25
  "?platform=web&EIO=4&transport=websocket"
26
  )
 
27
 
28
  # heartbeat εΏœη­”γ‚’εΎ…γ€γ‚Ώγ‚€γƒ γ‚’γ‚¦γƒˆ
29
  HEARTBEAT_RESPONSE_TIMEOUT = 5.0
@@ -38,7 +39,18 @@ ACCOUNT_RECV_TIMEOUT = 1.0
38
 
39
  JST = timezone(timedelta(hours=9))
40
 
41
-
 
 
 
 
 
 
 
 
 
 
 
42
  # ---------------------------------------------------------------------------
43
  # γƒ­γ‚°η”¨γƒ˜γƒ«γƒ‘
44
  # ---------------------------------------------------------------------------
@@ -458,6 +470,7 @@ def open_channel_ws(session_token: str, channel_id: str) -> LoggingWS:
458
 
459
  # Engine.IO open を待ってから connect を送る
460
  deadline = time.monotonic() + REQUEST_TIMEOUT
 
461
  while time.monotonic() < deadline:
462
  try:
463
  packet = ws.recv()
@@ -468,12 +481,18 @@ def open_channel_ws(session_token: str, channel_id: str) -> LoggingWS:
468
  if packet.startswith("0"):
469
  log("SOCKET", "Channel Engine.IO open γƒ‘γ‚±γƒƒγƒˆγ‚’ε—δΏ‘γ—γΎγ—γŸγ€‚")
470
  send_channel_connect(ws, session_token, channel_id)
471
- return ws
 
472
  if packet == "2":
473
  send_pong(ws)
474
  continue
 
 
 
 
 
475
  log("SOCKET", f"Channel ζŽ₯ηΆšεΎ…ζ©ŸδΈ­γ«ε—δΏ‘: {packet!r}")
476
- raise TimeoutError("Channel Engine.IO open γƒ‘γ‚±γƒƒγƒˆγ‚’ε—δΏ‘γ§γγΎγ›γ‚“γ§γ—γŸγ€‚")
477
 
478
 
479
  def open_account_ws(session_token: str) -> LoggingWS:
 
24
  "wss://account-ws.channel.io/socket.io/"
25
  "?platform=web&EIO=4&transport=websocket"
26
  )
27
+ GROUP_PATH = os.getenv("CW_GROUP_ID", "/groups/574628")
28
 
29
  # heartbeat εΏœη­”γ‚’εΎ…γ€γ‚Ώγ‚€γƒ γ‚’γ‚¦γƒˆ
30
  HEARTBEAT_RESPONSE_TIMEOUT = 5.0
 
39
 
40
  JST = timezone(timedelta(hours=9))
41
 
42
+ def send_join_group(ws: LoggingWS, group_path: str) -> None:
43
+ message = (
44
+ '42/desk/channel,'
45
+ + json.dumps(
46
+ ["join", group_path],
47
+ ensure_ascii=False,
48
+ separators=(",", ":"),
49
+ )
50
+ )
51
+ log("SOCKET", f"join 送俑: {group_path}")
52
+ ws.send(message)
53
+
54
  # ---------------------------------------------------------------------------
55
  # γƒ­γ‚°η”¨γƒ˜γƒ«γƒ‘
56
  # ---------------------------------------------------------------------------
 
470
 
471
  # Engine.IO open を待ってから connect を送る
472
  deadline = time.monotonic() + REQUEST_TIMEOUT
473
+ connect_sent = False
474
  while time.monotonic() < deadline:
475
  try:
476
  packet = ws.recv()
 
481
  if packet.startswith("0"):
482
  log("SOCKET", "Channel Engine.IO open γƒ‘γ‚±γƒƒγƒˆγ‚’ε—δΏ‘γ—γΎγ—γŸγ€‚")
483
  send_channel_connect(ws, session_token, channel_id)
484
+ connect_sent = True
485
+ continue
486
  if packet == "2":
487
  send_pong(ws)
488
  continue
489
+ # connect εΏœη­”εΎ…γ‘: 40/desk/channel,{"sid":"..."}
490
+ if connect_sent and packet.startswith("40/desk/channel,"):
491
+ log("SOCKET", "Channel connect εΏœη­” (sid) γ‚’ε—δΏ‘γ—γΎγ—γŸγ€‚")
492
+ send_join_group(ws, GROUP_PATH)
493
+ return ws
494
  log("SOCKET", f"Channel ζŽ₯ηΆšεΎ…ζ©ŸδΈ­γ«ε—δΏ‘: {packet!r}")
495
+ raise TimeoutError("Channel connect εΏœη­”γ‚’ε—δΏ‘γ§γγΎγ›γ‚“γ§γ—γŸγ€‚")
496
 
497
 
498
  def open_account_ws(session_token: str) -> LoggingWS: