scratch-vm/src/io/btSession.js
2018-07-09 13:41:57 -04:00

36 lines
963 B
JavaScript

const JSONRPCWebSocket = require('../util/jsonrpc');
const ScratchLinkWebSocket = 'ws://localhost:20110/scratch/bt';
class BTSession extends JSONRPCWebSocket {
constructor () {
super(new WebSocket(ScratchLinkWebSocket));
}
requestDevice (options) {
return this.sendRemoteRequest('discover', options);
}
connectDevice (options) {
return this.sendRemoteRequest('connect', options);
}
sendMessage (options) {
return this.sendRemoteRequest('send', options);
}
didReceiveCall (method /* , params */) {
// TODO: Add peripheral 'undiscover' handling
switch (method) {
case 'didDiscoverPeripheral':
// TODO: do something on peripheral discovered
break;
case 'didReceiveMessage':
// TODO: do something on received message
break;
default:
return 'nah';
}
}
}
module.exports = BTSession;