Skip to content

Commit

Permalink
Fix adapter imports for sdk
Browse files Browse the repository at this point in the history
There's a confusion in ESM and CJS, let's try to fix them by using
`default` wrapper removal for `adapter`
(as suggested here: reduxjs/redux-toolkit#1960)
  • Loading branch information
nandito committed Mar 13, 2024
1 parent 701e70f commit fc70db7
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/utils/ServerSocket.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { io } from "socket.io-client";
import adapter from "webrtc-adapter";
import adapterRaw from "webrtc-adapter";
import { ReconnectManager } from "./ReconnectManager";
import { PROTOCOL_RESPONSES } from "../model/protocol";

const adapter = adapterRaw.default ?? adapterRaw;

const DEFAULT_SOCKET_PATH = "/protocol/socket.io/v4";

const NOOP_KEEPALIVE_INTERVAL = 2000;
Expand Down
3 changes: 2 additions & 1 deletion src/webrtc/P2pRtcManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import * as CONNECTION_STATUS from "../model/connectionStatusConstants";
import RtcStream from "../model/RtcStream";
import { getOptimalBitrate } from "../utils/optimalBitrate";
import { setCodecPreferenceSDP, addAbsCaptureTimeExtMap } from "./sdpModifier";
import adapter from "webrtc-adapter";
import adapterRaw from "webrtc-adapter";
import ipRegex from "../utils/ipRegex";
import { Address6 } from "ip-address";
import checkIp from "check-ip";
import validate from "uuid-validate";
import rtcManagerEvents from "./rtcManagerEvents";
import Logger from "../utils/Logger";

const adapter = adapterRaw.default ?? adapterRaw;
const logger = new Logger();

const ICE_PUBLIC_IP_GATHERING_TIMEOUT = 3 * 1000;
Expand Down
3 changes: 2 additions & 1 deletion src/webrtc/Session.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as sdpModifier from "./sdpModifier";
import * as statsHelper from "./statsHelper";
import { setVideoBandwidthUsingSetParameters } from "./rtcrtpsenderHelper";
import adapter from "webrtc-adapter";
import adapterRaw from "webrtc-adapter";
import { MAXIMUM_TURN_BANDWIDTH_UNLIMITED } from "./constants";
import Logger from "../utils/Logger";

const adapter = adapterRaw.default ?? adapterRaw;
const logger = new Logger();

export default class Session {
Expand Down
3 changes: 2 additions & 1 deletion src/webrtc/VegaRtcManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as CONNECTION_STATUS from "../model/connectionStatusConstants";
import ServerSocket from "../utils/ServerSocket";
import rtcManagerEvents from "./rtcManagerEvents";
import rtcStats from "./rtcStatsService";
import adapter from "webrtc-adapter";
import adapterRaw from "webrtc-adapter";
import VegaConnection from "./VegaConnection";
import { getMediaSettings, modifyMediaCapabilities } from "../utils/mediaSettings";
import { MEDIA_JITTER_BUFFER_TARGET } from "./constants";
Expand All @@ -16,6 +16,7 @@ import { maybeTurnOnly } from "../utils/transportSettings";
import VegaMediaQualityMonitor from "./VegaMediaQualityMonitor";
import Logger from "../utils/Logger";

const adapter = adapterRaw.default ?? adapterRaw;
const logger = new Logger();

const browserName = adapter.browserDetails.browser;
Expand Down
4 changes: 3 additions & 1 deletion src/webrtc/bugDetector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import adapter from "webrtc-adapter";
import adapterRaw from "webrtc-adapter";

const adapter = adapterRaw.default ?? adapterRaw;

/**
* Detect mic issue which seems to happen on OSX when the computer is woken up and sleeping
Expand Down
4 changes: 3 additions & 1 deletion src/webrtc/mediaConstraints.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import adapter from "webrtc-adapter";
import adapterRaw from "webrtc-adapter";

const adapter = adapterRaw.default ?? adapterRaw;

const isSafari = adapter.browserDetails.browser === "safari";

Expand Down
4 changes: 3 additions & 1 deletion src/webrtc/rtcStatsService.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// ensure adapter is loaded first.
import adapter from "webrtc-adapter"; // eslint-disable-line no-unused-vars
import adapterRaw from "webrtc-adapter";
import rtcstats from "rtcstats";
import { v4 as uuidv4 } from "uuid";

const adapter = adapterRaw.default ?? adapterRaw; // eslint-disable-line no-unused-vars

const RTCSTATS_PROTOCOL_VERSION = "1.0";

// when not connected we need to buffer at least a few getstats reports
Expand Down
3 changes: 2 additions & 1 deletion src/webrtc/sdpModifier.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import SDPUtils from "sdp";
import adapter from "webrtc-adapter";
import adapterRaw from "webrtc-adapter";
import * as sdpTransform from "sdp-transform";
import Logger from "../utils/Logger";

const adapter = adapterRaw.default ?? adapterRaw;
const logger = new Logger();

const browserName = adapter.browserDetails.browser;
Expand Down

0 comments on commit fc70db7

Please sign in to comment.