Skip to content

Commit 37026b6

Browse files
committed
Merge branch 'release/v1.0.0' into main
2 parents de95aaf + 909b403 commit 37026b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5061
-27
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
tests:
7+
name: Unit-Tests
8+
runs-on: macOS-latest
9+
steps:
10+
- uses: actions/checkout@v1
11+
- name: run unit tests
12+
run: |
13+
swift test --enable-code-coverage
14+
- name: Upload coverage to Codecov
15+
uses: codecov/codecov-action@v1
16+
with:
17+
token: ${{ secrets.CODECOV_TOKEN }}
18+
file: ./.build/debug/codecov/WebsocketKit.json
19+
flags: unittests
20+
name: codecov-umbrella
21+
fail_ci_if_error: true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
/Packages
44
/*.xcodeproj
55
xcuserdata/
6+
.bundle/**
7+
.vendor/**
8+
.swiftpm

.jazzy.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
abstract: Docs/Sections/*.md
2+
author: Alexander Weiß
3+
author_url: https://alexanderweiss.dev
4+
github_url: https://github.com/alexanderwe/SurferKit
5+
swift_build_tool: spm
6+
build_tool_arguments: [-Xswiftc, -swift-version, -Xswiftc, "5"]
7+
output: ./docs

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org' do
2+
gem 'jazzy' , "0.13.0"
3+
end

Gemfile.lock

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
CFPropertyList (3.0.2)
5+
activesupport (4.2.11.3)
6+
i18n (~> 0.7)
7+
minitest (~> 5.1)
8+
thread_safe (~> 0.3, >= 0.3.4)
9+
tzinfo (~> 1.1)
10+
algoliasearch (1.27.4)
11+
httpclient (~> 2.8, >= 2.8.3)
12+
json (>= 1.5.1)
13+
atomos (0.1.3)
14+
claide (1.0.3)
15+
cocoapods (1.9.3)
16+
activesupport (>= 4.0.2, < 5)
17+
claide (>= 1.0.2, < 2.0)
18+
cocoapods-core (= 1.9.3)
19+
cocoapods-deintegrate (>= 1.0.3, < 2.0)
20+
cocoapods-downloader (>= 1.2.2, < 2.0)
21+
cocoapods-plugins (>= 1.0.0, < 2.0)
22+
cocoapods-search (>= 1.0.0, < 2.0)
23+
cocoapods-stats (>= 1.0.0, < 2.0)
24+
cocoapods-trunk (>= 1.4.0, < 2.0)
25+
cocoapods-try (>= 1.1.0, < 2.0)
26+
colored2 (~> 3.1)
27+
escape (~> 0.0.4)
28+
fourflusher (>= 2.3.0, < 3.0)
29+
gh_inspector (~> 1.0)
30+
molinillo (~> 0.6.6)
31+
nap (~> 1.0)
32+
ruby-macho (~> 1.4)
33+
xcodeproj (>= 1.14.0, < 2.0)
34+
cocoapods-core (1.9.3)
35+
activesupport (>= 4.0.2, < 6)
36+
algoliasearch (~> 1.0)
37+
concurrent-ruby (~> 1.1)
38+
fuzzy_match (~> 2.0.4)
39+
nap (~> 1.0)
40+
netrc (~> 0.11)
41+
typhoeus (~> 1.0)
42+
cocoapods-deintegrate (1.0.4)
43+
cocoapods-downloader (1.4.0)
44+
cocoapods-plugins (1.0.0)
45+
nap
46+
cocoapods-search (1.0.0)
47+
cocoapods-stats (1.1.0)
48+
cocoapods-trunk (1.5.0)
49+
nap (>= 0.8, < 2.0)
50+
netrc (~> 0.11)
51+
cocoapods-try (1.2.0)
52+
colored2 (3.1.2)
53+
concurrent-ruby (1.1.7)
54+
escape (0.0.4)
55+
ethon (0.12.0)
56+
ffi (>= 1.3.0)
57+
ffi (1.13.1)
58+
fourflusher (2.3.1)
59+
fuzzy_match (2.0.4)
60+
gh_inspector (1.1.3)
61+
httpclient (2.8.3)
62+
i18n (0.9.5)
63+
concurrent-ruby (~> 1.0)
64+
jazzy (0.13.0)
65+
cocoapods (~> 1.5)
66+
mustache (~> 1.1)
67+
open4
68+
redcarpet (~> 3.4)
69+
rouge (>= 2.0.6, < 4.0)
70+
sassc (~> 2.1)
71+
sqlite3 (~> 1.3)
72+
xcinvoke (~> 0.3.0)
73+
json (2.3.1)
74+
liferaft (0.0.6)
75+
minitest (5.14.2)
76+
molinillo (0.6.6)
77+
mustache (1.1.1)
78+
nanaimo (0.3.0)
79+
nap (1.1.0)
80+
netrc (0.11.0)
81+
open4 (1.3.4)
82+
redcarpet (3.5.0)
83+
rouge (3.24.0)
84+
ruby-macho (1.4.0)
85+
sassc (2.4.0)
86+
ffi (~> 1.9)
87+
sqlite3 (1.4.2)
88+
thread_safe (0.3.6)
89+
typhoeus (1.4.0)
90+
ethon (>= 0.9.0)
91+
tzinfo (1.2.7)
92+
thread_safe (~> 0.1)
93+
xcinvoke (0.3.0)
94+
liferaft (~> 0.0.6)
95+
xcodeproj (1.19.0)
96+
CFPropertyList (>= 2.3.3, < 4.0)
97+
atomos (~> 0.1.3)
98+
claide (>= 1.0.2, < 2.0)
99+
colored2 (~> 3.1)
100+
nanaimo (~> 0.3.0)
101+
102+
PLATFORMS
103+
ruby
104+
105+
DEPENDENCIES
106+
jazzy (= 0.13.0)!
107+
108+
BUNDLED WITH
109+
2.0.2

LICENSE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Alexander Weiß
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
23+

Package.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.2
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
7-
name: "WebsocketKit",
7+
name: "WebSocketKit",
8+
platforms: [
9+
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13)
10+
],
811
products: [
912
// Products define the executables and libraries a package produces, and make them visible to other packages.
1013
.library(
11-
name: "WebsocketKit",
12-
targets: ["WebsocketKit"]),
14+
name: "WebSocketKit",
15+
targets: ["WebSocketKit"]),
1316
],
1417
dependencies: [
1518
// Dependencies declare other packages that this package depends on.
@@ -19,10 +22,10 @@ let package = Package(
1922
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2023
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2124
.target(
22-
name: "WebsocketKit",
25+
name: "WebSocketKit",
2326
dependencies: []),
2427
.testTarget(
25-
name: "WebsocketKitTests",
26-
dependencies: ["WebsocketKit"]),
28+
name: "WebSocketKitTests",
29+
dependencies: ["WebSocketKit"]),
2730
]
2831
)

README.md

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,121 @@
1-
# WebsocketKit
1+
# WebSocketKit
22

3-
A description of this package.
3+
<p align="center">
4+
<a href="https://developer.apple.com/swift/">
5+
<img src="https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat" alt="Swift 5.0">
6+
</a>
7+
<a href="https://github.com/apple/swift-package-manager">
8+
<img src="https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg" alt="SPM">
9+
</a>
10+
11+
<a href="https://github.com/alexanderwe/LoggingKit">
12+
<img src="https://github.com/alexanderwe/WebSocketKit/workflows/CI/badge.svg" alt="CI">
13+
</a>
14+
<a href="https://codecov.io/gh/alexanderwe/WebSocketKit">
15+
<img src="https://codecov.io/gh/alexanderwe/WebSocketKit/branch/main/graph/badge.svg?token=zNmgmMp5zB" alt="Code coverage">
16+
</a>
17+
</p>
18+
19+
<p align="center">
20+
WebSocketKit is a small wrapper around the `Network` framework to work with websocket connections
21+
</p>
22+
23+
## Installation
24+
25+
### Swift Package Manager
26+
27+
To integrate using Apple's [Swift Package Manager](https://swift.org/package-manager/), add the following as a dependency to your `Package.swift`:
28+
29+
```swift
30+
dependencies: [
31+
.package(url: "https://github.com/alexanderwe/WebSocketKit.git", from: "1.0.0")
32+
]
33+
```
34+
35+
Alternatively navigate to your Xcode project, select `Swift Packages` and click the `+` icon to search for `WebSocketKit`.
36+
37+
### Manually
38+
39+
If you prefer not to use any of the aforementioned dependency managers, you can integrate LoggingKit into your project manually. Simply drag the `Sources` Folder into your Xcode project.
40+
41+
## Usage
42+
43+
At first import `WebSocketKit`
44+
45+
```swift
46+
import WebSocketKit
47+
```
48+
49+
Define a `WebsSocket` instance
50+
51+
```swift
52+
let websocket = WebsSocket(url: URL(string: "wss://echo.websocket.org")!)
53+
```
54+
55+
It also makes sense to create a instance of a class that conforms to the `WebSocketConnectionDelegate` in order to receive websocket events. Be aware that you also need to import the `Network` framework in order to have access to `NWProtocolWebSocket`.
56+
57+
```swift
58+
import Network
59+
60+
61+
class WebSocketDelegate: WebSocketConnectionDelegate {
62+
63+
func webSocketDidConnect(connection: WebSocketConnection) {
64+
print("WebSocket did connect")
65+
}
66+
67+
func websocketDidPrepare(connection: WebSocketConnection) {
68+
print("WebSocket did prepare")
69+
}
70+
71+
func webSocketDidDisconnect(connection: WebSocketConnection, closeCode: NWProtocolWebSocket.CloseCode, reason: Data?) {
72+
print("WebSocket did disconnect")
73+
}
74+
75+
func websocketDidCancel(connection: WebSocketConnection) {
76+
print("WebSocket did cancel")
77+
}
78+
79+
func webSocketDidReceiveError(connection: WebSocketConnection, error: Error) {
80+
print("WebSocket did receive error: \(error)")
81+
}
82+
83+
func webSocketDidReceivePong(connection: WebSocketConnection) {
84+
print("WebSocket did receive pong")
85+
}
86+
87+
func webSocketDidReceiveMessage(connection: WebSocketConnection, string: String) {
88+
print("WebSocket did receive string message: \(string)")
89+
}
90+
91+
func webSocketDidReceiveMessage(connection: WebSocketConnection, data: Data) {
92+
print("WebSocket did receive data message")
93+
}
94+
}
95+
```
96+
97+
Set an instance of the delegate instance to the `Websocket` instance and start listening for events
98+
99+
```swift
100+
let delegate = WebSocketDelegate()
101+
websocket.delegate = delegate
102+
103+
websocket.connect() // Connects to the url specified in the initializer and listens for messages
104+
```
105+
106+
### Custom headers
107+
108+
Often it is necessary to attach custom headers to the connection. You can do so by specifying them in the initializer of the `Websocket` class.
109+
110+
```swift
111+
let websocket = Websocket(url: URL(string: "wss://echo.websocket.org")!,
112+
additionalHeaders: [
113+
"Authorization:": "Bearer <someToken>",
114+
"My-Custom-Header-Key:": "My-Custom-Header-Value"
115+
]
116+
)
117+
```
118+
119+
## Contributing
120+
121+
Contributions are very welcome 🙌

0 commit comments

Comments
 (0)