浏览代码

PM

master
Roderic Day 5 年前
父节点
当前提交
eaca1c85b7
共有 3 个文件被更改,包括 41 次插入1 次删除
  1. +11
    -0
      pico.js
  2. +5
    -1
      pico.py
  3. +25
    -0
      test.py

+ 11
- 0
pico.js 查看文件

posts: [], posts: [],
users: [], users: [],
} }

/*
*
* GUI
*
*/
const autoFocus = (vnode) => { const autoFocus = (vnode) => {
vnode.dom.focus() vnode.dom.focus()
} }
} }
m.mount(document.body, Main) m.mount(document.body, Main)


/*
*
* WEBSOCKETS
*
*/
const connect = (username) => { const connect = (username) => {
const wsUrl = location.href.replace('http', 'ws') const wsUrl = location.href.replace('http', 'ws')



+ 5
- 1
pico.py 查看文件

text = data['text'] text = data['text']
if not text: if not text:
continue continue
await broadcast(kind='post', source=ws.username, text=text)
elif 'target' in data:
targets = {ss for ss in sockets if ss.username in {ws.username, data['target']}}
await send_json_many(ts=ts, targets=targets, kind='post', source=ws.username, text=text)
else:
await broadcast(kind='post', source=ws.username, text=text)


elif data['action'] == 'logout': elif data['action'] == 'logout':
sockets.discard(ws) sockets.discard(ws)

+ 25
- 0
test.py 查看文件

return _test(client1, client2) return _test(client1, client2)




def test_private_message():
client1 = _make_client('ws://localhost:8642/', 0.10, Script()
+ {'action': 'login', 'username': 'Norman'}
- {'kind': 'update', 'users': ['Norman'], 'info': 'Welcome to /', 'username': 'Norman'}
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Ray joined'}
- {'kind': 'update', 'users': ['Emma', 'Norman', 'Ray'], 'info': 'Emma joined'}
+ {'action': 'post', 'target': 'Emma', 'text': 'なに?'}
- {'kind': 'post', 'source': 'Norman', 'text': 'なに?'}
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Emma left'}
)
client2 = _make_client('ws://localhost:8642/', 0.11, Script()
+ {'action': 'login', 'username': 'Ray'}
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Welcome to /', 'username': 'Ray'}
- {'kind': 'update', 'users': ['Emma', 'Norman', 'Ray'], 'info': 'Emma joined'}
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Emma left'}
- {'kind': 'update', 'users': ['Ray'], 'info': 'Norman left'}
)
client3 = _make_client('ws://localhost:8642/', 0.12, Script()
+ {'action': 'login', 'username': 'Emma'}
- {'kind': 'update', 'users': ['Emma', 'Norman', 'Ray'], 'info': 'Welcome to /', 'username': 'Emma'}
- {'kind': 'post', 'source': 'Norman', 'text': 'なに?'}
)
return _test(client1, client2, client3)


if __name__ == '__main__': if __name__ == '__main__':
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
for fn_name, fn in list(locals().items()): for fn_name, fn in list(locals().items()):

正在加载...
取消
保存