-
-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
import asyncio | ||
|
||
import websockets | ||
import websockets.frames | ||
from websockets.server import ServerConnection | ||
|
||
from uvicorn.config import Config | ||
from uvicorn.server import ServerState | ||
|
||
|
||
class WebSocketProtocol(asyncio.Protocol): | ||
def __init__( | ||
self, | ||
config: Config, | ||
server_state: ServerState, | ||
_loop: asyncio.AbstractEventLoop | None = None, | ||
): | ||
self.conn = ServerConnection() | ||
|
||
def data_received(self, data: bytes) -> None: | ||
if data: | ||
self.conn.receive_data(data) | ||
else: | ||
self.conn.receive_eof() | ||
self.handle_events() | ||
|
||
def handle_events(self): | ||
for event in self.conn.events_received(): | ||
if isinstance(event, websockets.frames.Frame): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters