2.5.1 • Published 2 years ago

@citydna/platform v2.5.1

Weekly downloads
175
License
MIT
Repository
-
Last release
2 years ago

@citydna/platform

The official SDK for creating apps for the Melbourne CityDNA platform.

Ecosystem

Works great with @citydna/common (branded component library), @citydna/maps (mapping components) and the @material-ui/core package for all your other UI needs. We've chosen to enforce typescript to avoid common mistakes, however, these packages can be used without it.

Installation

Only use this package with the citydna create-react-app template. It'll be relatively useless without it :)

$ yarn create react-app citydna-app-example --template=citydna
$ cd citydna-app-example
$ yarn add @citydna/platform

Usage

// src/Controller.citydna.tsx
import React from 'react'
import { CityDNAComponent, useDevices } from '@citydna/platform'

const MyControllerComponent:CityDNAComponent = () => {
  // 1. grab the emit function
  const { emit } = useDevices()

  // 2. set up your event handler
  const sendEventToScreen = () => emit("my-event", "Hello world")

  // 3. use your event handler.
  return <button onClick={sendEventToScreen}>Send event to screen</button>
}

// Platform annotation (see http://citydna.melbourne/cra-template)
MyControllerComponent.citydna = {...}
export default MyControllerComponent
// src/Screen.citydna.tsx
import React from "react"
import { CityDNAComponent, useDevices } from "@citydna/platform"

const MyScreenComponent: CityDNAComponent = () => {
  // 1. get event listener hook
  const { useEvent } = useDevices()

  // 2. use it to respond to events
  useEvent("my-event", data => {
    console.log(data) // => "Hello World"
  })

  return <>I am the screen!</>
}

API - TSDoc

You can check out the TSDoc for detailed information about types described below.

useDevices()

This hook gives your app access to devices in the room, which app components they are allocated to, as well as emitting to and listening for events within the room.

// API
const { devices, emit, myID, useEvent } = useDevices()

This will be the most commonly used hook when developing apps that communicate across devices.

devices:Device[] & {allocation: DeviceAllocation}[]

Returns an array of connected devices, including their name, type and any allocated app components.

emit<T>:(eventName:string, data:T) => void

Returns a function that allows you to emit events to all devices in the room.

myID:string

The device ID automatically generated when authorising with the Pusher service. Helps you find your own config in the devices array.

useEvent<T>:(eventName:string, callback:(data:T) => voidå) => void

Returns a hook that allows you to listen to events sent by emit.


useApp()

const { room, app, manifest, appSettings, setAppSettings } = useApp()
2.5.1-develop.0

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.4.2

2 years ago

2.2.1-develop.0

2 years ago

2.3.1-develop.0

2 years ago

2.4.1-develop.0

2 years ago

2.3.0

2 years ago

2.4.3-develop.0

2 years ago

2.4.2-develop.0

2 years ago

2.5.2-develop.0

2 years ago

2.2.0

2 years ago

2.2.0-develop.2

2 years ago

2.3.0-develop.2

2 years ago

2.3.0-develop.1

2 years ago

2.3.0-develop.4

2 years ago

2.5.0-develop.2

2 years ago

2.5.0-develop.0

2 years ago

2.5.0

2 years ago

2.5.1

2 years ago

2.2.0-develop.7

2 years ago

2.0.0

2 years ago

2.1.1-develop.0

2 years ago

1.13.0-develop.0

2 years ago

2.0.1-develop.1

2 years ago

2.0.1-develop.2

2 years ago

2.0.1-develop.0

2 years ago

2.1.0-develop.4

2 years ago

2.1.0-develop.0

2 years ago

2.0.0-develop.0

2 years ago

2.1.0

2 years ago

2.0.0-develop.4

2 years ago

1.12.1-develop.0

2 years ago

1.12.0

2 years ago

1.12.0-develop.6

2 years ago

1.11.1-develop.0

2 years ago

1.12.0-develop.3

2 years ago

1.10.0-develop.3

2 years ago

1.11.0-develop.0

2 years ago

1.10.0-develop.5

2 years ago

1.11.0

2 years ago

1.10.0

2 years ago

1.9.1-develop.1

2 years ago

1.9.1-develop.0

2 years ago

1.9.0

2 years ago

1.9.0-develop.98

3 years ago

1.9.0-develop.79

3 years ago

1.9.0-develop.84

3 years ago

1.9.0-develop.87

3 years ago

1.9.0-develop.75

3 years ago

1.9.0-develop.72

3 years ago

1.9.0-develop.66

3 years ago

1.9.0-develop.70

3 years ago

1.9.0-develop.63

3 years ago

1.9.0-develop.52

3 years ago

1.9.0-develop.49

3 years ago

1.9.0-develop.50

3 years ago

1.9.0-develop.45

3 years ago

1.9.0-develop.42

3 years ago

1.9.0-develop.41

3 years ago

1.9.0-develop.37

3 years ago

1.9.0-develop.39

3 years ago

1.9.0-develop.34

3 years ago

1.9.0-develop.33

3 years ago

1.9.0-develop.29

3 years ago

1.9.0-develop.21

3 years ago

1.9.0-develop.19

3 years ago

1.9.0-develop.8

3 years ago

1.9.0-develop.9

3 years ago

1.9.0-develop.7

3 years ago

1.9.0-develop.5

3 years ago

1.9.0-develop.2

3 years ago

1.9.0-develop.0

3 years ago

1.8.0

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.5.7

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.1.0

4 years ago

1.0.36

4 years ago

1.0.26

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago