mumble のチャンネルビューアに使う JSON フォーマットの出力について


mumble のチャンネルビューアで利用する JSONデータフォーマットを、php を使って出力してみました。ちょっと強引なところもありますが・・・。なかなか情報がなくて出力するのに一苦労でした。

出力用のphpソース

<?php
$PROXY_STRING = 'Meta:tcp -h 127.0.0.1 -p 6502';
require('Ice.php');
require('Murmur.php');
$callback = isset($_REQUEST['callback']) ? $_REQUEST['callback'] : null;

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: text/javascript; charset=utf-8');

$communicator = Ice_initialize();
$base = $communicator->stringToProxy($PROXY_STRING);
$meta = $base->ice_checkedCast("::Murmur::Meta");
$servers = $meta->getBootedServers();
$default = $meta->getDefaultConf();

function mapTree2Model($tree) {
    $channels = array();
    for ($i = 0; $i < count($tree->children); $i++) {
        $channels[] = mapTree2Model($tree->children[$i]);
    }
    $users = array();
    for ($i = 0; $i < count($tree->users); $i++) {
        for ($j = 0; $j < count($tree->users); $j++) {
            $users[$j]['session'] = $tree->users[$j]->session;
            $users[$j]['userid'] = $tree->users[$j]->userid;
            $users[$j]['mute'] = $tree->users[$j]->mute;
            $users[$j]['deaf'] = $tree->users[$j]->deaf;
            $users[$j]['suppress'] = $tree->users[$j]->suppress;
            $users[$j]['prioritySpeaker'] = $tree->users[$j]->prioritySpeaker;
            $users[$j]['selfMute'] = $tree->users[$j]->selfMute;
            $users[$j]['selfDeaf'] = $tree->users[$j]->selfDeaf;
            $users[$j]['recording'] = $tree->users[$j]->recording;
            $users[$j]['channel'] = $tree->users[$j]->channel;
            $users[$j]['name'] = $tree->users[$j]->name;
            $users[$j]['onlinesecs'] = $tree->users[$j]->onlinesecs;
            $users[$j]['bytespersec'] = $tree->users[$j]->bytespersec;
            $users[$j]['version'] = $tree->users[$j]->version;
            $users[$j]['release'] = $tree->users[$j]->release;
            $users[$j]['os'] = $tree->users[$j]->os;
            $users[$j]['osversion'] = $tree->users[$j]->osversion;
            $users[$j]['identity'] = $tree->users[$j]->identity;
            $users[$j]['context'] = $tree->users[$j]->context;
            $users[$j]['comment'] = $tree->users[$j]->comment;
            $users[$j]['address'] = $tree->users[$j]->address;
            $users[$j]['tcponly'] = $tree->users[$j]->tcponly;
            $users[$j]['idlesecs'] = $tree->users[$j]->idlesecs;
            $users[$j]['udpPing'] = $tree->users[$j]->udpPing;
            $users[$j]['tcpPing'] = $tree->users[$j]->tcpPing;
        }
    }
    if($tree->c->id == 0) {
        global $servers, $default;
        foreach($servers as $s) {
            $name = $s->getConf("registername");
            if (! $name) {
              $name =  $default["registername"];
            }
        }
    } else {
        $name = $tree->c->name;
    }

    return array(
	'x_connecturl' => "mumble://path/to/mumble.jp:64738/?version=1.2.4" ,
        'channels' => $channels,
	'temporary' => $tree->c->temporary,
	'description' => $tree->c->description,
	'parent' => $tree->c->parent,
	'position' => $tree->c->position,
        'name' => $name, //$tree->c->name,
	'users' => $users,
	'id' => $tree->c->id
    );
}
$tree = $meta->getServer(1)->getTree();
$json = json_encode(mapTree2Model($tree));
$json = '{'.
	'"x_connecturl": ' .
	'"mumble://path/to/mumble.jp:64738/?version=1.2.4",' .
	'"root":' .
	$json .
	'}';
if (!empty($callback)) {
    echo $callback . '(' . $json . ');';
} else {
    echo $json;
}
php?>

ドキュメンテーション



コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

ブログ著者情報

KAZ@Apocrypha
KAZ@Apocrypha
備忘録的な話題だけでなく、内容に拘らず情報発信をして行きたいと思っています。よろしくお願いします。
このエントリーをはてなブックマークに追加

カテゴリー