How to connect to user's stream in TokBox

2019-07-27 01:37发布

问题:

I'm making a 1 on 1 video call app using TokBox. I'm opening a session using this code:

[_session connectWithApiKey:kApiKey token:kToken];

after getting the didConnect message i'm publishing a stream on one user device using this code:

    _publisher = [[OTPublisher alloc] initWithDelegate:self];
    [_publisher setName:@"PublishName"];
    [_session publish:_publisher];
    [self.view addSubview:_publisher.view];
    [_publisher.view setFrame:CGRectMake(0, 0, widgetWidth, widgetHeight)];

What do I need to transfer to the other user in order for him to see what the first user publishes? I tried going through the docs but It's really unclear to me. Do I need a session ID? Publish ID?

Thanks.

回答1:

Think of sessions as rooms. People connected to the same session will be in the same room so they are able to see each other. Lets say you have 2 iPhones, A and B. After iPhone A calls [_session publish...], iPhone B will get a stream created event with A's video stream. Simply subscribe to that stream and B should be able to see As video.

You probably want to have a streamCreated delegate. In your streamCreated delegate, simply call [session subscribe...] to subscribe to the publishing stream.

For an example, check out the OpenTok HelloWorld Tutorial. Its a simple group video chat where everybody is publishing and subscribing to each other.