// pages/advance/advance.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:"",
    rtmpserver:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let url = options.url;
    let rtmpserver = options.rtmpserver;

    if (url == null || url.length == 0) {
      url = "wss://xyt.yunzongji.cn:443";
    }

    if (rtmpserver == null || rtmpserver.length == 0) {
      rtmpserver = "rtmp://121.196.151.58:18085/live";
    }

    this.setData({
      url: url,
      rtmpserver: rtmpserver
    })

  },
  bindSaveTap: function() {
    if (!(this.data.url && this.data.rtmpserver)) {
      wx.showToast({
        title: '请输入完整的信息',
        icon: 'none'
      });
      return;
    }
    if (!(this.data.url.length > 0 && this.data.rtmpserver.length > 0)) {
      wx.showToast({
        title: '请输入完整的信息',
        icon: 'none'
      });
      return;
    }

    wx.setStorage({
      key: 'url',
      data: this.data.url,
    });
    wx.setStorage({
      key: 'rtmpserver',
      data: this.data.rtmpserver,
    });

    wx.showToast({
      title: '保存成功',
      icon: 'none'
    });

    wx.navigateBack({
      
    });

  },
  bindUrlInput: function (e) {
    let value = e.detail.value;
    let url = this.parseKeyboardInput(this.data.url, value);
    if (url) {
      this.data.url = url;
      return url;
    }
    this.data.url = value;
  },
  bindRtmpInput: function (e) {
    let value = e.detail.value;
    let rtmpserver = this.parseKeyboardInput(this.data.rtmpserver, value);
    if (rtmpserver) {
      this.data.rtmpserver = rtmpserver;
      return rtmpserver;
    }
    this.data.rtmpserver = value;
  },
  parseKeyboardInput: function (src, value) {
    if (src.length == 0 && value.length == 0) return null;
    if (value.length == 1) {
      return value.toLowerCase();
    }
    return null;
  }
})