我正在使用 Vonage (Tokbox) API 进行视频通话。我已经生成了会话和令牌,但没有创建流 id

问题描述 投票:0回答:2

我正在使用 Vonage (Tokbox) API 进行视频通话。使用 codeigniter 集成 Vonage。
我已经生成了会话和令牌,但未创建流 ID。此类中 OpenTok\OpenTok 类的 getStream($sessionId, $streamId) 方法发生了什么,但未生成流 id。
我的代码是:

$opentok = new OpenTok($this->config->item('opentok_key'), $this->config->item('opentok_secret'));


        // Create a session that attempts to use peer-to-peer streaming:
        $session = $opentok->createSession();

        // A session that uses the OpenTok Media Router, which is required for archiving:
        $session = $opentok->createSession(array( 'mediaMode' => MediaMode::ROUTED ));

        // A session with a location hint:
        // $session = $opentok->createSession(array( 'location' => '12.34.56.78' ));

        // An automatically archived session:
        $sessionOptions = array(
            'archiveMode' => ArchiveMode::ALWAYS,
            'mediaMode' => MediaMode::ROUTED
        );
        $session = $opentok->createSession($sessionOptions);


        // Store this sessionId in the database for later use
        $sessionId = $session->getSessionId();


        // Generate a Token from just a sessionId (fetched from a database)
        $token = $opentok->generateToken($sessionId);
        // Generate a Token by calling the method on the Session (returned from createSession)
        $token = $session->generateToken();

        // Set some options in a token
        $token = $session->generateToken(array(
            'role'       => Role::MODERATOR,
            'expireTime' => time()+(7 * 24 * 60 * 60), // in one week
            'data'       => 'name=Johnny',
            'initialLayoutClassList' => array('focus')
        ));



        // Get stream info from just a sessionId (fetched from a database)
        $stream = $opentok->getStream($sessionId, $streamId);
        // echo "<pre>"; print_r($stream); exit();

        // Stream properties
        $stream->id; // string with the stream ID
        $stream->videoType; // string with the video type
        $stream->name; // string with the name
        $stream->layoutClassList; // array with the layout class list
codeigniter
2个回答
1
投票

getStream($sessionId, $streamId)
需要
streamId
作为您必须传入的参数。该方法不会为您生成它。

您只创建了会话,但您必须发布流或订阅现有流。如果您不想将任何流发布为

publisher
,则必须监听
streamCreated
事件才能订阅其他流。查看所有流事件的开发文档:StreamEvent


0
投票

在此事件中,您必须生成 /make 流 id 并将其传递给 getStream(session ID,steamId) metnod。

session.on("streamCreated", function (event) {
    console.log("New stream in the session: " + event.stream.streamId);
});
// Replace with a valid token:
session.connect(token);

因此 event.stream.streamId 将为您提供所需的内容。

参考: https://developer.vonage.com/en/video/guides/subscribe-streams/detect-streams?source=video

© www.soinside.com 2019 - 2024. All rights reserved.