{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!pip install websockets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import websockets\n",
    "import json\n",
    "import base64\n",
    "\n",
    "from api import BigApi\n",
    "BigApi.init(\".admin.rice.env\")\n",
    "BigApi.adminLogin()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Convert wssPayload to json, then convert to base64 string\n",
    "def getWebsocketPayload(accessToken):\n",
    "    wssPayload = {\n",
    "        \"accessToken\": accessToken,\n",
    "        \"systemInfo\": {\n",
    "            \"deviceUniqueIdentifier\": \"python_notebook\"\n",
    "        }\n",
    "    }\n",
    "    return base64.b64encode(json.dumps(wssPayload).encode(\"utf-8\")).decode(\"utf-8\")\n",
    "\n",
    "# Convert wssPayload to json, then convert to base64 string\n",
    "wssPayload = getWebsocketPayload(BigApi.accessToken)\n",
    "\n",
    "# Connect to the websocket server\n",
    "uri = f\"{BigApi.cloudWssUrl}/{wssPayload}\"\n",
    "print(uri)\n",
    "await websockets.connect(uri)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "room = BigApi.cloudPost(\"/room\", {\n",
    "    \"name\": \"Test Room 2\",\n",
    "    \"description\": \"(Unit test room)\",\n",
    "    \"category\": \"MOVIES\",\n",
    "    \"environmentId\": \"builtin_modern_cinema\",\n",
    "    \"visibility\": \"Public\",\n",
    "    \"version\": \"0.9.9\",\n",
    "    \"maxUsersPerInstance\": 4,\n",
    "    \"roomType\": \"room\",\n",
    "    \"version\": \"0.9.9\",\n",
    "})\n",
    "roomId = room[\"roomId\"]\n",
    "\n",
    "roomId\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "BigApi.cloudPut(f\"/room/{roomId}\", {\"version\": \"0.9.9\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "BigApi.cloudPost(f\"/room/{roomId}/join\", { \"version\": \"0.9.9\" })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "activity = BigApi.cloudPost(f\"/activity\", { \n",
    "    \"id\": \"social_browser\",\n",
    "    \"state\": {\n",
    "        \"url\": \"https://bigscreenvr.com\"\n",
    "    },\n",
    "    \"version\": \"0.9.9\" \n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "activities = BigApi.cloudGet(\"/activities\")\n",
    "activities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "activityId = \"Tji-F3IzZdDt8xX9YNVzKvT8IBo\"\n",
    "html = BigApi.cloudGetRaw(f\"/apps/browser/{activityId}\")\n",
    "print(html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "BigApi.cloudDel(f\"/apps/browser/{activityId}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
