Comments (4)
The current implementation matches the API and behavior of the Javascript version, which auto connects upon instantiation. For current apps using this library, it would be a breaking change to require an .open()
call prior to connecting; also it would no longer match the JS version (not a deal-breaker, just a nice-to-have).
The event object is simply a struct and could easily be copied between objects. For example.
let event = ws.event
ws = WebSocket("ws://url")
ws.event = event
Could this problem be solved by creating a wrapper class around the WebSocket object? Perhaps the wrapper has a .open()
method which creates a new WebSocket when called. And it (re)assigns the .event
struct at the same time.
from swiftwebsocket.
Thanks for the tip, a wrapper is a reasonable solution.
To avoid breaking changes, you could consider letting a websocket to be instantiated without a URL.
And if it's created without a url, naturally you would have to set this afterwards, and then you could call .open() on it. I think that would be expected behaviour in that case, it would not be a breaking change and it would offer a bit more flexibility.
But I completely respect it if this is not a path you wish to pursue.
A few suggestions however.
// Suggestion 1:
let ws = WebSocket()
ws.url = "ws://url"
ws.open()
// Or perhaps 2:
let ws = WebSocket()
ws.openURL("ws://url")
// 3:
let ws = WebSocket("ws://url", autoConnect: false)
from swiftwebsocket.
I like suggestion 2. I'm working on it.
from swiftwebsocket.
The master branch now includes this feature.
from swiftwebsocket.
Related Issues (20)
- Substring Method Deprecated -- WebSocket.Swift
- the library is very slow
- Abnormal Closure
- How to subscribe and listen to events? HOT 1
- cannot connect with a server HOT 1
- Support Swift 4.2 on CocoaPod HOT 3
- signal SIGPIPE on device
- Swift 5.0 compile error. HOT 9
- Type 'RunLoop' has no member 'Mode' HOT 5
- Compile warning In XCode 10.2.1 with swift 5
- Take Responsibility of this project. HOT 1
- Memory Usage when sending a large message HOT 4
- WebSocketError.needMoreInput
- How do I get the HTTP response headers?
- Doesn't compile on Xcode 11.3.1 HOT 2
- 'NSObject.hashValue' is not overridable; did you mean to override 'NSObject.hash'?
- The "Autobahn Test" link doesn't work...
- Data race
- Send pongs and receive ping events. HOT 1
- Initialization of 'UnsafePointer<UInt8>' results in a dangling pointer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftwebsocket.