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 canvas from '@napi-rs/canvas' // For canvas. | |
import fs from 'fs' // For creating files for our images. | |
import cwebp from 'cwebp' // For converting our images to webp. | |
// Load in the fonts we need | |
GlobalFonts.registerFromPath('./fonts/Inter-ExtraBold.ttf', 'InterBold'); | |
GlobalFonts.registerFromPath('./fonts/Inter-Medium.ttf','InterMedium'); | |
GlobalFonts.registerFromPath('./fonts/Apple-Emoji.ttf', 'AppleEmoji'); | |
// This function accepts 6 arguments: |
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
document.querySelectorAll('.button').forEach(function(item) { | |
// Add on mouseenter | |
item.addEventListener('mouseenter', function(e) { | |
calculateAngle(e, this.querySelector('span'), this); | |
}); | |
// Add on mousemove | |
item.addEventListener('mousemove', function(e) { | |
calculateAngle(e, this.querySelector('span'), this); | |
}); | |
// Reset everything on mouse leave |
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
// When the document has loaded | |
document.addEventListener('DOMContentLoaded', function() { | |
// Connect to the websocket | |
connect(); | |
// And add our event listeners | |
document.getElementById('websocket-button').addEventListener('click', function(e) { | |
if(isOpen(socket)) { | |
socket.send(JSON.stringify({ | |
"data" : "this is our data to send", | |
"other" : "this can be in any format" |
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
// @connect | |
// Connect to the websocket | |
let socket; | |
const connect = function() { | |
return new Promise((resolve, reject) => { | |
const socketProtocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:') | |
const port = 3000; | |
const socketUrl = `${socketProtocol}//${window.location.hostname}:${port}/ws/` | |
// Define socket |
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
<script src="local.js"></script> | |
<p>Welcome to websockets. Click here to start receiving messages.</p> | |
<button id="websocket-button">Click me</button> | |
<div id="websocket-returns"></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
// Get the /ws websocket route | |
app.ws('/ws', async function(ws, req) { | |
ws.on('message', async function(msg) { | |
// What was the message? | |
console.log(msg); | |
// Send back some data | |
ws.send(JSON.stringify({ | |
"append" : true, | |
"returnText" : "I am using websockets!" | |
})); |
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 path from 'path' | |
import { fileURLToPath } from 'url' | |
const __filename = fileURLToPath(import.meta.url); | |
const __dirname = path.dirname(__filename); | |
import express from 'express' | |
import expressWs from 'express-ws' | |
import http from 'http' | |
// Our port | |
let port = 3000; | |
// App and server |
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
cordova build ios |
NewerOlder