mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-23 23:38:21 +00:00
parent
ab38edf7ca
commit
147bb8758a
@ -16,14 +16,25 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import asyncio
|
||||
import aiohttp.errors
|
||||
|
||||
from aiohttp.web import WebSocketResponse
|
||||
from gns3server.web.route import Route
|
||||
from gns3server.compute.notification_manager import NotificationManager
|
||||
|
||||
|
||||
class NotificationHandler:
|
||||
@asyncio.coroutine
|
||||
def process_websocket(ws):
|
||||
"""
|
||||
Process ping / pong and close message
|
||||
"""
|
||||
try:
|
||||
yield from ws.receive()
|
||||
except aiohttp.errors.WSServerHandshakeError:
|
||||
pass
|
||||
|
||||
|
||||
class NotificationHandler:
|
||||
@Route.get(
|
||||
r"/notifications/ws",
|
||||
description="Send notifications using Websockets")
|
||||
@ -32,8 +43,7 @@ class NotificationHandler:
|
||||
ws = WebSocketResponse()
|
||||
yield from ws.prepare(request)
|
||||
|
||||
# Process ping / pong and close message
|
||||
asyncio.async(ws.receive())
|
||||
asyncio.async(process_websocket(ws))
|
||||
|
||||
with notifications.queue() as queue:
|
||||
while True:
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import os
|
||||
import aiohttp
|
||||
import aiohttp.errors
|
||||
import asyncio
|
||||
import tempfile
|
||||
|
||||
@ -39,6 +40,17 @@ import logging
|
||||
log = logging.getLogger()
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def process_websocket(ws):
|
||||
"""
|
||||
Process ping / pong and close message
|
||||
"""
|
||||
try:
|
||||
yield from ws.receive()
|
||||
except aiohttp.errors.WSServerHandshakeError:
|
||||
pass
|
||||
|
||||
|
||||
class ProjectHandler:
|
||||
|
||||
@Route.post(
|
||||
@ -238,8 +250,7 @@ class ProjectHandler:
|
||||
ws = aiohttp.web.WebSocketResponse()
|
||||
yield from ws.prepare(request)
|
||||
|
||||
# Process ping / pong and close message
|
||||
asyncio.async(ws.receive())
|
||||
asyncio.async(process_websocket(ws))
|
||||
|
||||
with controller.notification.queue(project) as queue:
|
||||
while True:
|
||||
|
Loading…
Reference in New Issue
Block a user