2016-06-16 11 views
10

Używam kodu ISBX/apprtc-ios do implementacji czatu wideo. Ta praca jest idealna na iPhone'a i symulator. Chcę wysłać dane tekstowe/łańcuchowe między dwoma równorzędnymi użytkownikami i używam klasy RTCDataChannel.Impelementacja RTCDataChannel WebRTC w iOS

Poniżej przedstawiam moją implementację i nie jestem w stanie nawiązać połączenia. Zawsze podaje status kRTCDataChannelStateConnecting Jak mogę podłączyć RTCDataChannel? Czy istnieje dostępna implementacja WebRTC RTCDataChannel dla systemu 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

Próbowałaś https://github.com/Mahabali/Apprtc-swift? Jestem pewien, że to samo, co internetowy datachannel to webrtc? Jaką odpowiedź otrzymujesz, gdy tworzysz kanał danych? – Dhilip

Odpowiedz

4

Jestem w stanie przesłać dane przez RTCDataChannel. To, co zrobiłem, to przed wysłaniem oferty. Stworzyłem RTCDataChannelInit z poniższą konfiguracją.

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; 

Gdy oba urządzenia zostaną podłączone, sprawdziłem stan w funkcji delegata. Stan kanału jest otwarty.

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

Potem wysłać dane, jak na poniższym kodzie:

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

Konfiguracja Kiedyś dano tutaj: https://groups.google.com/forum/#!searchin/discuss-webrtc/RTCDataChannel/discuss-webrtc/9NObqxnItCg/mRvXBIwkA7wJ

+0

przechodzę przez punkt samouczków webrtc - https://www.tutorialspoint.com/webrtc/webrtc_sending_messages.html i zaimplementowałem kanał danych, który działa poprawnie w Internecie i na iOS tylko odbieranie wiadomości, ale nie wysyłanie, możesz mi pomóc na zewnątrz –