npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@techandsoftware/teletext-caster

v0.10.2

Published

View teletext pages on Chromecast

Downloads

6

Readme

Javascript module to cast teletext pages to Chromecast.

Usage

As an ECMAScript module

The HTML/javascript code below does the following:

  • Imports the Google cast API framework
  • Shows a cast button
  • Imports this module
  • Code which operates it
<script src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"></script>
<google-cast-launcher id="castbutton"></google-cast-launcher>

<script type="module">
  import { ttxcaster } from 'https://cdn.jsdelivr.net/npm/@techandsoftware/teletext-caster@latest/dist/teletextcaster.min.js';

  // dispay a page using a base64url encoded string. See below about PACKED_PAGE
  ttxcaster.display(PACKED_PAGE)

  // display a page using Output Lines. Parameters described below
  ttxcaster.display({
    defaultG0Charset: encoding,
    header: header,
    outputLines: outputLines
  })
</script>

If using npm instead of jsdelivr, then install the package:

npm install @techandsoftware/teletext-caster

Use this import instead:

import { ttxcaster } from './node_modules/@techandsoftware/teletext-caster/dist/teletextcaster.min.js';

Older browsers

If you're targetting browsers that don't support ES6 modules, a UMD is available in the dist directory for importing using <script>. This exports the module in the global ttx so access it as ttx.ttxcaster

<!-- from jsdelivr -->
<script src="https://cdn.jsdelivr.net/npm/@techandsoftware/teletext-caster@latest/dist/teletextcaster.umd.min.js"></script>

<!-- using npm -->
<script src="./node_modules/@techandsoftware/teletext-caster/dist/teletextcaster.umd.min.js"></script>

API

The ttxcaster.display method is the only one which needs to be called to display a page. The other methods are optional.

(Google's API framework and cast button are discussed in Google's guide. It's not necessary to call Google's API directly as this module wraps around it.)

ttxcaster.display(PACKED_PAGE || object)

Displays a page. You can supply a string or an object.

PACKED_PAGE is a base64-encoded string of 7-bit characters for the 25 rows x 40 characters concatenated together. The encoded string uses the character repertoire defined in the base64url encoding. This format is taken from the URL hash fragment format used by Simon Rawles' online edit.tf teletext editor. See further details here: https://github.com/rawles/edit.tf

If an object is supplied, it has these properties:

{
  defaultG0Charset: string (optional),
  header: string (optional),
  outputLines: [strings],
  packed: string
}

defaultG0Charset is optional. If supplied, the page uses it as the default G0 character set. The available character sets can be seen at @techandsoftware/teletext in the documentation for setDefaultG0Charset().

header is optional. When present, it's a string of 32 characters, which have the same encoding as the outputLines (see below) but without the initial OL,rowNum, . This is used as the header row and is used instead of Output Line 0 in the provided outputLines. When not provided, the row 0 in the lines is used if there is one. When a header is supplied, the page is also cleared before the outputLines are displayed.

One of outputLines or packed is required, which are alternative formats for the page data. If packed is supplied, it's a string with the PACKED_PAGE format described above. outputLines is an array of strings with up to 25 elements. The strings are in the Output Line format used in MRG's .tti files. Each line has this format:

OL,rowNum,line

In this:

  • rowNum is between 0 and 24
  • line is the string to display. Attribute characters (character codes less than 0x20) are represented in three ways: 1) As they are with no translation, or 2) They have 0x80 added to translate them to characters with codes 128-159, or 3) they are replaced by escape (character 0x1b) then the character with 0x40 added.

ttxcaster.available.attach(function)

Register a function to receive the available event. The available event happens when the client browser (probably Chrome) supports Google's casting API, so there is the possibility of connecting to Chromecast devices and you can expect to get castStateChanged events. If the browser doesn't supporting casting then there's no event.

ttxcaster.castStateChanged.attach(function)

Register a function for state change events. The function is called when the cast icon state changes. The state can be retrieved with ttxcaster.getCastState(). (This is a proxy to CAST_STATE_CHANGED events on CastContext in Google's cast API.)

ttxcaster.getCastState()

Gets the cast icon state. The response is a string with one of these values:

  • NO_DEVICES_AVAILABLE
  • NOT_CONNECTED
  • CONNECTING
  • CONNECTED

(This is a proxy to CastContext.getCastState() in Google's cast API.)

ttxcaster.setSmoothMosaics()

Renders block mosaics using a pixel art scaling algorithm so that graphics are higher resolution.

ttxcaster.setBlockMosaics()

Renders block mosaics in their usual blocky form.

ttxcaster.clearScreen()

Clears the screen.

ttxcaster.toggleReveal()

Shows or hides concealed characters if the page contains them.

ttxcaster.toggleMixMode()

Hides or shows row background colours.

ttxcaster.toggleBoxMode()

Activates or deactivates box mode mode display. The page needs to contain boxed characters for them to display, otherwise the page is transparent.

ttxcaster.toggleGrid()

Shows or hides a grid.

Demo

See a live demo in supporting browsers at https://teletextmoduledemo.tech-and-software.ltd.uk/teletext-caster-demo.html

Licensing

The Chromecast receiver app that this module connects to is intended for non-commercial use. For commercial enquiries, contact [email protected]

This package complies with REUSE 3.