{"id":19845452,"url":"https://github.com/opentok/learning-opentok-php","last_synced_at":"2025-05-01T21:30:40.691Z","repository":{"id":25595919,"uuid":"29030659","full_name":"opentok/learning-opentok-php","owner":"opentok","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-16T15:32:38.000Z","size":114,"stargazers_count":25,"open_issues_count":4,"forks_count":62,"subscribers_count":70,"default_branch":"main","last_synced_at":"2024-04-08T16:02:35.531Z","etag":null,"topics":["opentok","php","sdk","tokbox","webrtc"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opentok.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-09T19:02:00.000Z","updated_at":"2024-02-16T15:32:42.000Z","dependencies_parsed_at":"2022-08-18T03:01:32.863Z","dependency_job_id":null,"html_url":"https://github.com/opentok/learning-opentok-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentok%2Flearning-opentok-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentok%2Flearning-opentok-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentok%2Flearning-opentok-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentok%2Flearning-opentok-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentok","download_url":"https://codeload.github.com/opentok/learning-opentok-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224278479,"owners_count":17285080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["opentok","php","sdk","tokbox","webrtc"],"created_at":"2024-11-12T13:07:55.787Z","updated_at":"2024-11-12T13:07:56.365Z","avatar_url":"https://github.com/opentok.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenTok Getting Started Sample App\n\n\u003cimg src=\"https://assets.tokbox.com/img/vonage/Vonage_VideoAPI_black.svg\" height=\"48px\" alt=\"Tokbox is now known as Vonage\" /\u003e\n\nA simple server that uses the [OpenTok](https://tokbox.com/developer/)\n[PHP SDK](https://github.com/opentok/Opentok-PHP-SDK) to create sessions,\ngenerate tokens for those sessions, archive (or record) sessions, and download\nthose archives.\n\n## Quick deploy to Heroku\n\nHeroku is a PaaS (Platform as a Service) that can be used to deploy simple and small applications\nfor free. To easily deploy this repository to Heroku, sign up for a Heroku account and click this\nbutton:\n\n\u003ca href=\"https://heroku.com/deploy?template=https://github.com/opentok/learning-opentok-php\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://www.herokucdn.com/deploy/button.png\" alt=\"Deploy\"\u003e\n\u003c/a\u003e\n\nHeroku will prompt you to add your OpenTok API key and OpenTok API secret, which you can\nobtain at the [TokBox Dashboard](https://dashboard.tokbox.com/keys).\n\n## Requirements\n\n- [Composer](https://getcomposer.org/)\n- [PHP 7.3 or higher](https://php.net)\n\n## Installation \u0026 Running on localhost\n\n  1. Clone the app by running the command\n  \n          git clone git@github.com:opentok/learning-opentok-php.git\n\n  2. `cd` to the root directory.\n\n  3. Run `composer install` command to fetch and install all dependencies.\n\n  4. Next, copy the `.env.dist` file to `.env` and edit to add your API Key and Secret:\n\n      ```\n      TOKBOX_API_KEY=0000000\n      TOKBOX_SECRET=abcdef1234567890abcdef01234567890abcdef\n      ```\n\n      *Important:* The archiving sample application uses archives that are stored in the OpenTok\n      cloud. In your [OpenTok Account page](https://tokbox.com/account/), ensure that the OpenTok\n      project you use (corresponding to the API key and API secret you use here) is *not* set\n      up to use cloud storage on Microsoft Azure or Amazon S3. However, in a production\n      application, you will want to use an OpenTok project that has archive file cloud storage\n      on Microsoft Azure or Amazon S3 enabled, since archives stored on the OpenTok cloud are\n      only available for 72 hours.\n\n  5. Start the server using composer:\n\n    `$ composer run --timeout 0 serve`\n\n  6. Visit the URL \u003chttp://localhost:3000/session\u003e in your browser. You should see a JSON response\ncontaining the OpenTok API key, session ID, and token.\n\n# Exploring the code\n\nThe `web/index.php` file contains setup and routing for the web service. The logic for each route is stored in `src/Action/`. The rest of this tutorial discusses code in these files.\n\nIn order to navigate clients to a designated meeting spot, we associate the Session ID to a room name which is easier for people to recognize and pass. For simplicity, we use a local file storage to implement the association where the room name is the file name and the Session ID is the contents. For production applications, you may want to configure a persistence (such as a database) to achieve this functionality.\n\n### Generate a Session and Token\n\nThe `GET /room/:name` route associates an OpenTok session with a \"room\" name. This route handles the passed room name and performs a check to determine whether the app should generate a new session ID or retrieve a session ID from the local file storage. Then, it generates an OpenTok token for that session ID. Once the API key, session ID, and token are ready, it sends a response with the body set to a JSON object containing the information.\n\n```php\n$name = $args['name'];\n// if a room name is already associated with a session ID\nif ($this-\u003estorage-\u003eexists($name)) {\n    // fetch the sessionId from local storage\n    $sessionId = $this-\u003estorage[$name];\n\n    // generate token\n    $token = $this-\u003eopentok-\u003egenerateToken($sessionId);\n    $responseData = [\n        'apiKey' =\u003e $this-\u003eapiKey,\n        'sessionId' =\u003e $sessionId,\n        'token'=\u003e$token\n    ];\n\n    return new JsonResponse($responseData);\n} else { // Generate a new session and store it off\n    $session = $this-\u003eopentok-\u003ecreateSession([\n        'mediaMode' =\u003e MediaMode::ROUTED\n    ]);\n\n    // store the sessionId into local\n    $this-\u003estorage[$name] = $session-\u003egetSessionId();\n    \n    // generate token\n    $token = $this-\u003eopentok-\u003egenerateToken($session-\u003egetSessionId());\n    $responseData = [\n        'apiKey' =\u003e $this-\u003eapiKey,\n        'sessionId' =\u003e $session-\u003egetSessionId(),\n        'token'=\u003e$token\n    ];\n\n    return new JsonResponse($responseData);\n}\n```\n\nThe `GET /session` route generates a convenient session for quick establishment of communication.\n\n```php\n$parser = RouteContext::fromRequest($request)-\u003egetRouteParser();\nreturn new RedirectResponse($parser-\u003eurlFor('room', ['name' =\u003e 'session']));\n```\n\n### Start an [Archive](https://tokbox.com/developer/guides/archiving/)\n\nA `POST` request to the `/archive/start` route starts an archive recording of an OpenTok session.\nThe session ID OpenTok session is passed in as JSON data in the body of the request\n\n```php\n// Start Archiving and return the Archive\n$data = json_decode($request-\u003egetBody()-\u003egetContents(), true);\n$sessionId = $data['sessionId'];\n$archive = $this-\u003eopentok-\u003estartArchive($sessionId, 'Getting Started Sample Archive');\n\nreturn new JsonResponse($archive-\u003etoJson());\n```\n\nYou can only create an archive for sessions that have at least one client connected. Otherwise,\nthe app will respond with an error.\n\n### Stop an Archive\n    \nA `POST` request to the `/archive:archiveId/stop` route stops an archive recording.\nThe archive ID is returned by the call to the `archive/start` endpoint.\n\n```php\n// Stop Archiving and return the Archive\n$archive = $this-\u003eopentok-\u003estopArchive($args['archiveId']);\nreturn new JsonResponse($archive-\u003etoJson());\n```\n\n### View an Archive\n\nA `GET` request to `'/archive/:archiveId/view'` redirects the requested clients to\na URL where the archive gets played.\n\n```php\n// Download the archive\n$archive = $this-\u003eopentok-\u003egetArchive($args['archiveId']);\nif ($archive-\u003estatus=='available') {\n    return new RedirectResponse($archive-\u003eurl);\n}\nelse {\n    return new HtmlResponse(file_get_contents($this-\u003eviewsDir . '/view.html'));\n}\n```\n\n### Get Archive information\n\nA `GET` request to `/archive/:archiveId` returns a JSON object that contains all archive properties, including `status`, `url`, `duration`, etc. For more information, see [here](https://tokbox.com/developer/sdks/node/reference/Archive.html).\n\n```php\n$archive = $this-\u003eopentok-\u003egetArchive($args['archiveId']);\nreturn new JsonResponse($archive-\u003etoJson());\n```\n\n### Fetch multiple Archives\n\nA `GET` request to `/archive` with optional `count` and `offset` params returns a list of JSON archive objects. For more information, please check [here](https://tokbox.com/developer/sdks/node/reference/OpenTok.html#listArchives).\n\nExamples:\n```php\nGET /archive // fetch up to 1000 archive objects\nGET /archive?count=10  // fetch the first 10 archive objects\nGET /archive?offset=10  // fetch archives but first 10 archive objetcs\nGET /archive?count=10\u0026offset=10 // fetch 10 archive objects starting from 11st\n```\n\n## More information\n\nThis sample app does not provide client-side OpenTok functionality\n(for connecting to OpenTok sessions and for publishing and subscribing to streams).\nIt is intended to be used with the OpenTok tutorials for Web, iOS, iOS-Swift, or Android:\n\n* [Web](https://tokbox.com/developer/tutorials/web/basic-video-chat/)\n* [iOS](https://tokbox.com/developer/tutorials/ios/basic-video-chat/)\n* [iOS-Swift](https://tokbox.com/developer/tutorials/ios/swift/basic-video-chat/)\n* [Android](https://tokbox.com/developer/tutorials/android/basic-video-chat/)\n\n## Development and Contributing\n\nInterested in contributing? We :heart: pull requests! See the [Contribution](CONTRIBUTING.md) guidelines.\n\n## Getting Help\n\nWe love to hear from you so if you have questions, comments, or find a bug in the project, let us know! You can either:\n\n- Open an issue on this repository\n- See \u003chttps://support.tokbox.com/\u003e for support options\n- Tweet at us! We're [@VonageDev](https://twitter.com/VonageDev) on Twitter\n- Or [join the Vonage Developer Community Slack](https://developer.nexmo.com/community/slack)\n\n## Further Reading\n\n- Check out the Developer Documentation at \u003chttps://tokbox.com/developer/\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentok%2Flearning-opentok-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentok%2Flearning-opentok-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentok%2Flearning-opentok-php/lists"}