Skip to content

Commit

Permalink
Fix message.type attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Mar 5, 2018
1 parent 0f93822 commit 0c27b94
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
10 changes: 1 addition & 9 deletions examples/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,4 @@ def index(request):
app.router.add_route('GET', '/', index)
sockjs.add_endpoint(app, chat_msg_handler, name='chat', prefix='/sockjs/')

handler = app.make_handler()
srv = loop.run_until_complete(
loop.create_server(handler, '127.0.0.1', 8080))
print("Server started at http://127.0.0.1:8080")
try:
loop.run_forever()
except KeyboardInterrupt:
srv.close()
loop.run_until_complete(handler.finish_connections())
web.run_app(app)
19 changes: 4 additions & 15 deletions sockjs-testsrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@
from sockjs.transports.xhrstreaming import XHRStreamingTransport


@asyncio.coroutine
def echoSession(msg, session):
async def echoSession(msg, session):
if msg.type == sockjs.MSG_MESSAGE:
session.send(msg.data)


@asyncio.coroutine
def closeSessionHander(msg, session):
async def closeSessionHander(msg, session):
if msg.type == sockjs.MSG_OPEN:
session.close()


@asyncio.coroutine
def broadcastSession(msg, session):
async def broadcastSession(msg, session):
if msg.type == sockjs.MSG_OPEN:
session.manager.broadcast(msg.data)

Expand Down Expand Up @@ -51,12 +48,4 @@ def broadcastSession(msg, session):
app, echoSession, name='cookie', prefix='/cookie_needed_echo',
cookie_needed=True)

handler = app.make_handler()
srv = loop.run_until_complete(
loop.create_server(handler, '127.0.0.1', 8081))
print("Server started at http://127.0.0.1:8081")
try:
loop.run_forever()
except KeyboardInterrupt:
srv.close()
loop.run_until_complete(handler.finish_connections())
web.run_app(app)
5 changes: 4 additions & 1 deletion sockjs/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def messages_frame(messages):
MSG_CLOSED = 4


SockjsMessage = collections.namedtuple('SockjsMessage', ['tp', 'data'])
class SockjsMessage(collections.namedtuple('SockjsMessage', ['type', 'data'])):
@property
def tp(self):
return self.type

OpenMessage = SockjsMessage(MSG_OPEN, None)
CloseMessage = SockjsMessage(MSG_CLOSE, None)
Expand Down

0 comments on commit 0c27b94

Please sign in to comment.