Skip to content

Commit

Permalink
Merge branch 'LD-3430-data-consumers'
Browse files Browse the repository at this point in the history
  • Loading branch information
fedulvtubudul committed Jul 7, 2023
2 parents ffbb6f4 + d132d8e commit 1e1201b
Show file tree
Hide file tree
Showing 42 changed files with 3,769 additions and 40 deletions.
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Mediasoup-Client-Swift (0.3.0)
- Mediasoup-Client-Swift (0.4.0)

DEPENDENCIES:
- Mediasoup-Client-Swift (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
Mediasoup-Client-Swift: 03b57ba84daecccc750b592a05a77c1fb337adf7
Mediasoup-Client-Swift: a8d229342746a17fb9d4ac61ccac1ec6d259603e

PODFILE CHECKSUM: d4fe3294dd9c7fc46519b6a7b26527f1f545e8d3

COCOAPODS: 1.11.3
COCOAPODS: 1.12.1
2 changes: 1 addition & 1 deletion Mediasoup-Client-Swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Pod::Spec.new do |spec|
}

spec.name = "Mediasoup-Client-Swift"
spec.version = "0.3.0"
spec.version = "0.4.0"
spec.platform = :ios, "14.0"
spec.module_name = "Mediasoup"
spec.module_map = "Mediasoup/Mediasoup.modulemap"
Expand Down
36 changes: 36 additions & 0 deletions Mediasoup.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
FF1E63582A5655830022A44A /* DataConsumerWrapper.hpp in Headers */ = {isa = PBXBuildFile; fileRef = FF1E63522A5655830022A44A /* DataConsumerWrapper.hpp */; settings = {ATTRIBUTES = (Private, ); }; };
FF1E635A2A5655830022A44A /* DataConsumerWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = FF1E63542A5655830022A44A /* DataConsumerWrapper.mm */; };
FF1E635B2A5655830022A44A /* DataConsumerWrapperDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = FF1E63552A5655830022A44A /* DataConsumerWrapperDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
FF1E635D2A5655830022A44A /* DataConsumerListenerAdapter.mm in Sources */ = {isa = PBXBuildFile; fileRef = FF1E63572A5655830022A44A /* DataConsumerListenerAdapter.mm */; };
FF1E635F2A566C500022A44A /* DataConsumer.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF1E635E2A566C500022A44A /* DataConsumer.swift */; };
FF1E63612A566C640022A44A /* DataConsumerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF1E63602A566C640022A44A /* DataConsumerDelegate.swift */; };
FF3AEE0C27F2D67E001A81AB /* DeviceWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = FF3AEE0B27F2D67E001A81AB /* DeviceWrapper.mm */; };
FF422680282B9603004D9974 /* ConsumerListenerAdapter.mm in Sources */ = {isa = PBXBuildFile; fileRef = FF42267E282B958C004D9974 /* ConsumerListenerAdapter.mm */; };
FF49F0E82804049300B64D36 /* Consumer.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF49F0E72804049300B64D36 /* Consumer.swift */; };
Expand Down Expand Up @@ -71,6 +77,14 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
FF1E63522A5655830022A44A /* DataConsumerWrapper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = DataConsumerWrapper.hpp; sourceTree = "<group>"; };
FF1E63532A5655830022A44A /* DataConsumerListenerAdapterDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataConsumerListenerAdapterDelegate.h; sourceTree = "<group>"; };
FF1E63542A5655830022A44A /* DataConsumerWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataConsumerWrapper.mm; sourceTree = "<group>"; };
FF1E63552A5655830022A44A /* DataConsumerWrapperDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataConsumerWrapperDelegate.h; sourceTree = "<group>"; };
FF1E63562A5655830022A44A /* DataConsumerListenerAdapter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = DataConsumerListenerAdapter.hpp; sourceTree = "<group>"; };
FF1E63572A5655830022A44A /* DataConsumerListenerAdapter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataConsumerListenerAdapter.mm; sourceTree = "<group>"; };
FF1E635E2A566C500022A44A /* DataConsumer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataConsumer.swift; sourceTree = "<group>"; };
FF1E63602A566C640022A44A /* DataConsumerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataConsumerDelegate.swift; sourceTree = "<group>"; };
FF2E23D6285890310008DC19 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
FF3AEE0027F2CDD1001A81AB /* Mediasoup.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Mediasoup.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FF3AEE0B27F2D67E001A81AB /* DeviceWrapper.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceWrapper.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -145,6 +159,19 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
FF1E63512A56555F0022A44A /* DataConsumer */ = {
isa = PBXGroup;
children = (
FF1E63562A5655830022A44A /* DataConsumerListenerAdapter.hpp */,
FF1E63572A5655830022A44A /* DataConsumerListenerAdapter.mm */,
FF1E63532A5655830022A44A /* DataConsumerListenerAdapterDelegate.h */,
FF1E63522A5655830022A44A /* DataConsumerWrapper.hpp */,
FF1E63542A5655830022A44A /* DataConsumerWrapper.mm */,
FF1E63552A5655830022A44A /* DataConsumerWrapperDelegate.h */,
);
path = DataConsumer;
sourceTree = "<group>";
};
FF3AEDF327F2C92E001A81AB = {
isa = PBXGroup;
children = (
Expand All @@ -170,6 +197,8 @@
children = (
FF49F0E72804049300B64D36 /* Consumer.swift */,
FF49F0E9280404E400B64D36 /* ConsumerDelegate.swift */,
FF1E635E2A566C500022A44A /* DataConsumer.swift */,
FF1E63602A566C640022A44A /* DataConsumerDelegate.swift */,
FF61457227F306BC0067B2C4 /* Device.swift */,
FFC5AC6F2824F8FB00C92A96 /* ICETransportPolicy.swift */,
FFC2452027F6E8DF008F61DE /* MediaKind.swift */,
Expand Down Expand Up @@ -224,6 +253,7 @@
FF89EFCF27F5C51500EEF5CD /* Mediasoup_Private */ = {
isa = PBXGroup;
children = (
FF1E63512A56555F0022A44A /* DataConsumer */,
FFB7DDB5282289AD00FE2CC2 /* Consumer */,
FF7FA6C827FE9661000B6470 /* Producer */,
FF7FA69827FAACB4000B6470 /* Transport */,
Expand Down Expand Up @@ -294,13 +324,15 @@
FF89EFC627F5B35900EEF5CD /* MediasoupClientErrorHandler.h in Headers */,
FFB7DDBB28228BE400FE2CC2 /* ReceiveTransportWrapperDelegate.h in Headers */,
FFB7DDB828228ABA00FE2CC2 /* ReceiveTransportWrapper.hpp in Headers */,
FF1E63582A5655830022A44A /* DataConsumerWrapper.hpp in Headers */,
FF89EFC027F462F200EEF5CD /* MediasoupClientError.h in Headers */,
FF7FA6A027FAAEF2000B6470 /* SendTransportWrapper.hpp in Headers */,
FF7FA6BD27FB0FB7000B6470 /* SendTransportWrapperDelegate.h in Headers */,
FF7FA6A427FAB838000B6470 /* SendTransportListenerAdapter.hpp in Headers */,
FF7FA6D427FF1A08000B6470 /* ProducerWrapperDelegate.h in Headers */,
FFB7DDBF28229BC100FE2CC2 /* ConsumerWrapperDelegate.h in Headers */,
FF7FA6CE27FE9A4B000B6470 /* ProducerWrapper.hpp in Headers */,
FF1E635B2A5655830022A44A /* DataConsumerWrapperDelegate.h in Headers */,
FFB7DDC22823989A00FE2CC2 /* ReceiveTransportListenerAdapter.hpp in Headers */,
FF61457527F30FDC0067B2C4 /* DeviceWrapper.h in Headers */,
);
Expand Down Expand Up @@ -425,6 +457,7 @@
FFB7DDB12822891C00FE2CC2 /* ReceiveTransport.swift in Sources */,
FFC2452127F6E8DF008F61DE /* MediaKind.swift in Sources */,
FF7FA6C427FD5ECD000B6470 /* Transport.swift in Sources */,
FF1E635D2A5655830022A44A /* DataConsumerListenerAdapter.mm in Sources */,
FF7FA6C227FD5EA5000B6470 /* TransportDelegate.swift in Sources */,
FFB7DDC3282398A500FE2CC2 /* ReceiveTransportListenerAdapter.mm in Sources */,
FF7FA6A227FAB803000B6470 /* SendTransportListenerAdapter.mm in Sources */,
Expand All @@ -438,6 +471,8 @@
FF89EFBF27F461DB00EEF5CD /* MediasoupError.swift in Sources */,
FFB7DDB728228A2100FE2CC2 /* ReceiveTransportWrapper.mm in Sources */,
FF7FA6D327FF18A5000B6470 /* ProducerDelegate.swift in Sources */,
FF1E635F2A566C500022A44A /* DataConsumer.swift in Sources */,
FF1E63612A566C640022A44A /* DataConsumerDelegate.swift in Sources */,
FF3AEE0C27F2D67E001A81AB /* DeviceWrapper.mm in Sources */,
FF422680282B9603004D9974 /* ConsumerListenerAdapter.mm in Sources */,
FF89EFD527F6AEBB00EEF5CD /* MediasoupClientErrorConverter.swift in Sources */,
Expand All @@ -447,6 +482,7 @@
FF89EFBD27F460F700EEF5CD /* MediasoupClientError.m in Sources */,
FFC5AC752825025100C92A96 /* MediasoupClientTransportConnectionState.mm in Sources */,
FF89EFC827F5B5E600EEF5CD /* Device.swift in Sources */,
FF1E635A2A5655830022A44A /* DataConsumerWrapper.mm in Sources */,
FF49F0E82804049300B64D36 /* Consumer.swift in Sources */,
FF7FA6D627FF1BA6000B6470 /* ProducerListenerAdapter.mm in Sources */,
);
Expand Down
102 changes: 102 additions & 0 deletions Mediasoup/DataConsumer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import Foundation
import Mediasoup_Private
import WebRTC


public class DataConsumer {
public weak var delegate: DataConsumerDelegate?

public var id: String {
return consumer.id
}

public var localId: String {
return consumer.localId
}

public var producerId: String {
return consumer.producerId
}

public var closed: Bool {
return consumer.closed
}

public var label: String {
return consumer.label
}

public var dataProtocol: String {
return consumer.dataProtocol
}

public var appData: String {
return consumer.appData
}

public var sctpStreamParameters: String {
return consumer.sctpStreamParameters
}

private let consumer: DataConsumerWrapper

internal init(consumer: DataConsumerWrapper) {
self.consumer = consumer
consumer.delegate = self
}

public func close() {
consumer.close()
}
}


extension DataConsumer: DataConsumerWrapperDelegate {
public func onMessage(_ messageData: Data, consumer: DataConsumerWrapper) {
guard consumer == self.consumer else {
return
}

self.delegate?.onMessage(data: messageData, from: self)
}

public func onConnecting(_ consumer: DataConsumerWrapper) {
guard consumer == self.consumer else {
return
}

self.delegate?.onConnecting(consumer: self)
}

public func onOpen(_ consumer: DataConsumerWrapper) {
guard consumer == self.consumer else {
return
}

self.delegate?.onOpen(consumer: self)
}

public func onClosing(_ consumer: DataConsumerWrapper) {
guard consumer == self.consumer else {
return
}

self.delegate?.onClosing(consumer: self)
}

public func onClose(_ consumer: DataConsumerWrapper) {
guard consumer == self.consumer else {
return
}

self.delegate?.onClose(consumer: self)
}

public func onTransportClose(_ consumer: DataConsumerWrapper) {
guard consumer == self.consumer else {
return
}

self.delegate?.onTransportClose(in: self)
}
}
11 changes: 11 additions & 0 deletions Mediasoup/DataConsumerDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation


public protocol DataConsumerDelegate: AnyObject {
func onConnecting(consumer: DataConsumer)
func onOpen(consumer: DataConsumer)
func onClosing(consumer: DataConsumer)
func onClose(consumer: DataConsumer)
func onTransportClose(in consumer: DataConsumer)
func onMessage(data: Data, from consumer: DataConsumer)
}
21 changes: 21 additions & 0 deletions Mediasoup/ReceiveTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ public class ReceiveTransport {
return Consumer(consumer: consumer, mediaKind: kind)
}
}

public func consumeData(
consumerId: String,
producerId: String,
streamId: UInt16,
label: String,
protocol protocolName: String?,
appData: String?
) throws -> DataConsumer {
return try convertMediasoupErrors {
let consumer = try self.transport.createDataConsumer(
withId: consumerId,
producerId: producerId,
streamId: streamId,
label: label,
protocol: protocolName,
appData: appData
)
return DataConsumer(consumer: consumer)
}
}
}

extension ReceiveTransport: Transport {
Expand Down
31 changes: 31 additions & 0 deletions Mediasoup_Private/DataConsumer/DataConsumerListenerAdapter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef DataConsumerListenerAdapter_h
#define DataConsumerListenerAdapter_h

#import <Foundation/Foundation.h>
#import "DataConsumer.hpp"


@protocol DataConsumerListenerAdapterDelegate;


class DataConsumerListenerAdapter final : public mediasoupclient::DataConsumer::Listener {
public:
__weak id<DataConsumerListenerAdapterDelegate> delegate;

DataConsumerListenerAdapter();
virtual ~DataConsumerListenerAdapter();

void OnConnecting(mediasoupclient::DataConsumer *dataConsumer) override;
void OnOpen(mediasoupclient::DataConsumer *dataConsumer) override;
void OnClosing(mediasoupclient::DataConsumer *dataConsumer) override;
void OnClose(mediasoupclient::DataConsumer *dataConsumer) override;
void OnTransportClose(mediasoupclient::DataConsumer *dataConsumer) override;

void OnMessage(
mediasoupclient::DataConsumer *dataConsumer,
const webrtc::DataBuffer &buffer
) override;

};

#endif /* DataConsumerListenerAdapter_h */
39 changes: 39 additions & 0 deletions Mediasoup_Private/DataConsumer/DataConsumerListenerAdapter.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#import "DataConsumerListenerAdapter.hpp"
#import "DataConsumerListenerAdapterDelegate.h"


DataConsumerListenerAdapter::DataConsumerListenerAdapter() {
}

DataConsumerListenerAdapter::~DataConsumerListenerAdapter() {
this->delegate = nil;
}

void DataConsumerListenerAdapter::OnMessage(
mediasoupclient::DataConsumer *dataConsumer,
const webrtc::DataBuffer &buffer
) {
auto data = [NSData dataWithBytes:buffer.data.data() length:buffer.size()];
[this->delegate onMessage:data from:this];
}

void DataConsumerListenerAdapter::OnConnecting(mediasoupclient::DataConsumer *dataConsumer) {
[this->delegate onConnecting:this];
}

void DataConsumerListenerAdapter::OnOpen(mediasoupclient::DataConsumer *dataConsumer) {
[this->delegate onOpen:this];
}

void DataConsumerListenerAdapter::OnClosing(mediasoupclient::DataConsumer *dataConsumer) {
[this->delegate onClosing:this];
}

void DataConsumerListenerAdapter::OnClose(mediasoupclient::DataConsumer *dataConsumer) {
[this->delegate onClose:this];
}

void DataConsumerListenerAdapter::OnTransportClose(mediasoupclient::DataConsumer* dataconsumer) {
// TODO: store __unsafe_unretained ref to Consumer and check if sender mathces?
[this->delegate onTransportClose:this];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef DataConsumerListenerAdapterDelegate_h
#define DataConsumerListenerAdapterDelegate_h

#import <Foundation/Foundation.h>


class DataConsumerListenerAdapter;


@protocol DataConsumerListenerAdapterDelegate
@required
- (void)onMessage:(NSData *_Nonnull)messageData from:(DataConsumerListenerAdapter *_Nonnull)adapter;
- (void)onConnecting:(DataConsumerListenerAdapter *_Nonnull)adapter;
- (void)onOpen:(DataConsumerListenerAdapter *_Nonnull)adapter;
- (void)onClosing:(DataConsumerListenerAdapter *_Nonnull)adapter;
- (void)onClose:(DataConsumerListenerAdapter *_Nonnull)adapter;
- (void)onTransportClose:(DataConsumerListenerAdapter *_Nonnull)adapter;
@end

#endif /* DataConsumerListenerAdapterDelegate_h */
Loading

0 comments on commit 1e1201b

Please sign in to comment.