-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: Create socket connections provider
- Loading branch information
1 parent
b43caf6
commit 5196391
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Sockets.swift | ||
// OctoPhone | ||
// | ||
// Created by Josef Dolezal on 13/05/2017. | ||
// Copyright © 2017 Josef Dolezal. All rights reserved. | ||
// | ||
|
||
import Alamofire | ||
import enum Result.NoError | ||
import ReactiveSwift | ||
|
||
/// Allows to create web socket connections | ||
class WebSocket { | ||
/// Connects to server and reads data stream | ||
/// | ||
/// - Parameters: | ||
/// - url: URL of the remote sockets stream | ||
/// - method: HTTP method of connection request | ||
func connect(url: URL, withMethod method: HTTPMethod) -> SignalProducer<Data, NoError> { | ||
let cancellable = Alamofire.request(url, method: method) | ||
|
||
return SignalProducer { sink, disposlable in | ||
cancellable.stream { data in | ||
sink.send(value: data) | ||
} | ||
|
||
disposlable.add { | ||
cancellable.cancel() | ||
} | ||
} | ||
} | ||
} |