topazcube 0.1.17 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/server.ts CHANGED
@@ -19,7 +19,7 @@ import fastjsonpatch from 'fast-json-patch'
19
19
  import { WebSocketServer, WebSocket } from 'ws'
20
20
  import { MongoClient, Db } from 'mongodb'
21
21
  import { glMatrix, vec3, quat } from 'gl-matrix'
22
- import wrtc from '@roamhq/wrtc' // Server-side WebRTC implementation
22
+ // WebRTC implementation loaded conditionally when needed
23
23
 
24
24
  glMatrix.setMatrixArrayType(Array)
25
25
 
@@ -485,12 +485,10 @@ export default class TopazCubeServer {
485
485
  client.ctdiff = message.ct + ping / 2 - time
486
486
  client.ping = ping
487
487
  //this.log(time, "PENG ping, ctdiff", message, ping, client.ctdiff, "ms")
488
- /*
489
488
  } else if (message.c == 'rtc-offer') {
490
489
  this._processOffer(client, message)
491
490
  } else if (message.c == 'rtc-candidate') {
492
491
  this._processICECandidate(client, message)
493
- */
494
492
  } else if (message.c == 'sub') {
495
493
  await this._checkDocument(message.n, client)
496
494
  if (!this.documents[message.n]) {
@@ -806,8 +804,27 @@ export default class TopazCubeServer {
806
804
 
807
805
  /*= WEBRTC ===================================================================*/
808
806
 
807
+ private _wrtc: any = null
808
+
809
+ private async _loadWebRTC(): Promise<any> {
810
+ if (!this._wrtc) {
811
+ try {
812
+ this._wrtc = await import('@roamhq/wrtc')
813
+ } catch (error) {
814
+ this.error('WebRTC module not available:', error)
815
+ throw new Error('WebRTC functionality requires @roamhq/wrtc and platform-specific binary packages')
816
+ }
817
+ }
818
+ return this._wrtc
819
+ }
809
820
 
810
821
  async _processOffer(client: ClientType, data: any): Promise<void> {
822
+ if (!this.allowWebRTC) {
823
+ this.warn('WebRTC is disabled')
824
+ return
825
+ }
826
+
827
+ const wrtc = await this._loadWebRTC()
811
828
  //this.log("RTC: Offer received", data);
812
829
  const peerConnection = new (wrtc as any).RTCPeerConnection({
813
830
  iceServers: [