Skip to content

Invalid argument supplied for foreach() (php 7.1, 7.2, 7.3) Or Trying to access array offset on value of type int (php 7.4) #15

Closed
@hiimike

Description

@hiimike

Hi guys, really good library to get easy of Openvidu. I found an issue with method fetch in Session.php class (to get all active connections, publishers etc.) and I think this is probably by new version of OpenVidu Server :2.15.0,
There is expected a certain json, but my theory is that json structure has been changed from openvidu server response. now I got this from /api/sessions
"connections": { "numberOfElements": 1, "content": [ { "connectionId": "con_YygXCxrtLm", "createdAt": 1598756663749, "location": "unknown", "platform": "Chrome 85.0.4183.83 on OS X 10.15.5 64-bit", "token": "wss://localhost:4443?sessionId=hsD0Tck5z5LMbiSG9oUV&token=tok_QBlmW8FFywHfXY8f&role=PUBLISHER&version=2.15.0", "role": "PUBLISHER", "serverData": "{}", "clientData": "{\"clientData\":\"\"}", "publishers": [ { "createdAt": 1598756665627, "streamId": "str_CAM_FoQc_con_YygXCxrtLm", "mediaOptions": { "hasAudio": true, "audioActive": true, "hasVideo": true, "videoActive": true, "typeOfVideo": "CAMERA", "frameRate": 30, "videoDimensions": "{\"width\":640,\"height\":480}", "filter": {} } } ], "subscribers": [] } ] }

I think previously the elements "numberOfElements" and "mediaOptions" was not present.
Anyways my solution was:

FromArray method Session.php class

if (array_key_exists('connections', $sessionArray)) { foreach ($sessionArray['connections']['content'] as $connection) { $publishers = []; $ensure = $connection['content'] ?? $connection; foreach ($ensure['publishers'] as $publisher) { $publishers[] = PublisherBuilder::build($publisher); } $subscribers = []; foreach ($ensure['subscribers'] as $subscriber) { $subscribers[] = $subscriber->streamId; } $this->activeConnections[] = ConnectionBuilder::build($ensure, $publishers, $subscribers); }

and in builder for publishers

public static function build(array $properties) { return new Publisher($properties['streamId'], $properties['createdAt'], $properties['mediaOptions']['hasAudio'], $properties['mediaOptions']['hasVideo'], $properties['mediaOptions']['audioActive'], $properties['mediaOptions']['videoActive'], $properties['mediaOptions']['frameRate'], $properties['mediaOptions']['typeOfVideo'], $properties['mediaOptions']['videoDimensions'] ); }

my env.
Apache with php 7.4, Openvidu docker image v 2.15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions