-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adam Bibby
committed
Oct 11, 2023
1 parent
b27a8a9
commit 938a383
Showing
10 changed files
with
230 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { braviaAPIFactory } from './internal' | ||
|
||
export interface GetSourceListOptions { | ||
scheme: 'extInput' | ||
} | ||
|
||
export interface Source { | ||
source: string | ||
} | ||
|
||
export const getSourceList = braviaAPIFactory<[options:GetSourceListOptions], Source[]>( | ||
'avContent', | ||
'getSourceList', | ||
'1.0', | ||
) | ||
|
||
export interface SetPlayContentOptions { | ||
uri: string | ||
} | ||
|
||
|
||
export const setPlayContent = braviaAPIFactory<[options:SetPlayContentOptions], void>( | ||
'avContent', | ||
'setPlayContent', | ||
'1.0', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { braviaAPIFactory } from './internal' | ||
|
||
export interface GetPublicKeyResult { | ||
publicKey: string | ||
} | ||
|
||
export const getPublicKey = braviaAPIFactory<[], GetPublicKeyResult>( | ||
'encryption', | ||
'getPublicKey', | ||
'1.0', | ||
) | ||
|
||
export interface GetSecretDataOptions { | ||
encKey: string | ||
} | ||
export interface GetSecretDataResult { | ||
secretData: string | ||
} | ||
|
||
export const getSecretData = braviaAPIFactory< | ||
[options: GetSecretDataOptions], | ||
GetSecretDataResult | ||
>('encryption', 'getSecretData', '1.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
export * as audio from './audio' | ||
export * as system from './system' | ||
export * as appControl from './appControl' | ||
export * as avContent from './avContent' | ||
|
||
export { sendRemoteCode } from './ircc-ip' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { braviaAPIFactory } from './internal' | ||
|
||
export interface SetPowerStatusOptions { | ||
status: boolean | ||
} | ||
|
||
/** | ||
* @link https://pro-bravia.sony.net/develop/integrate/rest-api/spec/service/system/v1_0/setPowerStatus/index.html | ||
*/ | ||
export const setPowerStatus = braviaAPIFactory< | ||
[options: SetPowerStatusOptions], | ||
void | ||
>('system', 'setPowerStatus', '1.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { getTextForm, setTextForm } from '../bravia/appControl' | ||
import { getPublicKey } from '../bravia/encryption' | ||
|
||
export async function sendText(text: string): Promise<void> { | ||
const result = await setTextForm(text) | ||
console.log(result) | ||
|
||
// const { publicKey } = await getPublicKey() | ||
// const key = await importPublicKey(publicKey) | ||
// const data = await encryptData(text, key) | ||
// getTextForm() | ||
} | ||
function base64ToArrayBuffer(base64: string) { | ||
var binary_string = window.atob(base64) | ||
var len = binary_string.length | ||
var bytes = new Uint8Array(len) | ||
for (var i = 0; i < len; i++) { | ||
bytes[i] = binary_string.charCodeAt(i) | ||
} | ||
return bytes.buffer | ||
} | ||
|
||
function arrayBufferToBase64(buffer: ArrayBuffer) { | ||
var binary = '' | ||
var bytes = new Uint8Array(buffer) | ||
var len = bytes.byteLength | ||
for (var i = 0; i < len; i++) { | ||
binary += String.fromCharCode(bytes[i]) | ||
} | ||
return window.btoa(binary) | ||
} | ||
|
||
async function importPublicKey(spki: string) { | ||
const binaryDer = base64ToArrayBuffer(spki) | ||
var cryptoKey = await window.crypto.subtle.importKey( | ||
'spki', | ||
binaryDer, | ||
{ | ||
name: 'RSA-OAEP', | ||
modulusLength: 256, | ||
hash: { name: 'sha-256' }, | ||
}, | ||
false, | ||
['encrypt'], | ||
) | ||
return cryptoKey | ||
} | ||
|
||
async function encryptData(message: string, cryptoKey: CryptoKey) { | ||
let enc = new TextEncoder() | ||
let encodedMessage = enc.encode(message) | ||
var encryptedData = await window.crypto.subtle.encrypt( | ||
{ | ||
name: 'RSA-OAEP', | ||
}, | ||
cryptoKey, | ||
encodedMessage, | ||
) | ||
var encodedData = arrayBufferToBase64(encryptedData) | ||
return encodedData | ||
} |