meetecho / janus-gateway

Janus WebRTC Server
https://janus.conf.meetecho.com
GNU General Public License v3.0
8.02k stars 2.45k forks source link

janus join special feedID #1704

Closed fukemy closed 5 years ago

fukemy commented 5 years ago

Hello, im new in Janus. Can anyone help my problem? Tks First i need to get available video in room, so i used the code

- (void) getListParticipants : (JanusHandle *)handle {
    NSString *transaction = [self randomStringWithLength:12];
    NSDictionary *body = @{
                           @"request": @"listparticipants",
                           @"room": @1234
                           };

    NSDictionary *joinMessage = @{
                                  @"janus": @"message",
                                  @"transaction": transaction,
                                  @"session_id":sessionId,
                                  @"handle_id":handle.handleId,
                                  @"body": body
                                  };
    [_socket send:[self jsonMessage:joinMessage]];
}

That mean i will got all available participant below:

2019-07-18 15:09:30.566265+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "success",
   "session_id": 3286806180666222,
   "transaction": "LzYrJwTaODvp",
   "sender": 2194304771641704,
   "plugindata": {
      "plugin": "janus.plugin.videoroom",
      "data": {
         "videoroom": "participants",
         "room": 1234,
         "participants": [
            {
               "id": 5272753392861879,
               "display": "eqweq",
               "publisher": false
            },
            {
               "id": 5074762633600248,
               "display": "Test2",
               "publisher": false
            },
            {
               "id": 3909544807907545,
               "display": "dfsf",
               "publisher": false
            },
            {
               "id": 2578901363940712,
               "display": "Test2",
               "publisher": true
            },
            {
               "id": 2543131219310247,
               "display": "4234",
               "publisher": false
            },
            {
               "id": 1469106657521513,
               "display": "Test",
               "publisher": true
            }
         ]
      }
   }
}
`
for example, i choose the "Test2" to connect: 

`
- (void)subcribeToFeed : (NSNumber *) feed byHandleId: (JanusHandle *)handle  {
    NSString *transaction = [self randomStringWithLength:12];

    NSDictionary *body = @{
                           @"request": @"join",
                           @"room": @1234,
                           @"feed": feed,
                           @"ptype": @"subscriber"
                           };
    NSDictionary *joinMessage = @{
                                  @"janus": @"message",
                                  @"transaction": transaction,
                                  @"session_id":sessionId,
                                  @"handle_id":handle.handleId,
                                  @"body": body
                                  };

    [_socket send:[self jsonMessage:joinMessage]];
}

but after that, i dont see any video in screen, here is all my log, the feedId and HandleId is available, plz help

2019-07-18 15:09:30.531366+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "success",
   "transaction": "JO542nxBCpyY",
   "data": {
      "id": 3286806180666222
   }
}
2019-07-18 15:09:30.544627+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:09:30.563215+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "success",
   "session_id": 3286806180666222,
   "transaction": "TegMw1tEiOCH",
   "data": {
      "id": 2194304771641704
   }
}
2019-07-18 15:09:30.566265+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "success",
   "session_id": 3286806180666222,
   "transaction": "LzYrJwTaODvp",
   "sender": 2194304771641704,
   "plugindata": {
      "plugin": "janus.plugin.videoroom",
      "data": {
         "videoroom": "participants",
         "room": 1234,
         "participants": [
            {
               "id": 5272753392861879,
               "display": "eqweq",
               "publisher": false
            },
            {
               "id": 5074762633600248,
               "display": "Test2",
               "publisher": false
            },
            {
               "id": 3909544807907545,
               "display": "dfsf",
               "publisher": false
            },
            {
               "id": 2578901363940712,
               "display": "Test2",
               "publisher": true
            },
            {
               "id": 2543131219310247,
               "display": "4234",
               "publisher": false
            },
            {
               "id": 1469106657521513,
               "display": "Test",
               "publisher": true
            }
         ]
      }
   }
}
2019-07-18 15:09:30.567186+0700 janus-gateway-ios[35355:2676505] Found Video to Subcriber
2019-07-18 15:09:30.572922+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "ack",
   "session_id": 3286806180666222,
   "transaction": "DfeJ0IcGXaSf"
}
2019-07-18 15:09:30.573138+0700 janus-gateway-ios[35355:2676505] Just an ack
2019-07-18 15:09:30.574593+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "event",
   "session_id": 3286806180666222,
   "transaction": "DfeJ0IcGXaSf",
   "sender": 2194304771641704,
   "plugindata": {
      "plugin": "janus.plugin.videoroom",
      "data": {
         "videoroom": "attached",
         "room": 1234,
         "id": 2578901363940712,
         "display": "Test2"
      }
   },
   "jsep": {
      "type": "offer",
      "sdp": "v=0\r\no=- 1563435143905838 1 IN IP4 192.168.100.5\r\ns=VideoRoom 1234\r\nt=0 0\r\na=group:BUNDLE video data\r\na=msid-semantic: WMS janus\r\nm=video 9 UDP/TLS/RTP/SAVPF 96\r\nc=IN IP4 192.168.100.5\r\na=sendonly\r\na=mid:video\r\na=rtcp-mux\r\na=ice-ufrag:Ex8M\r\na=ice-pwd:X+/QZPpDCUrrbss8e8+b+6\r\na=ice-options:trickle\r\na=fingerprint:sha-256 D2:B9:31:8F:DF:24:D8:0E:ED:D2:EF:25:9E:AF:6F:B8:34:AE:53:9C:E6:F3:8F:F2:64:15:FA:E8:7F:53:2D:38\r\na=setup:actpass\r\na=rtpmap:96 VP8/90000\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtcp-fb:96 goog-remb\r\na=extmap:3 urn:3gpp:video-orientation\r\na=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\na=ssrc:3099450662 cname:janusvideo\r\na=ssrc:3099450662 msid:janus janusv0\r\na=ssrc:3099450662 mslabel:janus\r\na=ssrc:3099450662 label:janusv0\r\na=candidate:1 1 udp 2013266431 192.168.100.5 56571 typ host\r\na=candidate:2 1 udp 2013266430 10.8.0.1 42900 typ host\r\na=candidate:3 1 udp 2013266429 172.17.0.1 37699 typ host\r\na=end-of-candidates\r\nm=application 9 DTLS/SCTP 5000\r\nc=IN IP4 192.168.100.5\r\na=sendrecv\r\na=sctpmap:5000 webrtc-datachannel 16\r\na=mid:data\r\na=ice-ufrag:Ex8M\r\na=ice-pwd:X+/QZPpDCUrrbss8e8+b+6\r\na=ice-options:trickle\r\na=fingerprint:sha-256 D2:B9:31:8F:DF:24:D8:0E:ED:D2:EF:25:9E:AF:6F:B8:34:AE:53:9C:E6:F3:8F:F2:64:15:FA:E8:7F:53:2D:38\r\na=setup:actpass\r\na=candidate:1 1 udp 2013266431 192.168.100.5 56571 typ host\r\na=candidate:2 1 udp 2013266430 10.8.0.1 42900 typ host\r\na=candidate:3 1 udp 2013266429 172.17.0.1 37699 typ host\r\na=end-of-candidates\r\n"
   }
}
2019-07-18 15:10:00.471965+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:10:30.478563+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:10:33.001078+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "timeout",
   "session_id": 3286806180666222
}
2019-07-18 15:10:33.001367+0700 janus-gateway-ios[35355:2676505] missing handle?
2019-07-18 15:11:00.469977+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:11:30.467470+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:12:00.472849+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:12:30.470954+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:13:00.471483+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:13:30.469926+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:14:00.476806+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:14:30.470560+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:15:00.469989+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
2019-07-18 15:15:30.472275+0700 janus-gateway-ios[35355:2676505] ====onMessage={
   "janus": "error",
   "error": {
      "code": 456,
      "reason": "Missing mandatory element (transaction)"
   }
}
fukemy commented 5 years ago

i update full code objc

#import "WebSocketChannel.h"
#import <Foundation/Foundation.h>

#import "WebRTC/RTCLogging.h"
#import "SRWebSocket.h"
#import "JanusTransaction.h"
#import "JanusHandle.h"

static NSString const *kJanus = @"janus";
static NSString const *kJanusData = @"data";

@interface WebSocketChannel () <SRWebSocketDelegate>
@property(nonatomic, readonly) ARDSignalingChannelState state;

@end

@implementation WebSocketChannel {
    NSURL *_url;
    SRWebSocket *_socket;
    NSNumber *sessionId;
    NSTimer *keepAliveTimer;
    NSMutableDictionary *transDict;
    NSMutableDictionary *handleDict;
    NSMutableDictionary *feedDict;
}

@synthesize state = _state;

- (instancetype)initWithURL:(NSURL *)url {
    if (self = [super init]) {
        _url = url;
        NSArray<NSString *> *protocols = [NSArray arrayWithObject:@"janus-protocol"];
        _socket = [[SRWebSocket alloc] initWithURL:url protocols:(NSArray *)protocols];
        _socket.delegate = self;
        keepAliveTimer = [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(keepAlive) userInfo:nil repeats:YES];
        transDict = [NSMutableDictionary dictionary];
        handleDict = [NSMutableDictionary dictionary];
        feedDict = [NSMutableDictionary dictionary];

        RTCLog(@"Opening WebSocket.");
        [_socket open];
    }
    return self;
}

- (void)dealloc {
  [self disconnect];
}

- (void)setState:(ARDSignalingChannelState)state {
  if (_state == state) {
    return;
  }
  _state = state;
}

- (void)disconnect {
  if (_state == kARDSignalingChannelStateClosed ||
      _state == kARDSignalingChannelStateError) {
    return;
  }
  [_socket close];
    RTCLog(@"C->WSS DELETE close");
}

#pragma mark - SRWebSocketDelegate

- (void)webSocketDidOpen:(SRWebSocket *)webSocket {
  RTCLog(@"WebSocket connection opened.");
  self.state = kARDSignalingChannelStateOpen;
  [self createSession];
}

- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message {
  NSLog(@"====onMessage=%@", message);
  NSData *messageData = [message dataUsingEncoding:NSUTF8StringEncoding];
  id jsonObject = [NSJSONSerialization JSONObjectWithData:messageData options:0 error:nil];
  if (![jsonObject isKindOfClass:[NSDictionary class]]) {
    NSLog(@"Unexpected message: %@", jsonObject);
    return;
  }
  NSDictionary *wssMessage = jsonObject;
  NSString *janus = wssMessage[kJanus];
    if ([janus isEqualToString:@"success"]) {
        NSString *transaction = wssMessage[@"transaction"];

        JanusTransaction *jt = transDict[transaction];
        if (jt.success != nil) {
            jt.success(wssMessage);
        }
        [transDict removeObjectForKey:transaction];

        if ([wssMessage objectForKey:@"plugindata"] != nil) {
            NSDictionary *pluginMessage = wssMessage[@"plugindata"];
            if ([pluginMessage objectForKey:@"data"] != nil){
                NSDictionary *dataMessage = pluginMessage[@"data"];
                if ([dataMessage objectForKey:@"participants"] != nil){
                    NSMutableArray *participantList = [dataMessage objectForKey:@"participants"];
                    for (NSDictionary *participantDict in participantList) {
                        if([participantDict[@"display"] isEqualToString:@"Test2"]){
                            BOOL isPublisher = [participantDict[@"publisher"] boolValue];
                            if (isPublisher == YES) {
                                NSLog(@"Found Video to Subcriber");
                                NSNumber *feed = participantDict[@"id"];
                                JanusHandle *handle = handleDict[wssMessage[@"sender"]];
                                [self subcribeToFeed:feed byHandleId:handle];
                            }

                        }
                    }
                }
            }
        }

    } else if ([janus isEqualToString:@"error"]) {
        NSString *transaction = wssMessage[@"transaction"];
        if (transaction == nil) {
            return;
        }
        JanusTransaction *jt = transDict[transaction];
        if (jt.error != nil) {
            jt.error(wssMessage);
        }
        [transDict removeObjectForKey:transaction];
    } else if ([janus isEqualToString:@"ack"]) {
        NSLog(@"Just an ack");
    } else {
        JanusHandle *handle = handleDict[wssMessage[@"sender"]];
        if (handle == nil) {
            NSLog(@"missing handle?");
        } else if ([janus isEqualToString:@"event"]) {
            NSDictionary *plugin = wssMessage[@"plugindata"][@"data"];
            if ([plugin[@"videoroom"] isEqualToString:@"joined"] || [plugin[@"videoroom"] isEqualToString:@"attached"]) {
                handle.onJoined(handle);
            }

            NSArray *arrays = plugin[@"publishers"];
            if (arrays != nil && [arrays count] > 0) {
                for (NSDictionary *publisher in arrays) {
                    NSNumber *feed = publisher[@"id"];
                    NSString *display = publisher[@"display"];
                    [self subscriberCreateHandle:feed display:display];
                }
            }

            if (plugin[@"leaving"] != nil) {
                JanusHandle *jHandle = feedDict[plugin[@"leaving"]];
                if (jHandle) {
                    jHandle.onLeaving(jHandle);
                }
            }

            if (wssMessage[@"jsep"] != nil) {
                handle.onRemoteJsep(handle, wssMessage[@"jsep"]);
            }
        } else if ([janus isEqualToString:@"detached"]) {
            handle.onLeaving(handle);
        }
    }
}

- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error {
  RTCLogError(@"WebSocket error: %@", error);
  self.state = kARDSignalingChannelStateError;
}

- (void)webSocket:(SRWebSocket *)webSocket
 didCloseWithCode:(NSInteger)code
           reason:(NSString *)reason
         wasClean:(BOOL)wasClean {
    RTCLog(@"WebSocket closed with code: %ld reason:%@ wasClean:%d",
           (long)code, reason, wasClean);
    NSParameterAssert(_state != kARDSignalingChannelStateError);
    self.state = kARDSignalingChannelStateClosed;
    [keepAliveTimer invalidate];
}

#pragma mark - Private

NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

- (NSString *)randomStringWithLength: (int)len {
    NSMutableString *randomString = [NSMutableString stringWithCapacity: len];
    for (int i = 0; i< len; i++) {
        uint32_t data = arc4random_uniform((uint32_t)[letters length]);
        [randomString appendFormat: @"%C", [letters characterAtIndex: data]];
    }
    return randomString;
}

- (void)createSession {
    NSString *transaction = [self randomStringWithLength:12];

    JanusTransaction *jt = [[JanusTransaction alloc] init];
    jt.tid = transaction;
    jt.success = ^(NSDictionary *data) {
        sessionId = data[@"data"][@"id"];
        [keepAliveTimer fire];
        [self publisherCreateHandle];
    };
    jt.error = ^(NSDictionary *data) {
    };
    transDict[transaction] = jt;

    NSDictionary *createMessage = @{
        @"janus": @"create",
        @"transaction" : transaction,
                                    };
  [_socket send:[self jsonMessage:createMessage]];
}

- (void)publisherCreateHandle {
    NSString *transaction = [self randomStringWithLength:12];
    JanusTransaction *jt = [[JanusTransaction alloc] init];
    jt.tid = transaction;
    jt.success = ^(NSDictionary *data){
        JanusHandle *handle = [[JanusHandle alloc] init];
        handle.handleId = data[@"data"][@"id"];
        handle.onJoined = ^(JanusHandle *handle) {
            [self.delegate onPublisherJoined: handle.handleId];
        };
        handle.onRemoteJsep = ^(JanusHandle *handle, NSDictionary *jsep) {
            [self.delegate onPublisherRemoteJsep:handle.handleId dict:jsep];
        };

        handleDict[handle.handleId] = handle;
        [self getListParticipants: handle];
    };
    jt.error = ^(NSDictionary *data) {
    };
    transDict[transaction] = jt;

    NSDictionary *attachMessage = @{
                                    @"janus": @"attach",
                                    @"plugin": @"janus.plugin.videoroom",
                                    @"transaction": transaction,
                                    @"session_id": sessionId,
                                    };
    [_socket send:[self jsonMessage:attachMessage]];
}

- (void)subcribeToFeed : (NSNumber *) feed byHandleId: (JanusHandle *)handle  {
    NSString *transaction = [self randomStringWithLength:12];

    NSDictionary *body = @{
                           @"request": @"join",
                           @"room": @1234,
                           @"feed": feed,
                           @"ptype": @"subscriber"
                           };
    NSDictionary *joinMessage = @{
                                  @"janus": @"message",
                                  @"transaction": transaction,
                                  @"session_id":sessionId,
                                  @"handle_id":handle.handleId,
                                  @"body": body
                                  };

    [_socket send:[self jsonMessage:joinMessage]];
}

- (void) getListParticipants : (JanusHandle *)handle {
    NSString *transaction = [self randomStringWithLength:12];
    NSDictionary *body = @{
                           @"request": @"listparticipants",
                           @"room": @1234
                           };

    NSDictionary *joinMessage = @{
                                  @"janus": @"message",
                                  @"transaction": transaction,
                                  @"session_id":sessionId,
                                  @"handle_id":handle.handleId,
                                  @"body": body
                                  };
    [_socket send:[self jsonMessage:joinMessage]];
}

- (void)publisherJoinRoom : (JanusHandle *)handle {
    NSString *transaction = [self randomStringWithLength:12];

    NSDictionary *body = @{
                           @"request": @"join",
                           @"room": @1234,
                           @"ptype": @"publisher",
                           @"display": @"ios webrtc",
                           };
    NSDictionary *joinMessage = @{
                                  @"janus": @"message",
                                  @"transaction": transaction,
                                  @"session_id":sessionId,
                                  @"handle_id":handle.handleId,
                                  @"body": body
                                  };

    [_socket send:[self jsonMessage:joinMessage]];
}

- (void)createHandle: (NSString *) transValue dict:(NSDictionary *)publisher {
}

- (void)publisherCreateOffer:(NSNumber *)handleId sdp: (RTCSessionDescription *)sdp {
    NSString *transaction = [self randomStringWithLength:12];

    NSDictionary *publish = @{
                             @"request": @"configure",
                             @"audio": @YES,
                             @"video": @YES,
                             };

    NSString *type = [RTCSessionDescription stringForType:sdp.type];

    NSDictionary *jsep = @{
                           @"type": type,
                           @"sdp": [sdp sdp],
                           };
    NSDictionary *offerMessage = @{
                                   @"janus": @"message",
                                   @"body": publish,
                                   @"jsep": jsep,
                                   @"transaction": transaction,
                                   @"session_id": sessionId,
                                   @"handle_id": handleId,
                                   };

    [_socket send:[self jsonMessage:offerMessage]];
}

- (void)trickleCandidate:(NSNumber *) handleId candidate: (RTCIceCandidate *)candidate {
    NSDictionary *candidateDict = @{
                                @"candidate": candidate.sdp,
                                @"sdpMid": candidate.sdpMid,
                                @"sdpMLineIndex": [NSNumber numberWithInt: candidate.sdpMLineIndex],
                                };

    NSDictionary *trickleMessage = @{
                                     @"janus": @"trickle",
                                     @"candidate": candidateDict,
                                     @"transaction": [self randomStringWithLength:12],
                                     @"session_id":sessionId,
                                     @"handle_id":handleId,
                                     };

    NSLog(@"===trickle==%@", trickleMessage);
    [_socket send:[self jsonMessage:trickleMessage]];
}

- (void)trickleCandidateComplete:(NSNumber *) handleId {
    NSDictionary *candidateDict = @{
       @"completed": @YES,
       };
    NSDictionary *trickleMessage = @{
                                     @"janus": @"trickle",
                                     @"candidate": candidateDict,
                                     @"transaction": [self randomStringWithLength:12],
                                     @"session_id":sessionId,
                                     @"handle_id":handleId,
                                     };

    [_socket send:[self jsonMessage:trickleMessage]];
}

- (void)subscriberCreateHandle: (NSNumber *)feed display:(NSString *)display {
    NSString *transaction = [self randomStringWithLength:12];
    JanusTransaction *jt = [[JanusTransaction alloc] init];
    jt.tid = transaction;
    jt.success = ^(NSDictionary *data){
        JanusHandle *handle = [[JanusHandle alloc] init];
        handle.handleId = data[@"data"][@"id"];
        handle.feedId = feed;
        handle.display = display;

        handle.onRemoteJsep = ^(JanusHandle *handle, NSDictionary *jsep) {
            [self.delegate subscriberHandleRemoteJsep:handle.handleId dict:jsep];
        };

        handle.onLeaving = ^(JanusHandle *handle) {
            [self subscriberOnLeaving:handle];
        };
        handleDict[handle.handleId] = handle;
        feedDict[handle.feedId] = handle;
        [self subscriberJoinRoom: handle];
    };
    jt.error = ^(NSDictionary *data) {
        NSLog(@"got error: %@", data);
    };
    transDict[transaction] = jt;

    NSDictionary *attachMessage = @{
                                    @"janus": @"attach",
                                    @"plugin": @"janus.plugin.videoroom",
                                    @"transaction": transaction,
                                    @"session_id": sessionId,
                                    };
    [_socket send:[self jsonMessage:attachMessage]];
}

- (void)subscriberJoinRoom:(JanusHandle*)handle {

    NSString *transaction = [self randomStringWithLength:12];
    transDict[transaction] = @"subscriber";

    NSDictionary *body = @{
                           @"request": @"join",
                           @"room": @1234,
//                           @"ptype": @"listener",
                           @"ptype": @"subscriber",
                           @"feed": handle.feedId,
                           };

    NSDictionary *message = @{
                                  @"janus": @"message",
                                  @"transaction": transaction,
                                  @"session_id": sessionId,
                                  @"handle_id": handle.handleId,
                                  @"body": body,
                                  };

    [_socket send:[self jsonMessage:message]];
}

- (void)subscriberCreateAnswer:(NSNumber *)handleId sdp: (RTCSessionDescription *)sdp  {
    NSString *transaction = [self randomStringWithLength:12];

    NSDictionary *body = @{
                              @"request": @"start",
                              @"room": @1234,
                              };

    NSString *type = [RTCSessionDescription stringForType:sdp.type];

    NSDictionary *jsep = @{
                           @"type": type,
                           @"sdp": [sdp sdp],
                           };
    NSDictionary *offerMessage = @{
                                   @"janus": @"message",
                                   @"body": body,
                                   @"jsep": jsep,
                                   @"transaction": transaction,
                                   @"session_id": sessionId,
                                   @"handle_id": handleId,
                                   };

    [_socket send:[self jsonMessage:offerMessage]];
}

- (void)subscriberOnLeaving:(JanusHandle *) handle {
    NSString *transaction = [self randomStringWithLength:12];

    JanusTransaction *jt = [[JanusTransaction alloc] init];
    jt.tid = transaction;
    jt.success = ^(NSDictionary *data) {
        [self.delegate onLeaving:handle.handleId];
        [handleDict removeObjectForKey:handle.handleId];
        [feedDict removeObjectForKey:handle.feedId];
    };
    jt.error = ^(NSDictionary *data) {
    };
    transDict[transaction] = jt;

    NSDictionary *message = @{
                                   @"janus": @"detach",
                                   @"transaction": transaction,
                                   @"session_id": sessionId,
                                   @"handle_id": handle.handleId,
                                   };

    [_socket send:[self jsonMessage:message]];
}

- (void)keepAlive {
    NSDictionary *dict = @{
                           @"janus": @"keepalive",
                           @"session_id": sessionId ? [NSNumber numberWithInt:-1],
                           @"transaction": [self randomStringWithLength:12],
                           };
    [_socket send:[self jsonMessage:dict]];
}

- (NSString *)jsonMessage:(NSDictionary *)dict {
    NSData *message = [NSJSONSerialization dataWithJSONObject:dict
                                                      options:NSJSONWritingPrettyPrinted
                                                        error:nil];
    NSString *messageString = [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding];
    return messageString;
}

@end
lminiero commented 5 years ago

As VERY CLEARLY explained in the guidelines, please DO NOT paste this humongous bunch of text inline. That said, this kind of questions belongs to the group, not here. We only use Github for Janus issues. Closing.