• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript net.connectToWS函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@statecraft/net.connectToWS函数的典型用法代码示例。如果您正苦于以下问题:TypeScript connectToWS函数的具体用法?TypeScript connectToWS怎么用?TypeScript connectToWS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了connectToWS函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: connectToWS

 ? () => connectToWS(urlStr)
开发者ID:josephg,项目名称:statecraft,代码行数:1,代码来源:main.ts


示例2: connectToWS

 const [statusStore, storeP] = reconnectingclient<string>(() => connectToWS(wsurl))
开发者ID:josephg,项目名称:statecraft,代码行数:1,代码来源:editor.ts


示例3: Array

;(async () => {
  const access = await navigator.requestMIDIAccess()
  // Get lists of available MIDI controllers

  const inputs = Array.from(access.inputs.values())
  const outputs = Array.from(access.outputs.values())
  
  const portData = (port: WebMidi.MIDIPort): MIDIPort => ({
    id: port.id, // These IDs are really silly.
    manufacturer: port.manufacturer,
    name: port.name,
    version: port.version,
    state: port.state,
  })
  const inputPortData = (port: WebMidi.MIDIPort): MIDIInput => ({
    ...portData(port),
    keys: {},//new Array(128).fill(null),
    pots: new Array(8).fill(NaN), //[],
    sliders: [NaN],
    pitch: 64,
    modulation: 0,
  })

  let data: State = {
    timeOrigin: performance.timeOrigin,
    inputs: inputs.map(inputPortData),
    outputs: outputs.map(portData),
  }

  console.log('state', data)
  console.log(inputs[0].connection, inputs[0].state)
  const localStore = singlemem<State>(data)

  const [reader, writer] = await connectToWS<BothMsg, BothMsg>(wsurl)
  const remoteStore = await connectMux<void>(reader, writer, localStore, true)

  const apply = (op: JSONOp) => {
    console.log('before', data, 'op', op)
    data = jsonType.apply(data, op)
    console.log('after', data)
    return localStore.mutate(I.ResultType.Single, {type: 'json1', data: op})
  }

  const subscribeToInput = (input: WebMidi.MIDIInput, i: number) => {
    // console.log(i)
    input.onmidimessage = m => {
      // console.log(input.name, m.data, m.timeStamp)

      const [mtype, oper1, oper2] = m.data
      const inputData = data.inputs[i]
      const {keys, pots, sliders} = inputData
      switch (mtype) {
        case 0x90: // Note ON
          apply(replaceOp(['inputs', i, 'keys', ''+oper1], keys[oper1], {held: true, pressure: oper2, timestamp: m.timeStamp}))
          break
        case 0x80: // Note OFF
          apply(replaceOp(['inputs', i, 'keys', ''+oper1], keys[oper1], {held: false, pressure: 0, timestamp: m.timeStamp}))
          break
        case 176: { // Pots and sliders
          const field = oper1 === 1 ? ['modulation']
            : (oper1 >= 0x15 && oper1 <= 0x1c) ? ['pots', oper1 - 0x15]
            : (oper1 === 0x7) ? ['sliders', 0]
            : null
          if (field == null) console.log('unknown CC /', oper1, oper2)
          else apply(replaceOp(['inputs', i, ...field], true, oper2))
          break
        }
        case 224: // Pitch slider
          apply(replaceOp(['inputs', i, 'pitch'], inputData.pitch, oper2))
          break
        default:
          console.log('unknown message', mtype, oper1, oper2)
          break
      }
    }
  }
  inputs.forEach(subscribeToInput)

  access.onstatechange = e => {
    // Print information about the (dis)connected MIDI controller
    const {port} = e
    const set = port.type === 'input' ? data.inputs : data.outputs
    const deviceIdx = set.findIndex(({id}) => id === port.id)
    if (deviceIdx >= 0) {
      set[deviceIdx].state = port.state
    } else {
      set.push(port.type === 'input' ? inputPortData(port) : portData(port))
      if (port.type === 'input') subscribeToInput(port as WebMidi.MIDIInput, set.length-1)
    }
    setSingle(localStore, data)

    // console.log('onstatechange', e.port.name, e.port.manufacturer, e.port.state);
    // console.log(e.port.type)
  }
})()
开发者ID:josephg,项目名称:statecraft,代码行数:95,代码来源:client.ts


示例4: connectToWS

 const [statusStore, storeP, uidChanged] = reconnectingclient<any>(() => connectToWS(wsurl))
开发者ID:josephg,项目名称:statecraft,代码行数:1,代码来源:client.ts



注:本文中的@statecraft/net.connectToWS函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript core.QueueApi类代码示例发布时间:2022-05-28
下一篇:
TypeScript core.version类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap