Skip to content

Commit 0e1f232

Browse files
use Socket.IO sid in transport() method (Fixes #1299)
1 parent 1e2aa6e commit 0e1f232

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/socketio/base_server.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,18 @@ def rooms(self, sid, namespace=None):
187187
namespace = namespace or '/'
188188
return self.manager.get_rooms(sid, namespace)
189189

190-
def transport(self, sid):
190+
def transport(self, sid, namespace=None):
191191
"""Return the name of the transport used by the client.
192192
193193
The two possible values returned by this function are ``'polling'``
194194
and ``'websocket'``.
195195
196196
:param sid: The session of the client.
197+
:param namespace: The Socket.IO namespace. If this argument is omitted
198+
the default namespace is used.
197199
"""
198-
return self.eio.transport(sid)
200+
eio_sid = self.manager.eio_sid_from_sid(sid, namespace or '/')
201+
return self.eio.transport(eio_sid)
199202

200203
def get_environ(self, sid, namespace=None):
201204
"""Return the WSGI environ dictionary for a client.

tests/async/test_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ def test_transport(self, eio):
307307
eio.return_value.send = AsyncMock()
308308
s = async_server.AsyncServer()
309309
s.eio.transport = mock.MagicMock(return_value='polling')
310-
_run(s._handle_eio_connect('foo', 'environ'))
311-
assert s.transport('foo') == 'polling'
312-
s.eio.transport.assert_called_once_with('foo')
310+
sid_foo = _run(s.manager.connect('123', '/foo'))
311+
assert s.transport(sid_foo, '/foo') == 'polling'
312+
s.eio.transport.assert_called_once_with('123')
313313

314314
def test_handle_connect(self, eio):
315315
eio.return_value.send = AsyncMock()

tests/common/test_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ def test_send_eio_packet(self, eio):
292292
def test_transport(self, eio):
293293
s = server.Server()
294294
s.eio.transport = mock.MagicMock(return_value='polling')
295-
s._handle_eio_connect('foo', 'environ')
296-
assert s.transport('foo') == 'polling'
297-
s.eio.transport.assert_called_once_with('foo')
295+
sid_foo = s.manager.connect('123', '/foo')
296+
assert s.transport(sid_foo, '/foo') == 'polling'
297+
s.eio.transport.assert_called_once_with('123')
298298

299299
def test_handle_connect(self, eio):
300300
s = server.Server()

0 commit comments

Comments
 (0)