PHP Classes

File: app/Core/Helpers/socketHelperFunctions.php

Recommend this page to a friend!
  Classes of Ahmad Mustapha   ReactPHP Chat Client   app/Core/Helpers/socketHelperFunctions.php   Download  
File: app/Core/Helpers/socketHelperFunctions.php
Role: Example script
Content type: text/plain
Description: Example script
Class: ReactPHP Chat Client
Implement a live chat system based on Web Sockets
Author: By
Last change:
Date: 3 years ago
Size: 1,216 bytes
 

Contents

Class file image Download
<?php

use App\Socket\Response;
use
Colors\Color;
use
Evenement\EventEmitter;
use
Ratchet\ConnectionInterface;

require
'generalHelperFunctions.php';

/**
 * Send message to client
 * @param ConnectionInterface $client
 * @return Response
 */
function resp(ConnectionInterface $client)
{
    return new
Response($client);
}

$clients = new SplObjectStorage;
/**
 * All clients are stored here
 * @return SplObjectStorage
 */
function clientStorage()
{
    global
$clients;
    return
$clients;
}

$chatClients = new ArrayObject();
/**
 * Clients that joined chat rooms
 * @param null $client
 * @param null $data
 * @return ArrayObject
 */
function chatClients($client = null, $data = null)
{
    global
$chatClients;

    if (
$client) {
       
$chatClients[$client->resourceId] = $data;
    }
    return
$chatClients;
}

/**
 * All created chat rooms
 * @param null $room
 * @param null $setValue
 * @return array|splObjectStorage
 */
function chatRooms($room = null, $setValue = null)
{
    static
$chatRooms = [];

    if (!isset(
$chatRooms[$room])) {
       
$chatRooms[$room] = [];
    }

    if (
$setValue) {
       
$chatRooms[$room][] = $setValue;
    }

    return
$room ? $chatRooms[$room] : $chatRooms;
}