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
private async onPresenceChanged() { | |
const members = await this.channel.presence.get(); | |
this.ensureLeaderElected(members); | |
this.onSwarmPresenceChanged(members); | |
} |
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
public async connect() { | |
this.channel.presence.subscribe(this.onPresenceChanged.bind(this)); | |
await this.channel.presence.enter('connected'); | |
this.onConnection(this.channel); | |
} |
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
constructor(channelName: string) { | |
this.id = Math.floor(Math.random() * 1000000) + ""; | |
this.ably = new Ably.Realtime({ key: "api-key-here", clientId: this.id }); | |
this.channel = this.ably.channels.get(channelName); | |
} |
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
public onElection: (channel: Types.RealtimeChannelPromise) => void = () => {}; | |
public onConnection: (channel: Types.RealtimeChannelPromise) => void = () => {}; | |
public onSwarmPresenceChanged: (members: Types.PresenceMessage[]) => void = () => {}; |
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
import { Types } from 'ably'; | |
import Ably from 'ably/promises'; | |
export default class Swarm { | |
public readonly id: string; | |
private readonly ably: Ably.Realtime; | |
private readonly channel: Types.RealtimeChannelPromise; |
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
import React, { useState, useEffect } from 'react'; | |
import Ably from "ably/promises"; | |
const client = new Ably.Realtime("you-api-key-here"); | |
const Component = (props) => { | |
const channel = client.channels.get('some-channel'); | |
const [ messages, updateMessages ] = useState([]); |
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
classCountComponent extends HTMLElement { | |
} |
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
var net = require('net'); | |
var path = require('path'); | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
const port = 3141; | |
const fetch = require("node-fetch"); |
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
Phase description | phase name | message 'kind' | |
---|---|---|---|
Dealing and setup | No messages | ||
Collecting image input | `drawing-request` | instruction | |
Collecting image input response | `drawing-response` | drawing-response | |
Collecting caption input | `caption-request` | instruction | |
Collecting caption input response | `caption-response` | caption response | |
Collecting scores from players input | `pick-one-request` | instruction | |
Collecting scores from players response | `pick-one-response` | pick-one-response | |
`skip-scoring-forwards` | skip-scoring-forwards | ||
Displaying scores | `show-scores` | instruction |
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
import React from 'react' | |
import Ably from "ably/promises"; | |
const client = new Ably.Realtime("your-ably-api-key"); | |
export default class AblyMessageComponent extends React.Component { | |
constructor() { | |
super(); | |
this.state = { messages: [] }; |