Coder Social home page Coder Social logo

Comments (10)

junshenshi avatar junshenshi commented on September 1, 2024 1

ok 谢谢

from laravel-swoole.

albertcht avatar albertcht commented on September 1, 2024

Hi @junshenshi ,

請問您的編號 1 是發送者的 fd 嗎?如果是的話 Websocket::broadcast()->to(1) 是無法送達的,因為 broadcast 代表要送給除了自己以外的人

from laravel-swoole.

junshenshi avatar junshenshi commented on September 1, 2024

hai Albert
不是发送给自身,
同样是发送给$to
只有原生方法成功
截图体现了to方法不行

from laravel-swoole.

albertcht avatar albertcht commented on September 1, 2024

Hi @junshenshi ,

我的意思是你無法發送的狀況下發送者 fd接收者 fd是相同的嗎?
發送者 fd接收者 fd相同時又使用了 broadcast 該筆發送會被忽略
再和你確認一次:

Websocket::to(1)->emit('message', 'for your eyes only');

你上面這樣寫是可以發送的嗎?

我剛剛自己測試了一下,發送邏輯是正常的

from laravel-swoole.

junshenshi avatar junshenshi commented on September 1, 2024

发现原因,to()方法需要传整型,字符串的fd无法触发。

from laravel-swoole.

albertcht avatar albertcht commented on September 1, 2024

沒錯,to() 方法的參數當傳入整數會被判斷為 fd,字串會被判斷為房間名稱
這樣的設計是延用自 socket.io 的設計方式
但對於字串型別的 fd 我可能要考慮下該如何兼容

from laravel-swoole.

junshenshi avatar junshenshi commented on September 1, 2024

OK 好了,我强制转换了。考虑下要不要把发送方法to切分为fd发送,room发送两个方法,fd发送可以传数组,因为有个场景大概是同一个用户,打开多个窗口拥有多个fd。我用循环解决了多fd,如果能传数组那更好了。

from laravel-swoole.

albertcht avatar albertcht commented on September 1, 2024

其實 websocket 現有的 api 除了有 to 之外,另外有 toAll 的方法是支援 array 的
但我現在可能會想將 toAll 合併至 to 讓他同時支援單或多個 fd 傳入
關於 to 是否會分成兩個方法來區分房間和 fd 我會仔細考慮一下,感謝你的建議

from laravel-swoole.

junshenshi avatar junshenshi commented on September 1, 2024

Ok 谢谢

from laravel-swoole.

albertcht avatar albertcht commented on September 1, 2024

Hi @junshenshi ,

在新版的程式中我已經將 websocket 和 room 中原本含有 All 名稱的方法全數移除,並讓原先單數的方法支援單個或是陣列參數

至於 to 我還是照原先的設計同時支援 fd 和房間名稱,只是對於 fd 的形態做更好的兼容,當字串形態的 fd 找不到房間成員時,而 fd 又符合 numeric 條件會將該 fd 列入發送清單中

from laravel-swoole.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.