-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for listening to OSC over TCP
Signed-off-by: Axel Boberg <[email protected]>
- Loading branch information
1 parent
29dbb9f
commit 81a50da
Showing
10 changed files
with
139 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import './style.css' | ||
|
||
import { SegmentedControl } from '../SegmentedControl' | ||
|
||
export function PreferencesSegmentedInput ({ label, value, segments = [], onChange = () => {} }) { | ||
return ( | ||
<div className='PreferencesSegmentedInput'> | ||
<label>{label}</label> | ||
<div className='PreferencesSegmentedInput-controlWrapper'> | ||
<SegmentedControl | ||
values={segments} | ||
value={segments[value] || segments[0]} | ||
onChange={newValue => onChange(segments.indexOf(newValue))} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} |
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,3 @@ | ||
.PreferencesSegmentedInput-controlWrapper { | ||
margin-top: 10px; | ||
} |
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,24 @@ | ||
import React from 'react' | ||
import './style.css' | ||
|
||
export function SegmentedControl ({ className = '', value: _value, values = [], onChange = () => {} }) { | ||
return ( | ||
<div className={`SegmentedControl ${className}`}> | ||
{ | ||
(Array.isArray(values) ? values : []) | ||
.map(value => { | ||
const isActive = value === _value | ||
return ( | ||
<div | ||
key={value} | ||
className={`SegmentedControl-segment ${isActive ? 'is-active' : ''}`} | ||
onClick={() => !isActive && onChange(value)} | ||
> | ||
{value} | ||
</div> | ||
) | ||
}) | ||
} | ||
</div> | ||
) | ||
} |
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,21 @@ | ||
.SegmentedControl { | ||
display: inline-block; | ||
padding: 4px; | ||
|
||
border-radius: 8px; | ||
background: var(--base-color--shade1); | ||
white-space: nowrap; | ||
} | ||
|
||
.SegmentedControl-segment { | ||
display: inline-block; | ||
padding: 0.75em 1em; | ||
color: var(--base-color); | ||
|
||
border-radius: 5px; | ||
} | ||
|
||
.SegmentedControl-segment.is-active { | ||
background: var(--base-color--background); | ||
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1); | ||
} |
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,38 @@ | ||
// SPDX-FileCopyrightText: 2024 Sveriges Television AB | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
const Transport = require('./Transport') | ||
|
||
const net = require('node:net') | ||
|
||
class TCPTransport extends Transport { | ||
/** | ||
* @private | ||
* @type { net.Server } | ||
*/ | ||
#server | ||
|
||
constructor () { | ||
super() | ||
this.#server = net.createServer(socket => { | ||
socket.on('data', data => { | ||
this.emit('message', data) | ||
}) | ||
socket.on('close', () => { | ||
socket.removeAllListeners() | ||
}) | ||
}) | ||
} | ||
|
||
teardown () { | ||
super.teardown() | ||
this.#server.close() | ||
} | ||
|
||
listen (port, address) { | ||
this.#server.listen(port, address) | ||
} | ||
} | ||
|
||
module.exports = TCPTransport |
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