Files
chrome-extensions-samples/_archive/apps/samples/appengine-channelapi
Oliver Dunk 5bf419b385 Reorganize directory structure (#825)
* Remove docs folder.

This was a redirect from a GitHub pages site that does not appear
to be in use.

* Rename api folder to api-samples.

* Move examples to functional-samples folder.

* Move cookbook sample to functional-samples.

* Move tutorials to functional-samples folder.

* Move mv2 and apps folders to _archive.

* Rename tools folder to .repo.

* Move reference folder to functional-samples.

* Update README.

Update README with new relative links for reorg.

* Update README.md

Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com>

---------

Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com>
2023-02-03 10:58:04 -06:00
..
2023-02-03 10:58:04 -06:00

Try it now in CWS

AppEngine Channel API example

This is an example of how to use the AppEngine's Channel API in a Chrome Packaged App. Since the Channel API is not directly compatible with the CSP restrictions in a packaged app, this sample uses a WebView and a "proxy" object that communicates with the Webview using async postMessage.

This code is an adaptation of the Tic Tac Toe game used by the AppEngine team to demonstrate the Channel API. The main modifications from the original game are:

  • index.html is not rendered as a template in the server, it is embedded in the app. All responses from the server are JSON messages;
  • the server doesn't use the appengine's user library, since that would require another authentication step. Instead, the server attributes a random UUID to the first user and another to the second. This user ID is returned to the client that uses it in the following calls. It is not secure, but simple enough for this sample. In a real application, this method would allow an eaversdropper to capture the GET request and replay with different commands;
  • all the interations with the channel API are abstracted in the ChannelAPI object defined by channel_in_a_webview.js. This object communicates with the webview page (channel_in_a_webview.html), served to the webview from the appengine server.

To run:

  • go to the appengine folder and type dev_appserver.py .
  • install the Chrome Packaged App in the app folder
  • run the Chrome packaged app twice and copy the game ID from one screen to the other
  • play

Screenshot

screenshot