電波の届かない列でも遊べるようにした ── 一度も開いていないゲームまでPlayable in a queue with no signal, even games you have never opened

/ WAITROOM 運営事務局WAITROOM Operations Office

地下の通路や建物の中の列では、電波が届かないことがよくあります。WAITROOM は、トップページを一度開いた端末なら、まだ遊んだことのないゲームでも電波なしで遊べます。そのために必要だった3つのことと、気づきにくかった落とし穴を書きます。Underground passages and indoor queues often have no signal. On any device that has opened the home page once, WAITROOM plays offline, even games you have never tried. Here are the three things that took, and the traps that were hard to spot.

01

待ち時間の場所は、電波が弱い

テーマパークの屋内の列、地下街の飲食店の前、人が集まるイベントの会場。待ち時間が長くなる場所ほど、電波が弱かったり混み合ったりしがちです。開こうとして読み込みが終わらなければ、待ち時間を楽しく過ごすという目的は果たせません。

そこで、ひとりで遊ぶときと、1台の端末を回して遊ぶとき(1台まわし)は、電波がまったくなくても最後まで遊べることを必須の条件にしました。

02

目標は「一度も開いていないゲームでも」

よくある作り方は「一度開いたページだけを端末に保存しておく」ものです。ただ、列に並んでから「あのゲームをやってみよう」と思い出して開くのは、たいてい初めてのゲームです。一度遊んだものしか開けないのでは、現場では間に合いません。

そこで、トップページを一度開いた時点で、すべてのゲームに必要なファイルを端末に保存しておくことを目標にしました。

03

必要だったこと1:遊ぶ画面を作り置きできる形にする

最初の作りでは、遊ぶ画面を開くたびにサーバーで問題の「種」(盤面や出題を決める値)を作っていました。そのため遊ぶ画面は毎回サーバーで組み立てる必要があり、電波がなければ開けませんでした。

種はサーバーで作る必要のない値だったので、端末の側で作るように変えました。これで遊ぶ画面は前もって作り置きでき、ほかのファイルと同じように端末に保存できるようになりました。

04

必要だったこと2:必要なファイルの一覧を自分で作る

サイトを作る道具(Next.js)には、次に開きそうなページを先読みする仕組みがあります。最初はそれに任せていましたが、電波を切って確かめると、シグナルタップを開くのに必要な 10 個のファイルのうち、10 個とも保存されていませんでした。先読みは、ページを描くための一部のファイルまでは取りに行かなかったのです。

推測での先読みはやめ、サイトを組み立てるときに必要なファイルの一覧を書き出して、端末に保存する係(Service Worker)にそのまま渡すようにしました。全部で約 1.1MB です。

05

必要だったこと3:パズルを解くプログラムを独立したファイルにする

スライドロボでは、盤面を作るたびに最短の手数を求めるプログラム(ソルバー)を、画面とは別の作業場所(Web Worker)で動かしています。道具の標準の仕組みでこの作業場所を作ると、起動に必要な情報がアドレスの「#」より後ろに付けて渡されます。

ところが、保存しておいたファイルを返すとき、この「#」以降は引き継がれません。電波がないときだけ情報が消え、ソルバーが起動できずに止まっていました。ソルバーを独立した普通のファイルとして書き出し、ほかのファイルと同じように保存するようにして解決しました。

06

電波があるときには気づけない落とし穴

Service Worker では、ほかにも2つの点でつまずきました。1つは、保存したファイルを探すときに、サーバーが返す応答の付帯情報(Vary)まで照合してしまい、「まだ開いたことのないページ」が見つからなかったことです。照合のときにこの情報を無視するよう指定して直しました。

もう1つは、ファイルを入れる場所と探す場所の名前が食い違っていたことです。電波があるうちはサーバーから取ってくるので、何の問題もなく動いてしまいます。どちらも電波を切ってはじめて分かる問題でした。

07

毎回、電波を切って確かめる

こうした問題は、普段の開発では表に出ません。そこで、ブラウザを自動で操作するテストを1本足しました。個々のゲームは一度も開かずにトップページだけを開き、そこで通信を切ってから、ひとりで遊ぶゲーム・スライドロボ・1台まわしを実際に動かします。電波まわりに手を入れたときは、このテストで確かめています。

08

使うときのコツ

列に並ぶ前、電波のあるうちにトップページを一度開いておけば、あとは電波がなくても遊べます。ブラウザの「ホーム画面に追加」をしておくと、アプリのように1回で開けて便利です。

ただし、部屋コードでの対戦は、それぞれの端末どうしで通信するので電波が必要です。電波のない場所でみんなで遊ぶときは、1台まわしを使ってください。

01

Where you wait, the signal is weak

Indoor queues at theme parks, restaurants in underground malls, crowded event venues: the places where waits are long tend to have weak or congested signal. If the page never finishes loading, it cannot help you pass the time.

So we made it a hard requirement that solo play and pass & play (passing one device around) work to the end with no signal at all.

02

The goal: even games you have never opened

The usual approach saves only pages you have already opened. But when you remember a game while standing in line, it is usually one you have not played yet. "Only what you played before" is not enough in practice.

So the goal became: once the home page has been opened, every file every game needs is already on the device.

03

Step 1: make the play screens buildable in advance

At first, each time a play screen opened, the server made the game’s seed (the value that decides the board or questions). That meant the server had to build the screen every time, so it could not open without a signal.

The seed did not need to come from the server, so we moved it to the device. The play screens could then be built ahead of time and saved like any other file.

04

Step 2: write our own list of required files

The framework we use (Next.js) can prefetch pages you are likely to open. We relied on that at first, but with the network off, none of the 10 files Signal Tap needs had been saved. Prefetching did not fetch some of the files a page needs to render.

We stopped guessing. When the site is built, we now write out the list of required files and hand it straight to the part that saves them on the device (the Service Worker). It comes to about 1.1 MB.

05

Step 3: ship the puzzle solver as a standalone file

In Slide Robo, a solver finds the shortest number of moves for each board, running in a separate workspace from the screen (a Web Worker). When the framework’s standard mechanism creates this workspace, it passes startup information after the “#” in the address.

But when a saved file is returned, the part after “#” is not carried over. Only when offline, that information vanished and the solver failed to start. We fixed it by building the solver as an ordinary standalone file, saved like everything else.

06

Traps you cannot see while online

The Service Worker tripped us up twice more. First, when looking up saved files it also compared a header in the server’s response (Vary), so pages never opened before could not be found. We told it to ignore that header when matching.

Second, the names of the place files were saved to and the place they were looked up in did not match. While online, files simply come from the server, so everything appears to work. Both problems only showed up with the network off.

07

We cut the network every time

Problems like these never surface in everyday development, so we added an automated browser test. It opens only the home page, never any individual game, cuts the network, then actually plays solo games, Slide Robo and pass & play. Whenever we touch anything offline-related, we check it with this test.

08

Tips for using it

Open the home page once while you still have signal, before joining the line, and you can play without signal after that. Using your browser’s “Add to Home Screen” lets you open it in one tap like an app.

Room-code matches need a signal, because the devices talk to each other. When playing together with no signal, use pass & play.

GAMES

この記事に出てくるゲームGames in this note

MORE

ほかの開発ノートMore dev notes