Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Detecting bluetooth device disconnects/crashes

オープン
#57 コメント 1 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript, node.js

調査の方向性

lib/connection.js から始めて read callback を調査し、長さ 0 のバッファーと読み取りエラーがどのように発生するかを含めて確認します。issue に記載された Bluetooth のシャットダウン動作を再現し、期待される disconnect event とそのタイミングを特定します。長さ 0 のバッファーが有効な接続中に発生することは不可能だと仮定せずに、disconnect の動作が定義され、カバーされていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Hi!
I couldn't find a way to detect if a connection has crashed or disconnected so I tried to implement my own.
In lib/connection.js, I noticed that - if I printed the chunks of the read method - they stop printing as soon as I turn off my bluetooth device; after ~20seconds of apparent frozen behavior, this method continued working, printing chunks of zero length buffers.
Thus, I added the following line
if(chunk.length == 0){ self.emit('error')}
in

(function read(){
      self.isOpen() && self.port.read((err, chunk) => {
        process.nextTick(read);
        if(err) return self.emit('error', err);
        self.emit('data', chunk);
        if(chunk.length == 0){ self.emit('error')}
      });
    })();

This allows me to fetch error events like so:

    connect(address, 1, (err, linkage) => {
      if (err) {
        console.log('connection attempt error');
      } else {
        linkage.on('error', (err) => {
          console.log('disconnected!);
        });
      }
    )}

However my approach assumes I won't be receiving zero length buffers when connected which I realize that might not always be true (or not for all devices);
Also, any thoughts on how to detect the disconnect before the ~20seconds pass?
Thanks!

主要言語
C++
スター
205
フォーク
56
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

lsongdev/node-bluetooth のほかの issue

lsongdev/node-bluetooth の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。