2016-06-16 37 views
10

Sto usando il codice ISBX/apprtc-ios per l'implementazione della chat video. Questo lavoro è perfetto per iPhone e simulatore. Voglio inviare dati di testo/stringa tra due peer e sto usando la classe RTCDataChannel.Impelementazione di RTCDataChannel di WebRTC in iOS

Di seguito è la mia implementazione e non sono in grado di stabilire la connessione. Fornisce sempre lo stato kRTCDataChannelStateConnecting Come posso collegare RTCDataChannel? È disponibile un'implementazione funzionante per WebRTC RTCDataChannel per iOS?

- (void)createNewDataChannel { 
    if (self.clientDataChannel) { 
     switch(self.clientDataChannel.state) { 
      case kRTCDataChannelStateConnecting: 
       NSLog(@"kRTCDataChannelStateConnecting"); 
       break; 
      case kRTCDataChannelStateOpen: 
       NSLog(@"kRTCDataChannelStateOpen"); 
       break; 
      case kRTCDataChannelStateClosing: 
       NSLog(@"kRTCDataChannelStateClosing"); 
       break; 
      case kRTCDataChannelStateClosed: 
       NSLog(@"kRTCDataChannelStateClosed"); 
       break; 
      default: 
       NSLog(@"Unknown"); 
     } 
     return; 
    } 
    if (self.peerConnection == nil) { 
     NSLog(@"Peerconnection is nil"); 
    } 

    RTCDataChannelInit *DataChannelInit = [[RTCDataChannelInit alloc] init]; 
    DataChannelInit.maxRetransmits = 0; 
    DataChannelInit.isOrdered=false; 
    DataChannelInit.maxRetransmitTimeMs = -1; 
    DataChannelInit.isNegotiated = false; 
    DataChannelInit.streamId = 25; 
    RTCDataChannel *dataChannel =[_peerConnection createDataChannelWithLabel:@"commands" config:DataChannelInit]; 
    dataChannel.delegate=self; 
    self.clientDataChannel = dataChannel; 

    if (self.clientDataChannel == nil) { 
     NSLog(@"Datachannel is nil"); 
    } 
    else { 
     NSLog(@"Datachannel is working"); 
    } 
} 
+0

Hai provato https://github.com/Mahabali/Apprtc-swift? Sono sicuro che la stessa cosa del web datachannel è webrtc? Che risposta ricevi quando crei un canale dati? – Dhilip

risposta

4

Sono in grado di inviare dati tramite RTCDataChannel. Quello che ho fatto è prima di inviare l'offerta. Ho creato il RTCDataChannelInit con la configurazione di seguito.

RTCDataChannelInit *datainit = [[RTCDataChannelInit alloc] init]; 

datainit.isNegotiated = YES; 

datainit.isOrdered = YES; 

datainit.maxRetransmits = 30; 

datainit.maxRetransmitTimeMs = 30000; 

datainit.streamId = 1; 
self.dataChannel = [_peerConnection createDataChannelWithLabel:@"commands" config:datainit]; 
self.dataChannel.delegate=self; 

Dopo aver connesso entrambi i dispositivi, ho controllato lo stato nella funzione delegato. Lo stato del canale è aperto.

- (void)channelDidChangeState:(RTCDataChannel*)channel 
{ 
    NSLog(@"channel.state %u",channel.state); 
} 

Poi mi inviano i dati secondo il codice qui sotto:

RTCDataBuffer *buffer = [[RTCDataBuffer alloc] initWithData:[str dataUsingEncoding:NSUTF8StringEncoding] isBinary:NO]; 
BOOL x = [self.dataChannel sendData:buffer]; 

La configurazione che ho usato è stata data qui: https://groups.google.com/forum/#!searchin/discuss-webrtc/RTCDataChannel/discuss-webrtc/9NObqxnItCg/mRvXBIwkA7wJ

+0

sto passando attraverso il tutorial di webrtc point - https://www.tutorialspoint.com/webrtc/webrtc_sending_messages.html e implementato il canale dati funziona perfettamente sul web e su iOS solo ricevendo il messaggio ma non inviando mi potete aiutare su –