Moved session and connection helpers and change data sending to use write streams

This commit is contained in:
Mitchell McCaffrey 2020-10-23 10:27:22 +11:00
parent 01e006f5e6
commit 37542dc0e6
5 changed files with 7 additions and 6 deletions

View File

@ -2,7 +2,7 @@ import SimplePeer from "simple-peer";
import { encode, decode } from "@msgpack/msgpack";
import shortid from "shortid";
import blobToBuffer from "./blobToBuffer";
import blobToBuffer from "../helpers/blobToBuffer";
// Limit buffer size to 16kb to avoid issues with chrome packet size
// http://viblast.com/blog/2015/2/5/webrtc-data-channel-message-size/
@ -63,7 +63,8 @@ class Connection extends SimplePeer {
const chunks = this.chunk(packedData);
for (let chunk of chunks) {
if (this.dataChannels[channel]) {
this.dataChannels[channel].send(encode(chunk));
// Write to the stream to allow for buffer / backpressure handling
this.dataChannels[channel].write(encode(chunk));
} else {
super.send(encode(chunk));
}

View File

@ -10,7 +10,7 @@ import { omit } from "../helpers/shared";
import useDebounce from "../helpers/useDebounce";
// Load session for auto complete
// eslint-disable-next-line no-unused-vars
import Session from "../helpers/Session";
import Session from "./Session";
import Map from "../components/map/Map";
import Tokens from "../components/token/Tokens";

View File

@ -2,7 +2,7 @@ import React, { useContext, useState, useEffect, useCallback } from "react";
// Load session for auto complete
// eslint-disable-next-line no-unused-vars
import Session from "../helpers/Session";
import Session from "./Session";
import { isStreamStopped, omit, fromEntries } from "../helpers/shared";
import AuthContext from "../contexts/AuthContext";

View File

@ -3,7 +3,7 @@ import { EventEmitter } from "events";
import Connection from "./Connection";
import { omit } from "./shared";
import { omit } from "../helpers/shared";
/**
* @typedef {object} SessionPeer

View File

@ -14,7 +14,7 @@ import { MapStageProvider } from "../contexts/MapStageContext";
import NetworkedMapAndTokens from "../network/NetworkedMapAndTokens";
import NetworkedParty from "../network/NetworkedParty";
import Session from "../helpers/Session";
import Session from "../network/Session";
const session = new Session();