مرجع المطوّرين

صكّ التوكن من الباك‌إند

الطريقة المعتمدة لتوليد توكن الدخول — وحقلٌ واحد لو سقط، تتعطّل الجلسة الواحدة في صمت.

رجوع لمنتجات المطوّرين

ليه من الباك‌إند؟

السرّ بتاعك ما ينزلش في التطبيق أبدًا. أي مفتاح يتشحن مع الـAPK ينفع يتفكّ ويُنتحل بيه أي مستخدم.

مرّر حقائق الجهاز

سيرفرك ما بيشوفش الجهاز. التطبيق هو اللي يبعتها لسيرفرك، وسيرفرك يمرّرها لنا في نفس الطلب.

السقوط صامت

من غير device_id، فرض «حساب واحد على جهاز واحد» بيرجع بدري من غير خطأ ولا لوج. التوكن بينجح، والحماية بتبقى مطفية.

ده مقيس، مش متوقَّع

على ثلاث ساعات دخولات حقيقية: التوكنات المصكوكة من الباك‌إند ٣٬٢٢٤ دخولاً — ١٠٠٪ منها بلا معرّف جهاز. المصكوكة من الكِت على الجهاز ١٬٦٤١ دخولاً — صفر٪. نفس المشروع بيعطي النتيجتين حسب مين صكّ.

حقول طلب التوكن

POST إلى ‎/api/v1/token‎ بسرّ السيرفر في الترويسة.

الحقلالمستوىالمعنى
user_idstringمطلوبWho the token is for. Your own user id. (Previously `identity` — still accepted.)
room_idstringمطلوبWhich room they are joining. (Previously `room_name` — still accepted.)
device_idstringموصى بهA stable id for the PHYSICAL DEVICE — not the user, and not the session. This is what enforces one account on one device: when the same user_id joins from a different device_id, the previous device is messaged and removed. Omit it and that enforcement silently does nothing: the check returns early, logs nothing, and the old device stays signed in.
device_modelstringموصى بهe.g. SM-A175F. Feeds per-handset quality analysis — which models have audio or video trouble.
osstringموصى بهandroid | ios.
os_versionstringموصى بهe.g. 14.
app_versionstringموصى بهYour app's version, so a regression can be traced to a release.
display_namestringاختياريShown to other participants. Omit it and the name stays empty — we never substitute the user id for it.
rolestringاختياريOnly honoured from a server-signed request, and only while your project still carries the client-asserted-role exception. The supported path is PUT /rooms/:room/participants/:id/role.
typestringاختياريaudio_room | live_stream. Legacy kits send `service` (+ `kind`) instead and the type is derived.

على سيرفرك

السرّ هنا وبس. الحقول المعلّمة بالأحمر جاية من التطبيق — سيرفرك ما يقدرش يعرفها لوحده.

mint-token.js
// Your backend — the app never sees the server secret.
const res = await fetch("https://engine.udt-stream.com/api/v1/token", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-App-Secret": process.env.UTD_SERVER_SECRET,   // never ship this in the app
  },
  body: JSON.stringify({
    user_id: currentUser.id,
    room_id: roomId,

    // 🔴 Forwarded FROM THE APP. Your server cannot know these on its own,
    // and without device_id one-account-one-device stops working for your users.
    device_id: body.device_id,
    device_model: body.device_model,
    os: body.os,
    os_version: body.os_version,
    app_version: body.app_version,
  }),
});

في تطبيقك

ابعت حقائق الجهاز لسيرفرك أنت، وهو يمرّرها. معرّف الجهاز لازم يفضل ثابت بعد إعادة تشغيل التطبيق.

request_token.dart
// Your app — send the device facts to YOUR backend, which forwards them to us.
final deviceId = await MyDeviceIdentity.stableId(); // persisted, survives app restarts
await myApi.post("/rooms/$roomId/token", body: {
  "device_id": deviceId,
  "device_model": deviceInfo.model,
  "os": Platform.isAndroid ? "android" : "ios",
  "os_version": deviceInfo.version,
  "app_version": packageInfo.version,
});

أكواد الرفض (403)

كل رفض بيحمل code. اقرأ الكود — ما تعرضش «اتشالت من الغرفة» إلا على الأول منهم.

الكودالمعنىاعمل إيه
user_bannedThis user is banned from this room.Show them they were removed. This is the ONLY code that should produce that message.
room_type_disabledThe project does not have this room type enabled.A configuration problem, not a user problem. Never show a removal notice.
streaming_disabledThe streaming service is not enabled for this project.Same — configuration, not the user.
appkey_identity_mint_disabledYou tried to mint an identity-bearing token with the publishable app_key.Mint from your backend with the server secret instead. This is the path this page describes.

أوضاع المصادقة

المحرّك بيسجّل وضع المصادقة على كل دخول، فتقدر تتأكد أنت على أي مسار فعلاً.

secret / signature / bearer

Your backend, authenticated with your server secret. The recommended path.

app_key

The device, using the publishable app key. The legacy path — being closed.

جاهز تبني مع UTD؟

أنشئ حسابك، اشحن محفظتك الأم، وشغّل الخدمات التي تحتاجها.