@7365admin1/layer-common 3.2.1-staging.62 → 3.2.1-staging.64

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.
@@ -1,5 +1,6 @@
1
1
  import { computed, onScopeDispose, readonly, ref, shallowRef } from "vue";
2
2
  import type { SimpleUser, SimpleUserDelegate, SimpleUserOptions } from "sip.js/lib/platform/web";
3
+ import type { SessionDescriptionHandlerOptions } from "sip.js/lib/platform/web/session-description-handler/session-description-handler-options";
3
4
 
4
5
  export type SipWebPhoneConfig = {
5
6
  webSocketServer: string;
@@ -11,7 +12,6 @@ export type SipWebPhoneConfig = {
11
12
  };
12
13
 
13
14
  export type SipWebPhoneMedia = {
14
- localVideo?: HTMLVideoElement | null;
15
15
  remoteAudio?: HTMLAudioElement | null;
16
16
  remoteVideo?: HTMLVideoElement | null;
17
17
  };
@@ -25,8 +25,6 @@ export default function useSipWebPhone() {
25
25
  const callState = ref<CallState>("idle");
26
26
  const errorMessage = ref("");
27
27
  const muted = ref(false);
28
- const cameraEnabled = ref(false);
29
- const localVideoAvailable = ref(false);
30
28
  const remoteVideoAvailable = ref(false);
31
29
  const currentTarget = ref("");
32
30
  const activeConfig = shallowRef<SipWebPhoneConfig>();
@@ -106,8 +104,7 @@ export default function useSipWebPhone() {
106
104
  aor: normalizeSipUri(config.aor),
107
105
  delegate,
108
106
  media: {
109
- constraints: { audio: true, video: Boolean(config.video) },
110
- local: { video: media.localVideo || undefined },
107
+ constraints: { audio: true, video: false },
111
108
  remote: {
112
109
  audio: media.remoteAudio || undefined,
113
110
  video: media.remoteVideo || undefined,
@@ -169,7 +166,14 @@ export default function useSipWebPhone() {
169
166
  currentTarget.value = destination;
170
167
  callState.value = "calling";
171
168
  try {
172
- await user.call(destination);
169
+ const sessionDescriptionHandlerOptions: SessionDescriptionHandlerOptions = {
170
+ constraints: { audio: true, video: false },
171
+ offerOptions: {
172
+ offerToReceiveAudio: true,
173
+ offerToReceiveVideo: Boolean(activeConfig.value?.video),
174
+ },
175
+ };
176
+ await user.call(destination, { sessionDescriptionHandlerOptions });
173
177
  } catch (error) {
174
178
  resetCall();
175
179
  errorMessage.value = getErrorMessage(error);
@@ -179,7 +183,10 @@ export default function useSipWebPhone() {
179
183
 
180
184
  async function answer() {
181
185
  const user = requireRegisteredUser();
182
- await user.answer();
186
+ const sessionDescriptionHandlerOptions: SessionDescriptionHandlerOptions = {
187
+ constraints: { audio: true, video: false },
188
+ };
189
+ await user.answer({ sessionDescriptionHandlerOptions });
183
190
  }
184
191
 
185
192
  async function decline() {
@@ -207,42 +214,19 @@ export default function useSipWebPhone() {
207
214
  muted.value = !enable;
208
215
  }
209
216
 
210
- function toggleCamera() {
211
- const user = requireUser();
212
- const tracks = user.localMediaStream?.getVideoTracks() || [];
213
- if (!tracks.length) throw new Error("No camera track is available. Reconnect the web phone with video enabled.");
214
- const enable = !cameraEnabled.value;
215
- tracks.forEach((track) => {
216
- track.enabled = enable;
217
- });
218
- cameraEnabled.value = enable;
219
- }
220
-
221
217
  function syncVideoState() {
222
218
  const user = simpleUser.value;
223
- const localStream = user?.localMediaStream;
224
219
  const remoteStream = user?.remoteMediaStream;
225
- const localTrack = localStream?.getVideoTracks()[0];
226
220
  const remoteTrack = remoteStream?.getVideoTracks()[0];
227
221
 
228
222
  const updateState = () => {
229
- const currentLocalTrack = localStream?.getVideoTracks()[0];
230
223
  const currentRemoteTrack = remoteStream?.getVideoTracks()[0];
231
- localVideoAvailable.value = Boolean(currentLocalTrack && currentLocalTrack.readyState === "live");
232
224
  remoteVideoAvailable.value = Boolean(currentRemoteTrack && currentRemoteTrack.readyState === "live");
233
- cameraEnabled.value = Boolean(currentLocalTrack?.enabled);
234
225
  };
235
226
 
236
227
  updateState();
237
- if (localStream) localStream.onaddtrack = updateState;
238
228
  if (remoteStream) remoteStream.onaddtrack = updateState;
239
229
 
240
- if (localTrack) {
241
- localTrack.onended = () => {
242
- localVideoAvailable.value = false;
243
- cameraEnabled.value = false;
244
- };
245
- }
246
230
  if (remoteTrack) {
247
231
  remoteTrack.onended = () => {
248
232
  remoteVideoAvailable.value = false;
@@ -254,8 +238,6 @@ export default function useSipWebPhone() {
254
238
  callState.value = "idle";
255
239
  currentTarget.value = "";
256
240
  muted.value = false;
257
- cameraEnabled.value = false;
258
- localVideoAvailable.value = false;
259
241
  remoteVideoAvailable.value = false;
260
242
  }
261
243
 
@@ -279,8 +261,6 @@ export default function useSipWebPhone() {
279
261
  callState: readonly(callState),
280
262
  errorMessage: readonly(errorMessage),
281
263
  muted: readonly(muted),
282
- cameraEnabled: readonly(cameraEnabled),
283
- localVideoAvailable: readonly(localVideoAvailable),
284
264
  remoteVideoAvailable: readonly(remoteVideoAvailable),
285
265
  currentTarget: readonly(currentTarget),
286
266
  isRegistered,
@@ -292,7 +272,6 @@ export default function useSipWebPhone() {
292
272
  decline,
293
273
  hangup,
294
274
  toggleMute,
295
- toggleCamera,
296
275
  };
297
276
  }
298
277
 
@@ -323,10 +302,10 @@ function normalizeDestination(target: string, aor: string) {
323
302
 
324
303
  function getErrorMessage(error: unknown) {
325
304
  if (error instanceof DOMException && error.name === "NotAllowedError") {
326
- return "Camera or microphone permission was denied. Allow media access in the browser and reconnect the web phone.";
305
+ return "Microphone permission was denied. Allow microphone access in the browser and reconnect the web phone.";
327
306
  }
328
307
  if (error instanceof DOMException && error.name === "NotFoundError") {
329
- return "No camera or microphone was found for this video call.";
308
+ return "No microphone was found for this call.";
330
309
  }
331
310
  return error instanceof Error ? error.message : "SIP connection failed.";
332
311
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "3.2.1-staging.62",
5
+ "version": "3.2.1-staging.64",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "publishConfig": {